dxsp.utils.token_utils.Token#

class dxsp.utils.token_utils.Token(**kwargs)[source]#

Bases: object

Class 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

__init__()[source]#

Initializes an instance of the class.

fetch_data()[source]#

Retrieves data for the token.

get_token_abi()[source]#

Retrieves the token abi.

get_token_contract()[source]#

Retrieves the token contract.

get_contract_function()#

Retrieves the contract functions by name.

get_token_balance()[source]#

Retrieves the token balance.

get_token_symbol()[source]#

Retrieves the token symbol.

get_token_name()[source]#

Retrieves the token name.

get_token_decimals()[source]#

Retrieves the token decimals.

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

fetch_data()

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.

get_token_contract()

Retrieves the token contract.

get_token_decimals()

Get the number of decimal places for the token.

get_token_name()

Get the name of the token.

get_token_symbol()

Retrieves the symbol of the token.

async fetch_data() None[source]#

Retrieves data for 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_contract()[source]#

Retrieves the token contract.

Returns:

The token contract.

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

async get_token_name()[source]#

Get the name of the token.

Parameters:

self – The object itself.

Returns:

The name of the token as a string.

async get_token_decimals()[source]#

Get the number of decimal places for the token.

Returns:

The number of decimal places for the token.

Return type:

int