Skip to main content

Retrieving Token URI

This guide explains how to use the getTokenURI method to retrieve the Uniform Resource Identifier (URI) of a token within your blockchain application using the ERC1155 API. The URI provides essential information about the token, often pointing to a JSON file that describes the token's properties.


Overview of the getTokenURI Method

The getTokenURI method is a critical function for accessing the metadata associated with tokens in the ERC1155 standard. It enables applications to display detailed information about tokens, such as their name, description, and image.


Prerequisites

  • Installed the edeXa-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 { ERC1155, Network } from 'edeXa-sdk';

async function getTokenURI() {
// Configuration settings for the ERC1155 instance
const settings = {
network: Network.SANDBOX, // Use Network.MAINNET for production environments
};

const erc1155 = new ERC1155({
...settings,
authorization: `Bearer ${token}`, // Replace `${token}` with your actual token
});

// Data required to retrieve the token URI
const dataToGetTokenURI = {
tokenId: 'uniqueTokenId', // Token ID of the token
chaincode: 'optionalChaincodeName', // Optional chaincode name
channel: 'optionalChannelName', // Optional blockchain channel
};

try {
// Retrieve the token URI
const getTokenURIResponse = await erc1155.getTokenURI(dataToGetTokenURI);
// Handle success
} catch (error) {
// Handle error
}
}

Request Parameters

ParameterTypeRequiredDescription
tokenIdStringYesThe ID of the token for which to retrieve the URI.
channelStringNoThe name of the blockchain channel where the operation occurs.
chaincodeStringNoThe name of the smart contract or chaincode managing the tokens.

Response Format

Upon successfully querying the token URI, the getTokenURI method returns a response object containing:

KeyTypeDescription
URIStringThe URI of the requested token.