dxsp.utils.token_utils.Token#
- class dxsp.utils.token_utils.Token(**kwargs)[source]#
Bases:
objectClass Token to interact with web3 token contract
- Parameters:
w3 – An instance of the web3 library.
address – The address of the token contract.
block_explorer_url – The URL of the block explorer for the token.
block_explorer_api – The API endpoint of the block explorer for the token.
symbol – The symbol of the token.
- Returns:
Token
- get_contract_function()#
Retrieves the contract functions by name.
Initializes an instance of the class.
- Parameters:
w3 (object) – An instance of the web3 library.
address (str) – The address of the token contract.
block_explorer_url (str) – The URL of the block explorer for the token.
block_explorer_api (str) – The API endpoint of the block explorer for the token.
symbol (str) – The symbol of the token.
Methods
Retrieves data for the token.
get_token_abi([address])Retrieves the ABI (Application Binary Interface) of a token contract at the given address.
get_token_balance(wallet_address)Get the balance of a token for a given wallet address.
Retrieves the token contract.
Get the number of decimal places for the token.
Get the name of the token.
Retrieves the symbol of the token.
- async get_token_abi(address=None)[source]#
Retrieves the ABI (Application Binary Interface) of a token contract at the given address. First, it tries to fetch the ABI from the block explorer if the block explorer url and api key are provided. If not, it tries to fetch the ABI from the dex ERC20 ABI URL
- Parameters:
address (str, optional) – The address of the token contract.
provided (If not) – contract instance is used. Defaults to None.
the (the address associated with) – contract instance is used. Defaults to None.
- Returns:
The ABI of the token contract, if successful. None if the request fails or the contract does not have an ABI.
- Return type:
str
- async get_token_balance(wallet_address)[source]#
Get the balance of a token for a given wallet address.
- Parameters:
wallet_address (str) – The wallet
for. (address to check the balance)
- Returns:
The balance of the token in ether.
- Return type:
float
- Raises:
None –
- async get_token_symbol()[source]#
Retrieves the symbol of the token.
- Returns:
The symbol of the token.
- Return type:
str