I deployed a contract yesterday which was mined and which was responding to calls. Today the contract "does not live" anymore. Do I need to redeploy? Is there a way to find addresses of contracts I deployed with a specific account?
3 Answers
The easiest way to find your contract is to checkout out the account that created the contract in a blockchain explorer.
For example, inspecting the account 0x5abfec25f74cd88437631a7731906932776356f9 will show you that it created the contract 0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae by its 4th transaction.
See How is the address of an Ethereum contract computed?
You may have been using a different network, like a testnet or tool. Or if you only interacted with the contract on mainnet for a brief moment after it was mined, it's possible there was a blockchain reorganization.
-
was deployed to testnet, and tried to call it again from testnet.– TMOTTMCommented Jun 15, 2016 at 21:20
If you used the testnet you can search for the contract's address (or the address used to broadcast it) using etherscan's testnet site. If it doesn't show up as a contract creation transaction then the contract was never deployed.
If it was deployed you need both the address of the contract and the ABI (for example this is the ABI for the DAO contract).
Using these you can open geth from anywhere and have a local instance of the contract with:
var abi = JSON.parse(contracts_abi_string);
var myContract = web3.eth.contract(abi).at(contractAddress);
You can then interact with myContract
.
-
-
@TMOTTM Do you still have the ABI? In order to call it you'll need both the contract's address (which it sounds like you have) and the ABI. Commented Jun 16, 2016 at 4:16
-
No don't think so. I closed the client since then. In principle it was really just the greeter tutorial example.– TMOTTMCommented Jun 16, 2016 at 4:20
-
@TMOTTM If you recreate it locally and broadcast it make sure you save the ABI (should be a string of JSON for example this is the ABI for the DAO contract). Then you should be able to reopen geth from anywhere and have a local instance of the contract with:
var myContract = web3.eth.contract(abi).at(contractAddress);
wherevar abi = JSON.parse(contracts_abi_string);
. You can then call your contracts methods onmyContract
. Commented Jun 16, 2016 at 4:31 -