get_token_supply

Function

def get_token_supply(token_address, decimals=False):
    token_contract = load_contract(token_address)
    token_info = get_token_info(token_address)
    token_supply = token_contract.functions.totalSupply().call()
    if decimals:
        return token_supply
    else:
        return float(round(from_token_decimals(token_supply, token_info['decimals']), 15))

Description

  • Load the contract from token address

  • Get the token info from token address

  • Get the token total supply

  • If decimals is set to False then remove 18 decimal places

  • Return the token supply as integer/float