fetch_erc20_balances_fallback

Documentation for eth_defi.balances.fetch_erc20_balances_fallback function.

fetch_erc20_balances_fallback(web3, address, tokens, block_identifier, decimalise=True, chunk_size=50, token_cache=LRUCache({}, maxsize=1024, currsize=0), gas_limit=10000000, raise_on_error=True, disable_multicall=None)[source]

Get all onchain balances of the token.

  • Safe variant

  • Try multicall approach first

  • If it fails for some reason, fall to individual JSON-RPC API approach

  • A reason for the failure would be crappy RPC providers

See fetch_erc20_balances_multicall() for usage and argument descriptions.

Parameters
  • disable_multicall (Optional[bool]) –

    Disable multicall behaviour.

    If set to None autodetect local dev/test chain and disable based on the presence of Anvil: assume no multicall contract deployed there. On the mainnet fork, assume the presence of multicall contract.

  • web3 (web3.main.Web3) –

  • address (Union[eth_typing.evm.HexAddress, str]) –

  • tokens (list[Union[eth_typing.evm.HexAddress, str]] | set[Union[eth_typing.evm.HexAddress, str]]) –

  • block_identifier (Union[Literal['latest', 'earliest', 'pending', 'safe', 'finalized'], eth_typing.evm.BlockNumber, eth_typing.evm.Hash32, eth_typing.encoding.HexStr, hexbytes.main.HexBytes, int]) –

  • token_cache (cachetools.Cache | None) –

Return type

dict[Union[eth_typing.evm.HexAddress, str], decimal.Decimal]