getTokenBalance()

Gets the number of tokens a user owns in their currently connected wallet.

Response

Example Usage

// ERC721
const erc721Count = await contract.getTokenBalance();

console.log(erc721Count); // 0, 1, etc..

// ERC1155
const tokenId = 0;
const erc1155Count = await contract.getTokenBalance(tokenId);

console.log(erc1155Count); // 0, 1, etc..

📘

tokenId is required when the contract type is ERC1155.

Logging

The SDK will prefix all logs from getTokenBalance() with HM (getTokenBalance) -

Possible Errors

  • Token id required - When tokenId is not provided for an ERC1155 contract
  • Errors in the connect() function

Feedback

Something not quite right, unclear or can't find what you are looking for? Please let us know at support.moonpay.com and we will get back to you as soon as we can.