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, contract_name='ERC20MockDecimals.json', cache=LRUCache({}, maxsize=1024, currsize=0), chain_id=None)[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[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 usecentre/FiatToken.json
.cache (cachetools.Cache | None) –
Use this cache for cache token detail calls.
The main purpose is to easily reduce JSON-RPC API call count.
By default, we use LRU cache of 1024 entries.
Set to
None
to disable the cache.Chain id hint for the cache.
If not given do
eth_chainId
RPC call to figure out.
- Returns
Sanitised token info
- Return type