useNFTBalance
Hook for getting the balance of a specific NFT token owned by a wallet address.
import { useNFTBalance } from "@thirdweb-dev/react";
Usage
Provide your NFT collection contract and the wallet address of the owner.
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}}"
);
if (error) {
console.error("failed to get balance", error);
}
return <p>Balance: {isLoading ? "Loading..." : data}</p>;
}