How to verify NFT ownership in a collection

GoldRush TeamUpdated 11 min read

Check if a wallet owns an NFT with ERC-721 ownerOf and balanceOf, ERC-1155 balanceOf or one API call, then gate access safely with Sign-In with Ethereum.

To verify that a wallet owns an NFT, ask the collection's contract: for an ERC-721 token, ownerOf(tokenId) returns the one address that owns it and balanceOf(wallet) says how many of the collection's tokens a wallet holds; for ERC-1155, balanceOf(wallet, id) returns the wallet's balance of one token ID. You can make those calls yourself over JSON-RPC, or use an NFT API that answers "does this wallet hold this collection, and which tokens?" in one request. Before you grant anything, also make the user prove they control the wallet, usually with a Sign-In with Ethereum signature.

How NFT ownership is recorded

An NFT's owner is whatever its contract says. There is no separate registry: the contract's storage maps each token to its owner (ERC-721) or each owner and token ID to a balance (ERC-1155), and every transfer updates it. The standards define the read functions you call:

Standard Function Returns Selector
ERC-721 ownerOf(uint256 tokenId) The address that owns the token 0x6352211e
ERC-721 balanceOf(address owner) How many of the collection's tokens it holds 0x70a08231
ERC-1155 balanceOf(address owner, uint256 id) How many of one token ID it holds 0x00fdd58e

A few rules from the standards matter for ownership checks:

  • ownerOf reverts for a token that doesn't exist. EIP-721 treats a token assigned to the zero address as invalid and says queries about it throw, so a burned or never-minted ID returns an error, not an empty address.
  • ERC-1155 has no ownerOf. In EIP-1155 one token ID can have many holders, so you ask for a balance instead, or several at once with balanceOfBatch.
  • A contract won't list what a wallet holds. balanceOf gives a count, not token IDs. The optional ERC-721 enumeration extension adds tokenOfOwnerByIndex, but many collections don't implement it, and nothing on chain lists a wallet's NFTs across collections.
  • You can check which standard a contract uses. Both standards implement EIP-165 supportsInterface: 0x80ac58cd is ERC-721 and 0xd9b67a26 is ERC-1155.

Check ownership onchain with JSON-RPC

Any Ethereum node answers these reads through eth_call, which runs a contract function without sending a transaction. The call data is the 4-byte selector followed by each argument padded to 32 bytes. This asks the Bored Ape Yacht Club contract who owns token #1:

curl https://ethereum-rpc.publicnode.com \  -H "Content-Type: application/json" \  -d '{"jsonrpc":"2.0","id":1,"method":"eth_call","params":[{"to":"0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d","data":"0x6352211e0000000000000000000000000000000000000000000000000000000000000001"},"latest"]}'

On 20 November 2026 (block 26,455,095) it returned the owner's address in the last 20 bytes of the result:

{    "jsonrpc": "2.0",    "id": 1,    "result": "0x00000000000000000000000046efbaedc92067e6d60e84ed6395099723252496"}

The same checks in JavaScript, with no library. Before you run it:

  • Node.js 18 or later for the built-in fetch (the code was run on Node 22).
  • One file for every JavaScript block on this page. Later blocks reuse BAYC, tokensHeld and the helpers from earlier ones, so add each block to the end of the same file. Save it as nft-ownership.mjs, so Node runs it as an ES module and top-level await works, and run it with node nft-ownership.mjs.
  • A GoldRush API key in the GOLDRUSH_API_KEY environment variable, from the GoldRush section on.
  • viem, for the token gate only.
const RPC = "https://ethereum-rpc.publicnode.com"; // eth_call runs a read-only contract function and returns its raw ABI-encoded result.async function ethCall(to, data) {    const res = await fetch(RPC, {        method: "POST",        headers: { "Content-Type": "application/json" },        body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "eth_call", params: [{ to, data }, "latest"] }),    });    const { result, error } = await res.json();    if (error) throw new Error(error.message); // ownerOf reverts for a token that doesn't exist    return result;} // ABI encoding: every argument is one 32-byte word.const addressWord = (address) => address.toLowerCase().replace(/^0x/, "").padStart(64, "0");const uintWord = (n) => BigInt(n).toString(16).padStart(64, "0"); // ERC-721 ownerOf(uint256), selector 0x6352211e: the one address that owns this token.async function ownerOf(collection, tokenId) {    const result = await ethCall(collection, "0x6352211e" + uintWord(tokenId));    return "0x" + result.slice(-40);} // ERC-721 balanceOf(address), selector 0x70a08231: how many of the collection's tokens the wallet holds.async function balanceOf721(collection, wallet) {    return BigInt(await ethCall(collection, "0x70a08231" + addressWord(wallet)));} // ERC-1155 balanceOf(address,uint256), selector 0x00fdd58e: how many of one token ID the wallet holds.async function balanceOf1155(collection, wallet, id) {    return BigInt(await ethCall(collection, "0x00fdd58e" + addressWord(wallet) + uintWord(id)));} const BAYC = "0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d";const owner = await ownerOf(BAYC, 1);console.log("BAYC #1 is owned by", owner);console.log("BAYC tokens in that wallet:", await balanceOf721(BAYC, owner));

