21

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

6 Answers 6

8

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
  • 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, 2016 at 12:34
9

You can use a filter to list all transactions 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 ethereum explorer like (https://github.com/etherparty/explorer) in your private testnet to look at the mined blocks. These particular explorer shows only block info and transaction info. It uses angular and can be modified easily. But currently it 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.

4

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

1
  • I have struggled with this for a few days, and I always get null for the transactionReceipt. unless there is some trick, it seems never to be available.
    – Cyberience
    Aug 24, 2021 at 4:51
0

For those of you using Parity's trace_transaction call, the newly-created contract address appears in the trace.result.address field. (And, as a side note, any self-destructed addresses appear in trace.action.address while the address that receives the proceeds of the self-destruct appears at trace.action.refundAddress.)

-1

When you are on MetaMask (this is a chrome extension) you can choose the option 'view on etherscan'. Here you can see all the Ethereum transactions.

In the To-address you will see: [Contract 0x........ Created]

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