TokenDetails
Documentation for eth_defi.token.TokenDetails Python class.
- class TokenDetails[source]
A helper class to detail with token instructions.
Any field can be None for non-wellformed tokens.
Attributes summary
The address of this token.
The EVM chain id where this token lives.
Number of decimals
Token name e.g.
Token symbol e.g.
Token supply as raw units
The underlying ERC-20 contract proxy class instance
Methods summary
__init__
(contract[, name, symbol, ...])convert_to_decimals
(raw_amount)Convert raw token units to decimals.
convert_to_raw
(decimal_amount)Convert decimalised token amount to raw uint256.
fetch_balance_of
(address)Get an address token balance.
- contract: web3.contract.contract.Contract
The underlying ERC-20 contract proxy class instance
- property address: eth_typing.evm.HexAddress
The address of this token.
- convert_to_decimals(raw_amount)[source]
Convert raw token units to decimals.
Example:
details = fetch_erc20_details(web3, token_address) # Convert 1 wei units to edcimals assert details.convert_to_decimals(1) == Decimal("0.0000000000000001")
- Parameters
raw_amount (int) –
- Return type
- convert_to_raw(decimal_amount)[source]
Convert decimalised token amount to raw uint256.
Example:
details = fetch_erc20_details(web3, token_address) # Convert 1.0 USDC to raw unit with 6 decimals assert details.convert_to_raw(1) == 1_000_000
- Parameters
decimal_amount (decimal.Decimal) –
- Return type