Run on the same day, it printed the address above and a balance of 1n. Asking for token #10000, which doesn't exist, threw execution reverted: ERC721: owner query for nonexistent token.

This is the most direct check there is, and it's enough for one collection on one chain. It gets harder when you need to:

  • List the tokens, not just count them. balanceOf says a wallet holds three; to know which three you need the enumeration extension or the collection's whole Transfer history.
  • Check many collections or chains. Each is a separate contract call to a separate node, and each chain needs its own RPC endpoint.
  • Gate on traits. Traits live in off-chain metadata, so a "Gold background holders only" rule means fetching and parsing every token's tokenURI.
  • Accept ENS names. Users type name.eth; the contract only knows addresses.

That's the work an indexer does ahead of time, which is why ownership checks are a standard part of an NFT API.

Check ownership with the GoldRush API

GoldRush has two ownership endpoints. Both take ERC-721 and ERC-1155 collections and resolve ENS names in the wallet field:

The collection check costs 1 per call and the token check 1 per call, whatever the wallet holds.

You need a GoldRush API key: sign up for the 14-day free trial, which includes 25,000 credits. Send it in an Authorization: Bearer header:

API=https://api.covalenthq.com/v1BAYC=0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d # Which BAYC tokens does vitalik.eth hold?curl "$API/eth-mainnet/address/vitalik.eth/collection/$BAYC/" \  -H "Authorization: Bearer $GOLDRUSH_API_KEY" # Does it hold token #1?curl "$API/eth-mainnet/address/vitalik.eth/collection/$BAYC/token/1/" \  -H "Authorization: Bearer $GOLDRUSH_API_KEY"

Each response has the wallet and collection you asked about and an items array with one entry per token the wallet holds, carrying token_id, balance (a string, which matters for ERC-1155), supports_erc and the token's nft_data. In JavaScript, added to the same file (it reuses BAYC):

const API = "https://api.covalenthq.com/v1";const headers = { Authorization: `Bearer ${process.env.GOLDRUSH_API_KEY}` }; // Errors come back as { data: null, error: true, error_code, error_message }; a request with no// Authorization header gets an HTML 401 from the edge instead, so don't assume the body is JSON.async function get(path) {    const res = await fetch(`${API}${path}`, { headers });    const body = await res.json().catch(() => null);    if (!res.ok || !body || body.error) {        throw new Error(`GoldRush ${body?.error_code ?? res.status}: ${body?.error_message ?? res.statusText}`);    }    return body.data;} // The collection's tokens this wallet holds. An empty list means it holds none.async function tokensHeld(chain, wallet, collection) {    const data = await get(`/${chain}/address/${wallet}/collection/${collection}/`);    return data.items        .filter((item) => BigInt(item.balance ?? 0) > 0n)        .map((item) => ({ tokenId: item.token_id, balance: item.balance }));} // Does this wallet hold this one token ID?async function holdsToken(chain, wallet, collection, tokenId) {    const data = await get(`/${chain}/address/${wallet}/collection/${collection}/token/${tokenId}/`);    return data.items.some((item) => item.token_id === String(tokenId) && BigInt(item.balance ?? 0) > 0n);} console.log(await tokensHeld("eth-mainnet", "vitalik.eth", BAYC));console.log(await holdsToken("eth-mainnet", "vitalik.eth", BAYC, 1));

Handle errors from the ownership checks

A failed request returns the same envelope as a successful one, with data set to null, and get turns it into an exception. The error handling docs show this body for a chain the API doesn't serve:

{ "data": null, "error": true, "error_message": "Chain nosuchchain-mainnet not supported.", "error_code": 501 }

A 501 is a stable answer: the chain or endpoint can't serve the request, so retrying it unchanged returns the same error. Check the chain name against the list below. A request with no Authorization header is refused by the edge proxy with an HTML 401 page rather than JSON, which is why get doesn't assume the body parses. For a token gate, treat any error as "not verified" and deny access rather than letting the user through. Error responses cost no credits.

Chains the ownership checks cover

Change the chain name to check the same wallet elsewhere. The collection check works on 6 chains (Ethereum, Polygon, Base, Optimism, BNB Smart Chain (BSC), and Gnosis) and the token check on 6. To list everything a wallet holds across collections instead, use NFTs for an address.

