Standard Token Interface#
Note
Entro provides basic support for ERC20 tokens. This support will expand later to encompass more token standards and additional functionality
ERC20 Token Usage#
Initializing an ERC20Token from an address#
from web3 import Web3
from nethermind.entro import ERC20Token
w3 = Web3(Web3.HTTPProvider("http://******"))
weth_token = ERC20Token.from_chain(w3, "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2")
Reading Token Paramters#
>>> weth_token.name
'Wrapped Ether'
>>> weth_token.symbol
'WETH'
>>> weth_token.decimals
18
ERC20Token API#
- class nethermind.entro.tokens.ERC20Token#
Class for representing ERC20 Tokens. Can be initialized from on-chain token, and will query token constants from contract.
Can be used to convert raw token amounts into human-readable amounts.
- __init__(name: str, symbol: str, decimals: int, address: ChecksumAddress | str, w3: Web3 | None = None) None #
- convert_decimals(raw_token_amount: int) float #
Divides raw token amounts by token decimals.
- Parameters:
raw_token_amount (int) – Raw token amount
- Returns:
Token amount adjusted by decimals
- classmethod from_chain(w3: Web3, token_address: ChecksumAddress | str) ERC20Token #
Initialize ERC20Token from on-chain token address. Fetches token name, symbol, and decimals from contract. If token_address is invalid, raises ___
- Parameters:
w3 –
Web3
RPC connection to EVM nodetoken_address – hex address of ERC20 token contract
- Returns:
- classmethod from_dict(w3: Web3, token_params: dict[str, Any]) ERC20Token #
Initialize ERC20Token from dictionary. Dictionary must contain keys: name, symbol, decimals, and address.
- Parameters:
- Returns:
- classmethod get_abi(json_string: bool = False) dict[str, Any] | str #
Returns ABI for ERC20 Token Contract.
- Parameters:
json_string (bool) –
If true, returns ABI as a JSON string. Otherwise, returns ABI as a dictionary.
Default: False
- Returns:
- human_readable(raw_token_amount: int) str #
Converts raw token amount to human-readable string containing the correct decimals and the token symbol.
- Parameters:
raw_token_amount – raw token amount
- Returns:
Human-readable string containing token amount and symbol
- to_dict() dict[str, Any] #
Returns dictionary containing token parameters. Typically used for JSON encoding ERC20 tokens
- Returns:
- address: ChecksumAddress#
Checksum Address of the Token Contract