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 balanceOf mapping 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, and anvil_setStorageAt RPC methods.

Parameters
Returns

Storage slot number (0-19).

Raises

RuntimeError – If no matching slot is found in the first 20 slots.

Return type

int