15

I successfully setup a private blockchain and created the "hello world" contract according to tutorial from etherium web site. One thing that I can't figure out is how to find the contract later. I thought once the contract is mined, it becomes part of the blockchain forever. The documentation seems to imply permanence because it's stressing how it's good etiquette to clean up unused contracts by committing suicide on them. That's why after I got this message, I thought the contract was permanently part of the blockchain:

    Contract mined! address: ........

But after quiting geth and getting back in, I can't find the contract anywhere (I lost it's address). It seemed to last only during the single instance of when geth was running. What am I missing here? Do I have to register the contract for it to become permanent? Would I use the same technique on the real blockchain in order to get my code listed here?:

https://www.etherchain.org/contracts

7

You're missing the contract address.

When sending a contract for the first time it will return the address to you as a Javascript callback that you said : " Contract mined! address: ........ "

But this is javascript.It will disapear when you closed the browser so you need to save the address beforehand and then call it back at will with :

var MyContract = web3.eth.contract(MyContract.abi);
var Instance = MyContract.at("address");

And you can the use Instance.thefunctionyouwant

You might be able to find the address by checking the last few transactions from your own address since as you said , it is saved forever, but you just don't know where it is. But as it's a test network i would suggest you to recreate the contract save the address and proceed as mentioned.

  • 1
    So you mean something like contract.at(eth.address[of_account]). I first thought "address" was to be used literally in the call. – TMOTTM Jun 19 '16 at 12:34
8

You can use a filter to list all transaction from a given address.

var filter = eth.filter({fromBlock:0, toBlock:'latest', address: "0x.."});
filter.get(function (err, transactions) {
  transactions.forEach(function (tx) {
    var txInfo = eth.getTransactionReceipt(tx.transactionHash);
    /* Here you have
    txInfo.contractAddress;
    txInfo.from;
    txInfo.input;
    */
  });
});

You can use an ether explorer like (https://github.com/etherparty/explorer) in your private testnet to look at the mined blocks. These particular explorer show only block info and transaction info. It uses angular and can be modified easily. But currently is somehow "limited".

6

As jayD has already said, you can set a callback function to be notified when a contract is correctly created.

If you lost the moment, you can anyway retrieve the contract address later. In fact, the contract address is deterministically computed from the address of its creator and how many transactions the creator has sent.

See How is the address of an Ethereum contract computed? for more details.

3

You may use "web3.eth.getTransactionReceipt('{txn_id}')". It will give you the contract address as well as other information like block number etc.

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.