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, cause_diagnostics_message=None)
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.
Note
Always give
chain_idwhen possible. Otherwise the caching of data is inefficient.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 (dict | 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
Noneto disable the cache.Instance of
cachetools.Cache. See cachetools documentation for details.chain_id (int) –
Chain id hint for the cache.
If not given do
eth_chainIdRPC call to figure out.cause_diagnostics_message (str | None) – Log in Python logging subsystem why this fetch was done to debug RPC overuse.
- Returns
Sanitised token info
- Return type