find_erc20_balance_slot
Documentation for eth_defi.provider.anvil.find_erc20_balance_slot function.
- find_erc20_balance_slot(web3, token_address, holder_address)
Find the ERC-20
balanceOfmapping storage slot by brute force.Tries slots 0-19 using Anvil snapshots, which covers all common ERC-20 implementations (OpenZeppelin, Solmate, USDC proxy, etc.).
Note
Only works on Anvil forks, as it uses
evm_snapshot,evm_revert, andanvil_setStorageAtRPC methods.- Parameters
web3 (web3.main.Web3) – Web3 connected to an Anvil fork.
token_address (Union[eth_typing.evm.HexAddress, str]) – ERC-20 token contract address.
holder_address (Union[eth_typing.evm.HexAddress, str]) – Address whose balance slot to find.
- Returns
Storage slot number (0-19).
- Raises
RuntimeError – If no matching slot is found in the first 20 slots.
- Return type