pub async fn get_token_metadata<P>(
provider: &P,
asset_id: &str,
) -> Result<StellarTokenMetadata, StellarTransactionUtilsError>Expand description
Fetch token metadata for a given asset identifier.
Determines the token kind and fetches appropriate metadata:
- Native XLM: decimals = 7, canonical_asset_id = “native”
- Accepts “native”, “XLM”, or empty string “” (empty string is treated as native XLM)
- Classic assets (CODE:ISSUER): decimals = 7 (default), canonical_asset_id = asset
- Code must be 1-12 characters, issuer must be a valid Stellar address (G…)
- Contract tokens: queries contract for decimals, canonical_asset_id = contract_id
- Must be a valid StrKey-encoded contract address (C…)
§Arguments
provider- Stellar provider for querying ledger entriesasset_id- Asset identifier:- “native”, “XLM”, or “” (empty string) for XLM
- “CODE:ISSUER” for traditional assets (e.g., “USDC:GA5Z…”)
- Contract address (StrKey format starting with “C”) for Soroban contract tokens
§Returns
Token metadata including kind, decimals, and canonical asset ID, or error if metadata cannot be fetched
§Errors
Returns RelayerError::Internal if:
- Asset identifier format is invalid
- Asset code is empty or exceeds 12 characters
- Issuer address is invalid (not 56 chars, doesn’t start with ‘G’, or invalid format)
- Contract address is invalid StrKey format