Function get_contract_token_decimals

Source
pub async fn get_contract_token_decimals<P>(
    provider: &P,
    contract_address: &str,
) -> Option<u32>
Expand description

Attempts to fetch decimals for a contract token by invoking the contract’s decimals() function.

This implementation uses multiple strategies:

  1. First tries to invoke the contract’s decimals() function (SEP-41 standard)
  2. Falls back to querying contract data storage if invocation fails
  3. Returns None if all methods fail

§Arguments

  • provider - Stellar provider for querying ledger entries and invoking contracts
  • contract_address - Contract address in StrKey format (must be valid ContractId)

§Returns

Some(u32) if decimals are found, None if decimals cannot be determined. Logs warnings for debugging when decimals cannot be fetched.

§Note

This function assumes the contract follows SEP-41 token interface with a decimals() function. Non-standard tokens may not have this function.