Build a token gate

A token gate gives access (a page, a Discord role, a mint, an event ticket) only to holders of a collection. Checking ownership is half of it. The other half is proving that the person in front of you controls the wallet: addresses are public, so anyone can paste the address of a well-known holder.

Sign-In with Ethereum (EIP-4361) is the standard way to do that. Your server issues a random nonce, the wallet signs a plain-text message that names your domain and that nonce, and the server checks the signature before it trusts the address. The domain stops a signature made for another site from working on yours, and the nonce stops an old signature being replayed. Smart contract wallets sign through EIP-1271, so verify with a library that supports it rather than recovering the signer yourself. This server-side check uses viem, then the tokensHeld function above. Install viem at the version it was run on:

npm install viem@2.52.2

Then add the check to the same file:

import { createPublicClient, http } from "viem";import { mainnet } from "viem/chains";import { parseSiweMessage, verifySiweMessage } from "viem/siwe"; const client = createPublicClient({ chain: mainnet, transport: http("https://ethereum-rpc.publicnode.com") }); // The wallet signed a SIWE message carrying a nonce your server issued for this session.async function canEnter({ message, signature }, nonce) {    const signed = await verifySiweMessage(client, { message, signature, domain: "example.com", nonce });    if (!signed) return false;    const { address } = parseSiweMessage(message);    const tokens = await tokensHeld("eth-mainnet", address, BAYC);    return tokens.length > 0;}

verifySiweMessage returns false when the signature is from another wallet or the domain or nonce doesn't match, so a holder's address alone never gets in. Store the nonce server-side, use it once, and recheck ownership when the session renews: NFTs can be sold a minute after sign-in.

NFT ownership check pitfalls: staking, delegation, ERC-1155 and bridges

  • Staked or escrowed tokens. When a holder deposits an NFT into a staking, lending or marketplace escrow contract, ownerOf returns that contract, not the holder, and a plain ownership check says they hold nothing. If your community stakes, read who deposited each token from the staking contract, or decide that staked tokens don't count and say so.
  • Delegated wallets. Many holders keep valuable NFTs in a cold wallet and sign in with a hot wallet. delegate.xyz runs an onchain registry where a cold wallet names a hot wallet as its delegate for the whole wallet, one contract or one token; it's at 0x00000000000000447e69651d841bD8D104Bed493 on Ethereum and many other chains. To support it, look up which vaults have delegated to the signed-in wallet, then check ownership for those vaults.
  • ERC-1155 balances. A balance can be more than one, and several wallets can hold the same token ID. If the gate needs a minimum, compare balance with it rather than checking that a token exists.
  • The same token on several chains. A bridged or multichain collection has a different contract address per chain. Check the chain the gate is about, with that chain's address.
  • Ownership changes. A check is true at the block it was made. For high-value access, recheck near the moment you grant it.
  • Spam lookalikes. Anyone can deploy a contract named after a famous collection. Gate on the contract address, never on the name or symbol.

Frequently asked questions

How do I check if a wallet owns an NFT?

For an ERC-721 token, call the collection contract's ownerOf(tokenId) and compare the result with the wallet, or call balanceOf(wallet) to see whether it holds any of the collection. For ERC-1155, call balanceOf(wallet, tokenId). An NFT API does the same in one request and returns which tokens the wallet holds.

What is the difference between ownerOf and balanceOf?

ownerOf is ERC-721 only and answers "who owns this token ID?" with one address. balanceOf(owner) answers "how many of this collection's tokens does this wallet hold?" with a number, and ERC-1155's balanceOf(owner, id) gives the wallet's balance of one token ID, since many wallets can hold it.

Is checking a wallet address enough for token gating?

No. Wallet addresses are public, so anyone can claim to own a holder's address. Ask the user to sign a Sign-In with Ethereum (EIP-4361) message with a nonce you issued, verify the signature server-side, and only then check ownership for the address that signed.

How do I verify ownership of an NFT that is staked?

A staked NFT is owned by the staking contract, so ownerOf and ownership APIs show the contract, not the holder. Read the depositor from the staking contract itself, which records who staked each token, or treat staked tokens as not held.

Can I check NFT ownership across several chains?

Yes, one chain at a time. Onchain, call each chain's contract through that chain's RPC endpoint. With GoldRush, change the chain name in the request: the collection check works on 6 chains and the token check on 6.

How much does the GoldRush NFT ownership check cost?

The collection check costs 1 per call and the specific-token check 1 per call, whatever the wallet holds. The 14-day free trial includes 25,000 credits.

Next steps

Get new guides by email

New tutorials and best practices for building with blockchain data, sent as they're published.