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

import { Networks } from '@0xsequence/typescript-sdk'
import type { Address } from 'viem'

const walletAddress = oms.wallet.walletAddress
const tokenContract = '0xTokenContract' as Address

if (!walletAddress) {
  throw new Error('No active wallet session')
}

const result = await oms.indexer.getTokenBalances({
  network: Networks.polygon,
  contractAddress: tokenContract,
  walletAddress,
  includeMetadata: true,
})

for (const balance of result.balances) {
  console.log(balance.contractAddress, balance.balance)
}
Parameters
ParameterTypeDescription
networkNetworkSDK network entry, such as Networks.polygon or Networks.amoy.
contractAddressstring or undefinedOptional token contract address filter. Omit it to query balances across contracts.
walletAddressstringWallet address to inspect. This can be the active embedded wallet or any wallet address.
includeMetadatabooleanWhether token metadata should be included in the response.
page{ page?: number; pageSize?: number } or undefinedOptional pagination request. Defaults to page 0 with up to 40 entries.
Returns getTokenBalances returns Promise<TokenBalancesResult>.
FieldTypeDescription
statusnumberHTTP status code from the balance response.
pageTokenBalancesPage or undefinedPagination metadata from the balance response.
balancesTokenBalance[]Balances returned for the wallet.

Get Native Token Balance

import { Networks } from '@0xsequence/typescript-sdk'

const nativeBalance = await oms.indexer.getNativeTokenBalance({
  network: Networks.amoy,
  walletAddress,
})

console.log(nativeBalance?.balance)
Parameters
ParameterTypeDescription
networkNetworkSDK network entry, such as Networks.polygon or Networks.amoy.
walletAddressstringWallet address to inspect.
Returns getNativeTokenBalance returns Promise<TokenBalance | undefined>. It returns undefined when the response does not include a native balance.

Token Balance Shape

Each TokenBalance can include:
FieldTypeDescription
contractTypestring or undefinedToken contract type, such as ERC20, ERC721, or NATIVE.
contractAddressstring or undefinedToken contract address. Native token balances do not include a contract address.
accountAddressstring or undefinedWallet address queried.
tokenIdstring or undefinedToken ID for token types that use IDs.
balancestring or undefinedRaw base-unit balance as a string.
blockHashstring or undefinedBlock hash for the balance snapshot.
blockNumbernumber or undefinedBlock number for the balance snapshot.
chainIdnumber or undefinedNumeric chain ID.