Documentation for eth_defi.token.fetch_erc20_details function.

fetch_erc20_details(web3, token_address, max_str_length=256, raise_on_error=True, contract_name='ERC20MockDecimals.json')[source]

Read token details from on-chain data.

Connect to Web3 node and do RPC calls to extract the token info. We apply some sanitazation for incoming data, like length checks and removal of null bytes.

The function should not raise an exception as long as the underlying node connection does not fail.


details = fetch_erc20_details(web3, token_address)
assert details.name == "Hentai books token"
assert details.decimals == 6
  • web3 (web3.main.Web3) – Web3 instance

  • token_address (Union[eth_typing.evm.HexAddress, str]) – ERC-20 contract address:

  • max_str_length (int) – For input sanitisation

  • raise_on_error – If set, raise TokenDetailError on any error instead of silently ignoring in and setting details to None.

  • contract_name

    Contract ABI file to use.

    The default is ERC20MockDecimals.json. For USDC use centre/FiatToken.json.


Sanitised token info

Return type