Wander Docs
HomeGithub
  • ๐Ÿ‘‹Welcome to Wander
  • โ›๏ธDeveloper tooling
    • Wander Devtools
    • ArLocal Devtools
  • ๐Ÿ“šExternal libraries
    • Arweave Wallet Kit
    • arweave-js
  • ๐Ÿ”ญDemos
    • Applications
  • ๐ŸงชAPI
    • Intro
    • Events
    • Connect
    • Disconnect
    • Get active address
    • Get active public key
    • Get all addresses
    • Get wallet names
    • Sign Transaction
    • Dispatch Transaction
    • Sign DataItem
    • Batch Sign DataItem
    • Sign message
    • Verify message
    • Private hash
    • User Tokens
    • Token Balance
    • Encrypt
    • Decrypt
    • Crypto signature
    • Subscriptions
    • Retrive permissions
    • Retrive Gateway Config
  • ๐ŸŒWander.app
Powered by GitBook
On this page
  • Result
  • Example usage

Was this helpful?

Edit on GitHub
  1. API

Token Balance

Wander Injected API tokenBalance() function

PreviousUser TokensNextEncrypt

Last updated 6 months ago

Was this helpful?

Some applications may request access to the balance of a specific token in your wallet. The tokenBalance() function returns the balance of the token identified by its ID.

Argument
Type
Description

id

string

The unique identifier (processId) of the token

Note: This function requires the permission.

Result

The tokenBalance() function returns the balance of the requested token as a string.

Note: This function throws an error if there is an issue retrieving the balance. Please make sure to handle such cases in your code.

export type TokenBalanceResult = string;

Example usage

// Connect to the extension and request access to the ACCESS_TOKENS permission
await window.arweaveWallet.connect(["ACCESS_TOKENS"]);

// Retrieve the list of tokens owned by the user
const tokens = await window.arweaveWallet.userTokens();
console.log("Tokens owned by the user:", tokens);

try {
  // Retrieve the balance of a user token
  const tokenId = tokens[0].processId
  const balance = await window.arweaveWallet.tokenBalance(tokenId);
  console.log(`Balance of the token with ID ${tokenId}:`, balance);
} catch (error) {
  console.error("Error fetching token balance:", error);
}
๐Ÿงช
ACCESS_TOKENS