Skip to main content

ownerOf

The ownerOf method is specific to the ERC-721 token standard and is used to determine the current owner of a specific non-fungible token (NFT). Given a unique token identifier, this method will return the Ethereum address that currently owns the token. This function is essential for various operations and checks related to ownership within the ERC-721 ecosystem. The method is a member of the ERC721Instance object, which can be retrieved using the appropriate function from the client library (e.g., EdexaClient or a similar one).

Method Signature

async ownerOf(tokenId: string): Promise<string>

Parameters

ParameterTypeDescription
tokenIdstringThe unique identifier corresponding to an ERC-721 token for which you aim to identify the current owner.

Returns

  • A Promise that resolves to the Ethereum address string of the current owner of the specified token.

Usage Example

Start by initializing the ERC-721 token contract of your choice:

const erc721 = edexaClient.getERC721Instance("your ERC-721 contract address here");

Proceed to invoke the ownerOf method with a specific token ID:

const tokenId = "67890"; // Example token ID
const ownerAddress = await erc721.ownerOf(tokenId);
console.log(`The owner of token ID ${tokenId} is: ${ownerAddress}`);

Notes

  • Should you query the owner of a token ID that does not exist or has not been minted, the method will likely throw an error. Always ensure the validity of the token ID and possibly handle exceptions gracefully in your code.

  • The ownerOf method is a fundamental query in the ERC-721 standard and is used extensively in various dApps to check and verify ownership before performing specific actions.