getBalance
The getBalance
method for the ERC-1155 token standard retrieves the balance of a specific token ID owned by a specified Ethereum address. Unlike ERC-721, which tracks ownership of individual unique tokens, ERC-1155 allows users to own multiple quantities of a particular token type. The method is part of the ERC1155Instance
object, which can be obtained through an appropriate method of the ZkyugaClient
or the relevant library.
Method Signature
getBalance(userAddress: string, id: string): Promise<BigNumber>
Parameters
userAddress
string
The Ethereum address for which you want to retrieve the token balance.
id
string
The specific ID of the ERC-1155 token for which the balance is being checked.
Returns
A
Promise
resolving to aBigNumber
that indicates the balance of the specified ERC-1155 token ID owned by the given Ethereum address.
Usage Example
First, instantiate the desired ERC-1155 token contract:
const erc1155 = zkyugaClient.getERC1155Instance("your ERC-1155 contract address here");
Then, call the getBalance
method for the desired Ethereum address and token ID:
const userAddress = "0xBbF289D846208c16EDc8474705C748aff07732dB";
const tokenId = "token-specific-id";
const tokenBalance = await erc1155.getBalance(userAddress, tokenId);
console.log(`Token Balance for ID ${tokenId}: ${tokenBalance.toString()}`);
Notes
ERC-1155 is a multi-token standard where a user can own multiple quantities of a specific token type. The
getBalance
method provides the balance for a specific token ID owned by an address.Always ensure the validity of the Ethereum address and token ID provided; otherwise, the method might throw an error or return inaccurate results.
Last updated