Skip to main content
Version: v1.3

Get Balance

Once you have your L1 assets on L2, you might want to check their balance. This guide explains how to do so by calling the three functions getL2BalanceBaseTokens, getL2BalanceNativeTokensand getL2NFTAmount for the corresponding token types.

Example Code

  1. Get the AgentID from the sender by calling ISC.sandbox.getSenderAccount().
ISCAgentID memory agentID = ISC.sandbox.getSenderAccount();
  1. To get the base token balance, you can call getL2BalanceBaseTokens using the agentID.
uint64 baseBalance = ISC.accounts.getL2BalanceBaseTokens(agentID);
  1. To get the native token balance of a specific NativeTokenID, use ISC.accounts.getL2BalanceNativeTokens with the id and agentID.
NativeTokenID memory id = NativeTokenID({ data: nativeTokenID});
uint256 nativeTokens = ISC.accounts.getL2BalanceNativeTokens(id, agentID);
  1. To get the number of NFTs, use ISC.accounts.getL2NFTAmount with the agentID.
uint256 nfts = ISC.accounts.getL2NFTAmount(agentID);

Full Example Code

packages/evm/evmtest/wiki_how_tos/GetBalance.sol
loading...