Skip to main content
Version: v1.1

Get IRC27 NFT Metadata

ERC721

As your L1 NFT is always registered as ERC721, you might want to get the metadata like tokenURI from there. Using getIRC27NFTData is normally only needed if you need special IRC27 metadata.

This guide explains how to use the getIRC27NFTData function within a smart contract to fetch information about a specific IRC27 NFT on the IOTA Network.

Mint an NFT

Mint your first NFT following our how to mint an NFT guide.

Understanding the getIRC27NFTData Function

The getIRC27NFTData function retrieves metadata for an IRC27 NFT based on its identifier. IRC27 is a series of standards to support interoperable and universal NFT systems throughout the IOTA ecosystem.

How To Use getIRC27NFTData

Create a function called fetchIRC27NFTData in your contract that calls getIRC27NFTData and processes its return value. getIRC27NFTData returns a struct of type IRC27NFTMetadata which contains properties like the NFT name, uri and more.

IRC27NFTMetadata URI

The uri property contains a JSON object which follows the ERC721 standard. This JSON is also returned by the tokenURI function from the ERC721NFTs contract.

function fetchIRC27NFTData(uint256 tokenId) public view returns (IRC27NFT memory irc27NftData) {
irc27NftData = ISC.sandbox.getIRC27NFTData(ISCTypes.asNFTID(tokenId));
return irc27NftData;
}

Full Example Contract

Combining all the above steps, here’s a complete example:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@iota/iscmagic/ISC.sol";
import "@iota/iscmagic/ISCTypes.sol";

contract IRCNFTMetadata {
function fetchIRC27NFTData(uint256 tokenId) public view returns (IRC27NFT memory irc27NftData) {
irc27NftData = ISC.sandbox.getIRC27NFTData(ISCTypes.asNFTID(tokenId));
return irc27NftData;
}
}