convert_balances_to_decimal

Documentation for eth_defi.balances.convert_balances_to_decimal function.

convert_balances_to_decimal(web3, raw_balances, require_decimals=True)[source]

Convert mapping of ERC-20 holdings to decimals.

Issues a JSON-RPC call to fetch token data for each ERC-20 in the input dictionary.

Example:

raw_balances = fetch_erc20_balances_by_token_list(web3, address, tokens)
return convert_balances_to_decimal(web3, raw_balances)
Parameters
  • raw_balances (Dict[HexAddress, int]) – Token address -> uint256 mappings

  • require_decimals – Safety check to ensure ERC-20 tokens have valid decimals set. Prevents some wrong addresses and broken tokens.

Returns

Token address -> DecimalisedHolding mappings

Return type

Dict[HexAddress, eth_defi.balances.DecimalisedHolding]