I'm using web3.py to interact with contracts. I was wondering, after calling a function with selfdestruct or suicide(address), how do I find out that the contract is in fact dead?

  • Try to call any read-only function of that contract, and verifies that it raises an exception. May 3, 2020 at 14:18
  • @goodvibration Is there any smarter ways other than relying on exceptions? May 3, 2020 at 14:29
  • It is indeed not a very reliable method, because the call can fail for other reasons (for example, you're not even connected to the node). So you're bound to check the error message, which may vary depending on your web3 provider. May 3, 2020 at 14:36
  • Why not just check if there is a contract at the address? ethereum.stackexchange.com/a/15642/31933 May 3, 2020 at 17:23
  • @LauriPeltonen Can we do something like this in web3 or evm manager API instead of from another contract? May 3, 2020 at 17:41

1 Answer 1


You can call eth.getCode to see if there is code at the address. If there is no code, there is no contract. If there is code, there is a contract associated with the address.

Using ether.js, you can see how it works below. The first call was after the contract was deployed and the second call was after it was selfdestructed.

> kovanEthersProvider.getCode('0x761f887ea907DB3FBc13f55867Db2c2c9BDB34F9').then(console.log) 

> kovanEthersProvider.getCode('0x761f887ea907DB3FBc13f55867Db2c2c9BDB34F9').then(console.log)

Follow the same pattern with web3.py.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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