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:
You will need to upgrade to either Python 3.6 or 3.7
You will need to upgrade the eth-abi
dependency to v2
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:
~web3.eth.Eth.getTransaction
will throw aTransactionNotFound
error~web3.eth.Eth.getTransactionReceipt
will throw aTransactionNotFound
error~web3.eth.Eth.getTransactionByBlock
will throw aTransactionNotFound
error~web3.eth.Eth.getTransactionCount
will throw aBlockNotFound
error~web3.eth.Eth.getBlock
will throw aBlockNotFound
error~web3.eth.Eth.getUncleCount
will throw aBlockNotFound
error~web3.eth.Eth.getUncleByBlock
will throw aBlockNotFound
error
contract.buildTransaction
was removed forcontract.functions.buildTransaction.<method name>
contract.deploy
was removed forcontract.constructor.transact
contract.estimateGas
was removed forcontract.functions.<method name>.estimateGas
contract.call
was removed forcontract.<functions/events>.<method name>.call
contract.transact
was removed forcontract.<functions/events>.<method name>.transact
contract.eventFilter
was removed forcontract.events.<event name>.createFilter
middleware_stack
was renamed to~Web3.middleware_onion
web3.miner.hashrate
was a duplicate of~web3.eth.Eth.hashrate
and was removed.web3.version.network
was a duplicate of~web3.net.Net.version
and was removed.web3.providers.tester.EthereumTesterProvider
andweb3.providers.tester.TestRPCProvider
have been removed for~web3.providers.eth_tester.EthereumTesterProvider
web3.eth.enableUnauditedFeatures
was removedweb3.txpool
was moved to~web3.geth.txpool
web3.version.node
was removed forweb3.clientVersion
web3.version.ethereum
was removed for~web3.eth.Eth.protocolVersion
- Relocated personal RPC endpoints to reflect Parity and Geth implementations:
web3.personal.listAccounts
was removed for~web3.geth.personal.listAccounts
or~web3.parity.personal.listAccounts
web3.personal.importRawKey
was removed for~web3.geth.personal.importRawKey
or~web3.parity.personal.importRawKey
web3.personal.newAccount
was removed for~web3.geth.personal.newAccount
or~web3.parity.personal.newAccount
web3.personal.lockAccount
was removed for~web3.geth.personal.lockAccount
web3.personal.unlockAccount
was removed for~web3.geth.personal.unlockAccount
or~web3.parity.personal.unlockAccount
web3.personal.sendTransaction
was removed for~web3.geth.personal.sendTransaction
or~web3.parity.personal.sendTransaction
- Relocated
web3.admin
module toweb3.geth
namespace - Relocated
web3.miner
module toweb3.geth
namespace
Expect the following methods to be removed in v6:
web3.sha3
was deprecated for~Web3.keccak
web3.soliditySha3
was deprecated for~Web3.solidityKeccak
~web3.net.Net.chainId
was deprecated for~web3.eth.Eth.chainId
. Follow issue #1293 for detailsweb3.eth.getCompilers()
was deprecated and will not be replaced~web3.eth.getTransactionFromBlock()
was deprecated for~Web3.getTransactionByBlock
The ConciseContract and ImplicitContract have been deprecated and will be removed in v6.
ImplicitContract instances will need to use the verbose syntax. For example:
contract.functions.<function name>.transact({})
ConciseContract has been replaced with the ContractCaller API. Instead of using the ConciseContract factory, you can now use:
contract.caller.<function_name>
or the classic contract syntax:
contract.functions.<function name>.call()
.
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.
For now, manager.providers
has changed to manager.provider
. Similarly, instances of web3.providers
have been changed to web3.provider
.
Web3.py will no longer automatically look up a testnet connection in IPCProvider.
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.
In order to interact with Infura after March 27, 2019, you'll need to set an environment variable called WEB3_INFURA_PROJECT_ID
. You can get a project id by visiting https://infura.io/register.