Check an NFT owner with Ethereum RPC
Use the standard ERC-721 ownerOf call to verify who owns a token, and learn when an NFT-specific API or indexer is needed to find broader NFT data.
To check the current owner of one ERC-721 token, call the contract’s ownerOf(tokenId) method with eth_call. This uses standard Ethereum JSON-RPC; it does not require an NFT-specific API. Enhanced NFT APIs and indexers are useful for tasks such as listing all NFTs held by an address, retrieving metadata, or querying transfer history, because those tasks require collecting or indexing data across contracts and blocks.
Call ownerOf with eth_call
The example calls ownerOf(uint256) for a known ERC-721 contract and token ID. Set RPC_URL to an Ethereum JSON-RPC endpoint from a provider’s documentation. The request uses the standard eth_call method, so it does not assume a provider-specific NFT endpoint.
- Replace the example contract and token ID with values for the NFT you want to inspect.
- The function selector for
ownerOf(uint256)is0x6352211e. The token ID is encoded as a 32-byte hexadecimal integer. - The
latestblock tag asks for the result at the node’s latest state.
const rpcUrl = process.env.RPC_URL;
const contract = process.env.NFT_CONTRACT;
const tokenId = process.env.TOKEN_ID;
if (!rpcUrl || !contract || !tokenId) {
throw new Error('Set RPC_URL, NFT_CONTRACT, and TOKEN_ID.');
}
if (!/^0x[0-9a-fA-F]{40}$/.test(contract)) {
throw new Error('NFT_CONTRACT must be a 20-byte hex address.');
}
if (!/^\d+$/.test(tokenId)) {
throw new Error('TOKEN_ID must be a non-negative decimal integer.');
}
const tokenHex = BigInt(tokenId).toString(16);
if (tokenHex.length > 64) {
throw new Error('TOKEN_ID does not fit in uint256.');
}
const data = '0x6352211e' + tokenHex.padStart(64, '0');
const response = await fetch(rpcUrl, {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({
jsonrpc: '2.0',
id: 1,
method: 'eth_call',
params: [{ to: contract, data }, 'latest']
})
});
if (!response.ok) {
throw new Error(`HTTP ${response.status}: ${await response.text()}`);
}
const result = await response.json();
if (result.error) {
throw new Error(`RPC error ${result.error.code}: ${result.error.message}`);
}
if (typeof result.result !== 'string' || !/^0x[0-9a-fA-F]{64}$/.test(result.result)) {
throw new Error(`Unexpected ownerOf result: ${JSON.stringify(result.result)}`);
}
const owner = '0x' + result.result.slice(-40);
console.log({ contract, tokenId, owner });Run with Node.js 18 or newer after setting RPC_URL, NFT_CONTRACT, and TOKEN_ID in your environment. A successful call prints an object with the contract, token ID, and decoded owner address.
A reverted call can mean the token does not exist at the requested block, the address is not a compatible ERC-721 contract, or the contract uses different behavior. The code reports RPC errors and rejects malformed results instead of treating them as an owner address.
Know what this result covers
ownerOf answers one contract-level question: who owns this token according to the contract at the queried block. It does not enumerate an address’s NFTs, return marketplace data, or provide metadata unless the contract exposes and you call the relevant methods.
For collections across many contracts, historical ownership, or convenient metadata retrieval, an NFT-focused API may provide higher-level queries. Check the provider’s documentation for the exact networks, methods, pagination rules, and response fields; those capabilities vary by service. RPC access sends requests to a node, while indexing collects and organizes data so it can be queried across contracts or blocks.
- Use a standard RPC call for a known contract and token when the contract method answers the question.
- Use a documented NFT API or an indexer when you need discovery, aggregation, metadata, or historical queries.
- Do not infer coverage or response speed from the label “enhanced API”; verify the method and network in the provider’s documentation.
Choose an API for the actual query
Write down the data you need first: one token’s current owner, all tokens for a wallet, token metadata, or transfer history. Then confirm that a candidate API documents that query for your target network and check how it handles pagination, missing metadata, and block references.
If response time matters to your application, measure it against your own representative requests and network conditions. A single request time does not establish general provider performance.
- For learning about RPC and indexing workflows, browse SubQuery Learn.
- For provider options and RPC setup, see the OnFinality RPC Assistant.