4

Suppose I create a new contract with:

web3.eth.contract(abi).new({ data: code }, (err, contract) => { ... })

Inside the callback I am able to get the contract.address of the new contract. I can then successfully call that contract.

I'm just trying to understand what the right way to store this address should be? I am leaning towards storing it into a DB which my system will load at startup.

Or is there a better way? I guess I was expecting a DNS-esque sort of thing where I could give my contract a unique name and version and it would map to the address. Does this not exist? Does putting the address into a DB during a migration step sound reasonable?

3

Ideally, you will be interacting with the contract thorough out your application. You can store it in database, locally or even hardcode the address.

If you store in db, you can easily deal with future migrations and upgrade of your contract when you want.

If the contract deployment is dynamic, you can hook the deploy into a promise and save the address to when it comes back. And make a global variable of all the contracts deployed.

You might want to look into iurimatias/embark-framework

4

The database or config file options as suggested by other answers sound fine: even if there was a DNS-esque registry, DApps would initially have to hardcode its address.

Your question is timely and the ENS, Ethereum Name Service, was just deployed on the testnet (Ropsten).

See the ENS wiki for a quickstart and other details. Here's an introduction:

ENS is the Ethereum Name Service, a distributed, extensible naming system based on the Ethereum blockchain.

ENS can be used to resolve a wide variety of resources. The initial standard for ENS defines resolution for Ethereum addresses, but the system is extensible by design, allowing more resource types to be resolved in future without the core components of ENS requiring upgrades.

ENS is deployed on the Ropsten testnet at 0x112234455c3a32fd11230c42e7bccd4a84e02010.

Initial discussion here.

2

If you are in node you might store it in a database like postgres or even create a file for a user to backup.

If you're in the browser you have a variety of options ranging from cookies to localStorage to indexedDB.

You can even allow users to enter their own contract addresses in, to recover an already deployed contract of known bytecode and ABI.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.