Avalanche SDK Client - v0.0.4-alpha.14
    Preparing search index...

    Function getBalance

    • Get the balance of an asset controlled by given addresses.

      Type Parameters

      • chain extends undefined | Chain

      Parameters

      Returns Promise<GetBalanceReturnType>

      The balance of the asset. GetBalanceReturnType

      avm.getBalance is deprecated in AvalancheGo, and AvalancheGo plans to remove it in an upcoming release. Use getUTXOs instead: page through all UTXOs, decode each with getUtxoFromBytes from @avalanche-sdk/client/utils, and add the amounts of the asset's secp256k1fx transfer outputs that only this address owns (threshold 1) and whose locktime has passed. avm.getBalance skips all other outputs.

      import { createAvalancheCoreClient } from '@avalanche-sdk/client'
      import { avalanche } from '@avalanche-sdk/client/chains'
      import { getBalance } from '@avalanche-sdk/client/methods/xChain'

      const client = createAvalancheCoreClient({
      chain: avalanche,
      transport: {
      type: "http",
      url: "<url>",
      },
      })

      const balance = await getBalance(client, {
      addresses: ["X-avax18jma8ppw3nhx5r4ap8clazz0dps7rv5ukulre5"],
      assetID: "FvwEAhmxKfeiG8SnEvq42hc6whRyY3EFYAvebMqDNDGCgxN5Z"
      })