Migrating your code from v4 to v5¶
Web3.py follows Semantic Versioning, which means that version 5 introduced backwards-incompatible changes. If your project depends on Web3.py v4, then you’ll probably need to make some changes.
Here are the most common required updates:
Python 3.5 no longer supported.¶
You will need to upgrade to either Python 3.6 or 3.7
eth-abi v1 no longer supported¶
You will need to upgrade the
eth-abi dependency to v2 or higher.
Changes to base API¶
In v4, JSON-RPC calls that looked up transactions or blocks and
didn’t find them, returned
None. Now if a transaction or
block is not found, a BlockNotFound or a TransactionNotFound
error will be thrown as appropriate. This applies to the
following web3 methods:
getTransaction()will throw a
getTransactionReceipt()will throw a
getTransactionByBlock()will throw a
getTransactionCount()will throw a
getBlock()will throw a
getUncleCount()will throw a
getUncleByBlock()will throw a
contract.buildTransactionwas removed for
contract.deploywas removed for
contract.estimateGaswas removed for
contract.callwas removed for
contract.transactwas removed for
contract.eventFilterwas removed for
middleware_stackwas renamed to
web3.miner.hashratewas a duplicate of
hashrate()and was removed.
web3.version.networkwas a duplicate of
version()and was removed.
web3.providers.tester.TestRPCProviderhave been removed for
web3.txpoolwas moved to
web3.version.nodewas removed for
web3.version.ethereumwas removed for
- Relocated personal RPC endpoints to reflect Parity and Geth implementations:
web3.personal.listAccountswas removed for
web3.personal.importRawKeywas removed for
web3.personal.newAccountwas removed for
web3.personal.lockAccountwas removed for
web3.personal.unlockAccountwas removed for
web3.personal.sendTransactionwas removed for
Expect the following methods to be removed in v6:
Deprecated ConciseContract and ImplicitContract¶
The ConciseContract and ImplicitContract have been deprecated and will be removed in v6.
ImplicitContract instances will need to use the verbose syntax. For example:
ConciseContract has been replaced with the ContractCaller API. Instead of using the ConciseContract factory, you can now use:
or the classic contract syntax:
Some more concrete examples can be found in the ContractCaller docs
In v5, only a single provider will be allowed. While allowing multiple providers is a feature we’d like to support in the future, the way that multiple providers was handled in v4 wasn’t ideal. The only thing they could do was fall back. There was no mechanism for any round robin, nor was there any control around which provider was chosen. Eventually, the idea is to expand the Manager API to support injecting custom logic into the provider selection process.
manager.providers has changed to
Similarly, instances of
web3.providers have been changed to
- Web3.py will no longer automatically look up a testnet connection
in IPCProvider. Something like
from web3.auto.ropsten import w3should be used instead.
Web3.py has stopped inferring the
.eth TLD on domain names.
If a domain name is used instead of an address, you’ll need
to specify the TLD. An
InvalidTLD error will be thrown if
the TLD is missing.