Check Balance Token
This method allows you to check your token balance from a particular token address in a blockchain network.
Method Signature
async balanceToken({
tokenAddress: string,
network: Network,
walletToken: string,
refreshToken?: string
}): Promise<CheckBalanceResponse>
Parameters
tokenAddress
:string
- The address of the token.network
:Network
- The network used for transactions. You can use theNetwork
enum to specify the network.walletToken
:string
- The wallet token of the wallet to check the balance for.refreshToken
:string
- The refresh token for authentication. Use this if you want to allow SDK automatically refresh the wallet token.
Returns
Promise<CheckBalanceResponse>
- An object containing the following properties:
balance
:string
- The balance of the token.symbol
:string
- The symbol of the token.address
:string
- The wallet address.walletToken
?:string
- The new wallet token of the wallet.refreshToken
?:string
- The new refresh token of the wallet.
Example Usage
const tokenAddress = '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2';
const balanceInfo = await sdk.wallet.balanceToken({
tokenAddress: tokenAddress,
network: Network.ETHEREUM,
walletToken: 'your-wallet-token',
refreshToken: 'your-refresh-token' // Optional
});
console.log(balanceInfo);
Response Example
{
"balance": "90.0",
"symbol": "WETH",
"address": "0xBfE64B4b628E0998A03e2522B051Cf1B4661c964",
"walletToken": "your-new-wallet-token",
"refreshToken": "your-new-refresh-token"
}
ℹ️
The SDK will automatically refresh the wallet token and return the new wallet token and refresh token if the refresh token is provided.
ℹ️
The response is an object containing the balance, symbol, and address of the specified token for the given network.
Additional Information
- This method requires a valid wallet token in the SDK configuration.
- The balance is returned as a string to preserve precision for large numbers.
- The network parameter determines which blockchain network will be used for checking the token balance.
For more information, see the Xellar Check Balance Token API Documentation (opens in a new tab).