fetch_erc20_details

Documentation for eth_defi.token.fetch_erc20_details function.

fetch_erc20_details(web3, token_address, max_str_length=256, raise_on_error=True)[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.

Example:

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

  • token_address (Union[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.

Returns

Sanitised token info

Return type

eth_defi.token.TokenDetails