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

    Function getBalance

    • Get the balance of AVAX controlled by a given address.

      This function does not call platform.getBalance, because AvalancheGo deprecated that method and will remove it. It reads all UTXOs of the addresses with platform.getUTXOs (one request for each 1024 UTXOs and each 1024 addresses) and adds them up with the rules of platform.getBalance. It gets the AVAX asset ID with platform.getStakingAssetID. It uses the local clock to find which outputs are locked.

      When it needs more than 1 platform.getUTXOs request, the requests do not read 1 state of the chain. A load balancer can send them to different nodes, and the chain can accept a transaction between 2 requests. So it reads all UTXOs again until 2 reads return the same UTXOs (at most 3 reads). If all 3 reads are different, it uses the last read.

      Type Parameters

      • chain extends undefined | Chain

      Parameters

      Returns Promise<GetBalanceReturnType>

      The balance information. GetBalanceReturnType

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

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

      const balance = await getBalance(client, {
      addresses: ["P-custom18jma8ppw3nhx5r4ap8clazz0dps7rv5u9xde7p"]
      })