Web3.py: getCode produces "0x" on smart contract addresses

Created on 23 May 2018  路  4Comments  路  Source: ethereum/web3.py

Version: 4.0.0
Python: 3.5
OS: Linux

What was wrong?

I have Geth (version 1.7.2) node, which was synced using the "fast" mode. When I use the getCode method on smart contract addresses, it always returns "0x". I have verified this with known smart contract addresses like the Iconomi ERC20 token contract address.

I am wondering why this is happening? Is it possible that nodes synced in "fast" mode cannot return the contract bytecode? Or is it a problem with web3py?

Any help is appreciated.

Most helpful comment

Likely culprits.

  • Wrong address (or connected to the wrong chain)
  • The node you're connected to isn't fully synced (still in the midst of a fast sync?)
  • The contract has been self destructed
  • The contract threw an error during deployment.

All 4 comments

Likely culprits.

  • Wrong address (or connected to the wrong chain)
  • The node you're connected to isn't fully synced (still in the midst of a fast sync?)
  • The contract has been self destructed
  • The contract threw an error during deployment.

Closed as it is very unlikely this is a web3.py bug. Please continue to post here if you still have issues and we can re-open if it turns out to be a web3.py issue.

The node is definitely not fully synced. I was stumped because all transaction related queries returned fine, however getCode didn't return the correct values. When the node syncs fully, will report back if the problem is resolved.

馃憤 your description fits. Fast sync finishes syncing Blocks/Transactions/Receipts well before the state sync finished and the contract code is part of the state sync.

Was this page helpful?
0 / 5 - 0 ratings