useNFTBalance
Hook to get the quantity a user owns of a specific ERC1155 NFT.
Available to use on smart contracts that implement the ERC1155 standard.
import { useNFTBalance } from "@thirdweb-dev/react";
const { data, isLoading, error } = useNFTBalance(
  contract,
  "{{wallet_address}}",
  "{{token_id}}",
);
Usage
Provide your smart contract instance, the wallet address to check, and the token ID to check.
import { useNFTBalance, useContract } from "@thirdweb-dev/react";
// Your smart contract address
const contractAddress = "{{contract_address}}";
function App() {
  const { contract } = useContract(contractAddress);
  const { isLoading, data, error } = useNFTBalance(
    contract,
    "{{wallet_address}}",
    "{{token_id}}",
  );
}
Configuration
walletAddress (required)
walletAddress (required)
The address of the wallet to check.
Use the useAddress hook to get the current wallet address.
import { useNFTBalance, useContract, useAddress } from "@thirdweb-dev/react";
// Your smart contract address
const contractAddress = "{{contract_address}}";
function App() {
  const address = useAddress();
  const { contract } = useContract(contractAddress);
  const { isLoading, data, error } = useNFTBalance(
    contract,
    address,
    "{{token_id}}",
  );
}
tokenId (required)
tokenId (required)
The token ID of the NFT to check.
import { useNFTBalance, useContract } from "@thirdweb-dev/react";
// Your smart contract address
const contractAddress = "{{contract_address}}";
function App() {
  const { contract } = useContract(contractAddress);
  const { isLoading, data, error } = useNFTBalance(
    contract,
    "{{wallet_address}}",
    "{{token_id}}",
  );
}
Return Value
Return Value
The hook's data property, once loaded, returns a BigNumber representing the quantity of the NFT owned by the wallet.
BigNumber;