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.
Copy [
"0x2D2438C6281B5115733287fC279f854c868D3ee2" ,
"0xFFFFFfFF00000000000000000000000000000417"
]
filters
An object of filters used to reduce the the amount of results returned. These filters are best used when looking up a specific token, or in conjuction with the genericTokenIds
when using the amountRange
filter.
e.g.
Copy {
"name" : "Root" ,
"symbol" : "ROOT" ,
"amountRange" : [ "0" , "10000" ]
}
Filter Types
Name
The name of the generic token.
Should be a string
e.g.
Symbol
The symbol of the generic token.
Should be a string
e.g.
Amount Range
The balance amount of the generic token held by the addresses given.
Should be an array of string numbers. The first number represents the minimum and the second number represents the maximum. The second number can be left out if the result should not be bound by the maximum.
e.g.
Usage
React Node.js GraphQL
Copy 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 ] ,
filters : {
name : "Root" ,
symbol : "ROOT" ,
amountRange : [ "0" , "10000" ]
} ,
})
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 >
)
}
Copy import { AssetRegister } from '@futureverse/asset-register/v2'
import { ChainAddress , GenericTokenId } from '@futureverse/asset-register/types'
import { GenericTokenBalanceModel } from '@futureverse/asset-register/models'
const ar = new AssetRegister ({
...
})
const tokenBalances = await ar .genericTokenBalances ({
addresses : [ '0x8bb9a0fff4ff087a5de85ba0e89a5d376ce2a595' as ChainAddress ] ,
filters : {
name : "Root" ,
symbol : "ROOT" ,
amountRange : [ "0" , "10000" ]
} ,
}) .execute ()[ 0 ] as Array < GenericTokenBalanceModel >
Copy query GenericTokenBalances ($addresses: [ ChainAddress ! ] ! , $genericTokenIds: [ GenericTokenId ! ]) {
genericTokenBalances(addresses: $addresses, genericTokenIds: $genericTokenIds) {
amount
genericToken {
chainId
chainType
location
}
owner {
address
}
}
}
Copy {
"addresses" : [ "0x8bb9a0fff4ff087a5de85ba0e89a5d376ce2a595" ] ,
"filters" : {
"name" : "Root" ,
"symbol" : "ROOT" ,
"amountRange" : [ "0" , "10000" ]
}
}
Last updated 2 months ago