How to find contract's address?

  • 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?:

  • jayD

    jayD Correct answer

    5 years ago

    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 ="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.

    So you mean something like `[of_account])`. I first thought `"address"` was to be used literally in the call.

License under CC-BY-SA with attribution

Content dated before 7/24/2021 11:53 AM