Embedded Wallets
SDK
Javascript
How to
Wallet Operation
Check Balance Coin

Check Balance Coin

This method allows you to check your native balance coin from a blockchain network.

Method Signature

async balanceCoin({ network: Network, walletToken: string, refreshToken?: string} ): Promise<CheckBalanceResponse>

Parameters

  • network: Network - The network used for transactions. You can use the Network enum to specify the network.
  • walletToken: string - The wallet token of the wallet to check the balance for.
  • refreshToken: string (optional) - 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 native coin.
  • symbol: string - The symbol of the native coin.
  • isPermissionGranted: boolean - Whether the user has granted permission to the connected app.
  • acceptPermissionPage: string - URL to the permission acceptance page in Xellar Passport.
  • walletToken: string - The new wallet token of the wallet.
  • refreshToken?: string - The new refresh token of the wallet.

Example Usage

const balanceInfo = await sdk.wallet.balanceCoin({ 
  network: Network.ETHEREUM, 
  walletToken: 'your-wallet-token', 
  refreshToken: 'your-refresh-token' // Optional
});
console.log(balanceInfo);

Response Example

{
  "balance": "0.02",
  "symbol": "ETH",
  "isPermissionGranted": true,
  "acceptPermissionPage": "https://passport.xellar.co/permissions/accept",
  "walletToken": "your-new-wallet-token",
  "refreshToken": "your-new-refresh-token"
}

Error Response (407 - Permission Required)

If the user hasn't granted permission to the connected app, the SDK will throw an error with status code 407:

{
  "status": 407,
  "message": "Permission required. Please visit https://passport.xellar.co/permissions/accept to grant permission to this application.",
  "data": {
    "isPermissionGranted": false,
    "acceptPermissionPage": "https://passport.xellar.co/permissions/accept"
  }
}
ℹ️

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 permission status for the specified network. If permission is not granted, users will need to visit the acceptPermissionPage to grant access.

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's balance will be checked.

For more information, see the Xellar Check Balance Coin API Documentation (opens in a new tab).