SOL Pay
  • SOL Pay
  • Quick Start
  • Streams
  • Stake Pools
  • Reference
    • SDK Reference
      • connectNetwork
      • connectWallet
      • sendSolanaLamports
      • sendSolana
      • sendTokens
      • sendTokensDecimal
      • signTransaction
      • broadcastSerializedTransaction
      • streamLamports
      • backupStreamWallet
      • getStreamDetails
      • refillStream
      • pauseStream
      • resumeStream
      • closeStream
      • signMessage
      • getBalance
      • getTokenBalances
      • getAccountInfo
      • getAssociatedTokenAddress
      • getTokenBalance
      • tokens.getData
      • tokens.getTags
      • tokens.getToken
      • tokens.search
      • tokens.getRawUnvalidatedList
      • adapters
      • networks
    • API Reference
      • transaction.php
      • token_transaction.php
      • signature.php
  • Website
  • Source Code
Powered by GitBook
On this page
  • Parameters:
  • Returns:
  • Throws:
  1. Reference
  2. SDK Reference

getTokenBalances

Gets the token balances of an account

(async() => {
    let token_balances_1 = await SOLPay.getTokenBalances(); // {"balances": [...]}
    let token_balances_2 = await SOLPay.getTokenBalances("SOLANA_ADDRESS"); // {"balances": [...]}
})();

Parameters:

  • address (optional, default: connected wallet address): string - the Solana address with which to get the token balances

Returns:

object ({"balances": [...]}) - the token balances data

  • balances: Array ([{...}, {...}, ...]) - the list of balances

    • object ({...}) - the balances data of the account

      • raw_data: object ({...}) - the raw data of the account

      • account: object ({...}) - the balance details of the account

        • address: string ("...") - the address of the account

        • lamports: number (10000) - the number of lamports in the account

      • delegate: object ({...}) - the balance details of the delegate account

        • address: string ("...") - the address of the delegate account

        • balance: object ({...}) - the token balance

          • amount: string ("11") - the number of tokens as an integer

          • decimals: number (9) - the number digits after the decimal point in a token

          • uiAmount: number (0.000000011) - the number of tokens as a decimal (deprecated)

          • uiAmountString: string ("0.000000011") - the number of tokens as a decimal in a string form

      • token: object ({...}) - the token balance details

        • address: string ("...") - the address of the token

        • balance: object ({...}) - the token balance

          • amount: string ("11") - the number of tokens as an integer

          • decimals: number (9) - the number digits after the decimal point in a token

          • uiAmount: number (0.000000011) - the number of tokens as a decimal (deprecated)

          • uiAmountString: string ("0.000000011") - the number of tokens as a decimal in a string form

Throws:

  • SOL Pay SDK Fatal Error: Invalid address ${address}, and no wallet was connected. Use SOLPay.connectWallet() to connect to a Solana wallet. - an invalid address was used, and no wallet was connected

  • SOL Pay SDK Fatal Error: No connection found. Use SOLPay.connectNetwork() to connect to the Solana network. - could not find a connection to the Solana network

  • SOL Pay SDK Fatal Error: Connection did not respond. Use SOLPay.connectNetwork() to connect to the Solana network. - did not receive response from Solana network

PreviousgetBalanceNextgetAccountInfo

Last updated 3 years ago