Skip to main content

Retrieving Token URI

Retrieving the Token URI is a critical operation in managing Non-Fungible Tokens (NFTs), as it provides a way to access the token's metadata. The edeXa ERC721 SDK offers the getTokenURI method for this purpose. This guide provides an example of how to fetch the Token URI using this method.


Overview of the getTokenURI Method

The getTokenURI method is used to retrieve the Uniform Resource Identifier (URI) associated with a specific token. This URI points to a resource with details about the token, such as its metadata.


Prerequisites

  • Installation of the edeXa ERC721 SDK in your project.
  • An authentication token obtained through the SDK's authentication method. This token is necessary to authorize your requests.

Sample Code Snippet

Here is a JavaScript code snippet demonstrating the use of the getTokenURI method:

import { ERC721, Network } from 'edeXa-sdk';
async function getTokenURI() {
const settings = {
network: Network.SANDBOX, // Or Network.MAINNET for production environments
};
const erc721 = new ERC721({
...settings,
authorization: `Bearer ${token}`, // Replace `${token}` with your actual authentication token
});

const dataToGetTokenURI = {
tokenId: 'Enter the tokenId to get the token URI', // Required tokenId
};

try {
const getTokenURIResponse = await erc721.getTokenURI(dataToGetTokenURI);
// Handle success
} catch (error) {
// Handle error
}
}

Request Parameters

ParameterRequiredTypeDescription
tokenIdYesNumberThe unique identifier of the token whose URI you want to retrieve.

Response Format

Upon successful execution, the getTokenURI method returns a response containing the token's URI.

AttributeTypeDescription
URIStringThe Uniform Resource Identifier (URI) associated with the specified token.