Get Token Balance

Overview

This section details how to retrieve token balance using user wallet address and token IDs.

Properties

addresses

A list of addresses used to query tokens.

e.g.

[
    "0x2D2438C6281B5115733287fC279f854c868D3ee2",
    "0xFFFFFfFF00000000000000000000000000000417"
]

genericTokenIds

A list of token IDs to filter tokens on the addresses provided. (Optional)

If this property is not provided, all tokens owned by the above addresses will be retrieved.

e.g.

[
    "7672:root:1"
]

Usage

1. Retrieve balances of specified tokens

import { useGenericTokenBalances } from '@futureverse/asset-register-react/v2'
import { ChainAddress, GenericTokenId } from '@futureverse/asset-register/types'

export const GenericTokenBalances = () => {
  const { genericTokenBalances } = useGenericTokenBalances({
    addresses: ['0x8bb9a0fff4ff087a5de85ba0e89a5d376ce2a595' as ChainAddress],
    genericTokenIds: ['7672:root:1' as GenericTokenId],
  })

   return (
    <div>
      {genericTokenBalances?.map((genericTokenBalance) => {
        return (
          <div>
            <div>{genericTokenBalance.genericToken.chainId}</div>
            <div>{genericTokenBalance.genericToken.location}</div>
            <div>{genericTokenBalance.owner.address}</div>
            <div>{genericTokenBalance.amount}</div>
          </div>
        )
      })}
    </div>
  )
}

2. Retrieve tokens owned by the specified addresses

import { useGenericTokenBalances } from '@futureverse/asset-register-react/v2'
import { ChainAddress, GenericTokenId } from '@futureverse/asset-register/types'

export const GenericTokenBalances = () => {
  const { genericTokenBalances } = useGenericTokenBalances({
    addresses: ['0x8bb9a0fff4ff087a5de85ba0e89a5d376ce2a595' as ChainAddress],
  })

   return (
    <div>
      {genericTokenBalances?.map((genericTokenBalance) => {
        return (
          <div>
            <div>{genericTokenBalance.genericToken.chainId}</div>
            <div>{genericTokenBalance.genericToken.location}</div>
            <div>{genericTokenBalance.owner.address}</div>
            <div>{genericTokenBalance.amount}</div>
          </div>
        )
      })}
    </div>
  )
}

Last updated

© 2023 -> ♾️