Skip to main content

getBalance

The getBalance method for the ERC-721 token standard provides the number of tokens owned by a specific Ethereum address. Unlike ERC20's balance, which reflects a quantity, the balance for ERC-721 reflects the count of unique, non-fungible tokens owned by an address. The method is part of the ERC721Instance object, which is obtainable via an appropriate method of the EdexaClient or the corresponding library.

Method Signature

getBalance(address: string): Promise<BigNumber>

Parameters

ParameterTypeDescription
addressstringThe Ethereum address for which you want to retrieve the count of ERC-721 tokens owned.

Returns

  • A Promise resolving to a BigNumber that indicates the count of ERC-721 tokens owned by the provided Ethereum address.

Usage Example

First, instantiate the desired ERC-721 token contract:

const erc721 = edexaClient.getERC721Instance("your ERC-721 contract address here");

Then, call the getBalance method for the desired Ethereum address:

const address = "0x2c360D20cE6b3D8b466511eF093C9177c3817B94";
const tokenCount = await erc721.getBalance(address);
console.log(`Token Count: ${tokenCount.toString()}`);

Notes

  • ERC-721 tokens are non-fungible, meaning each token is unique. The getBalance method provides a count of these unique tokens owned by an address, not a sum like in ERC-20.

  • Ensure that the Ethereum address provided is valid; otherwise, the method might throw an error or return inaccurate data.