Multicall
raw JSON → 0.15.2 verified Sat May 09 auth: no python
Aggregate results from multiple Ethereum contract calls into a single RPC call, using the MakerDAO Multicall contract. Current version 0.15.2, compatible with Python >=3.10 and <4. Release cadence is irregular.
pip install multicall Common errors
error EthCallError: No data returned from call at block ↓
cause The target contract or block does not exist, or the RPC endpoint is faulty.
fix
Verify the contract address and RPC URL. Ensure the block is within the chain's range.
error AttributeError: 'Multicall' object has no attribute 'aggregate' ↓
cause Using the old API on multicall >=0.10.0 which removed `.aggregate()`.
fix
Call the instance directly:
multi() instead of multi.aggregate(). error ValueError: Address must be checksummed ↓
cause Passing an address without proper EIP-55 checksumming.
fix
Use
Web3.to_checksum_address('0x...') on the address. Warnings
breaking In version 0.10.0, the API changed from using `Multicall.aggregate()` to calling the instance directly `multi()`. Old code using `.aggregate()` will break. ↓
fix Replace `.aggregate()` with a direct call: `multi()` instead of `multi.aggregate()`.
deprecated The `_w3` argument is deprecated in favor of passing a `web3` instance directly to the `Multicall` constructor. ↓
fix Use `Multicall(..., web3=w3)` instead of `Multicall(..., _w3=w3)`.
gotcha Call targets must be checksummed addresses; passing an address without correct checksum will raise an error. ↓
fix Use `Web3.to_checksum_address()` on all addresses before passing to `Call`.
Imports
- Multicall wrong
from multicall import Multicallcorrectfrom multicall import Multicall - Call wrong
from multicall import Multicallcorrectfrom multicall import Call
Quickstart
from multicall import Multicall, Call
from web3 import Web3
w3 = Web3(Web3.HTTPProvider('https://mainnet.infura.io/v3/YOUR-PROJECT-ID'))
multi = Multicall([
Call(('0x...', 'balanceOf(address)(uint256)'), [['0x...', None]]),
], _w3=w3)
result = multi()
print(result)