Skip to main content
Version: v1.4

Get On-Chain NFT Data

This guide explains how to use the getNFTData function within a smart contract to fetch information about a specific on-chain NFT on the IOTA network.

Mint an NFT

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

How to Use the getNFTData Function

The getNFTData function retrieves data for an NFT based on its identifier. It returns a struct of type ISCNFT, which contains various properties of the NFT like the issuer, metadata, owner, and NFTID. To use this function, you need to create a function in your smart contract that calls getNFTData and processes its return value, as shown in the example contract below:

Example Code

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

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

contract NFTMetadata {
function fetchNFTData(uint256 tokenId) public view returns (ISCNFT memory nftData) {
nftData = ISC.sandbox.getNFTData(ISCTypes.asNFTID(tokenId));
return nftData;
}
}