TokenDetails

Documentation for eth_defi.token.TokenDetails class.

class TokenDetails[source]

A helper class to detail with token instructions.

Any field can be None for non-wellformed tokens.

Attributes summary

address

The address of this token.

decimals

Number of decimals

name

Token name e.g.

symbol

Token symbol e.g.

total_supply

Token supply as raw units

contract

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.

contract: web3.contract.Contract

The underlying ERC-20 contract proxy class instance

name: Optional[str] = None

Token name e.g. USD Circle

symbol: Optional[str] = None

Token symbol e.g. USDC

total_supply: Optional[int] = None

Token supply as raw units

decimals: Optional[int] = None

Number of decimals

property address: 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

decimal.Decimal

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

int

__init__(contract, name=None, symbol=None, total_supply=None, decimals=None)
Parameters
Return type

None