Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.polygon.technology/llms.txt

Use this file to discover all available pages before exploring further.

Use oms.indexer for wallet balance reads. Requests use the project access key configured on OMSClient, and balance amounts are returned as raw base-unit strings.

Get Token Balances

let result = try await oms.indexer.getTokenBalances(
    network: .polygon,
    contractAddress: "0xTokenContract",
    walletAddress: oms.wallet.walletAddress,
    includeMetadata: true
)

for balance in result.balances {
    let displayBalance = try formatUnits(value: balance.balance ?? "0", decimals: 6)
    print(balance.contractAddress ?? "", displayBalance)
}
Parameters
ParameterTypeDescription
networkNetworkSupported SDK network, such as .polygon or .polygonAmoy.
contractAddressStringToken contract address to query.
walletAddressStringWallet address to inspect. This can be the active embedded wallet or any wallet address.
includeMetadataBoolWhether token metadata should be included in the response.
Returns getTokenBalances returns TokenBalancesResult.
FieldTypeDescription
statusIntHTTP status code from the balance response.
pageTokenBalancesPage?Pagination metadata from the balance response.
balances[TokenBalance]Balances returned for the wallet and contract.

Get Native Token Balance

let nativeBalance = try await oms.indexer.getNativeTokenBalance(
    network: .polygonAmoy,
    walletAddress: oms.wallet.walletAddress
)

print(nativeBalance?.balance ?? "0")
Parameters
ParameterTypeDescription
networkNetworkSupported SDK network, such as .polygon or .polygonAmoy.
walletAddressStringWallet address to inspect.
Returns getNativeTokenBalance returns TokenBalance?. It returns nil when the response does not include a native balance.

Token Balance Shape

Each TokenBalance may include:
FieldTypeDescription
contractTypeString?Token contract type, such as ERC20, ERC721, or NATIVE.
contractAddressString?Token contract address. Native token balances do not include a contract address.
accountAddressString?Wallet address queried.
tokenIdString?Token ID for token types that use IDs.
balanceString?Raw base-unit balance as a string.
blockHashString?Block hash for the balance snapshot.
blockNumberInt64?Block number for the balance snapshot.
chainIdInt64?Numeric chain ID.