From 3d2408c88b716cbbf178945118237db08240af05 Mon Sep 17 00:00:00 2001 From: Gino Date: Wed, 29 May 2024 08:00:51 +0100 Subject: [PATCH 01/14] draft guide created --- .../core-contracts/nft/get-nft-metadata.md | 166 ++++++++++++++++++ 1 file changed, 166 insertions(+) create mode 100644 docs/build/isc/v1.1/docs/how-tos/core-contracts/nft/get-nft-metadata.md diff --git a/docs/build/isc/v1.1/docs/how-tos/core-contracts/nft/get-nft-metadata.md b/docs/build/isc/v1.1/docs/how-tos/core-contracts/nft/get-nft-metadata.md new file mode 100644 index 00000000000..3997fa0f7c1 --- /dev/null +++ b/docs/build/isc/v1.1/docs/how-tos/core-contracts/nft/get-nft-metadata.md @@ -0,0 +1,166 @@ +--- +description: How to get NFT metadata on L1 +image: /img/logo/WASP_logo_dark.png +tags: + - NFT + - EVM + - how-to +--- +import ExampleCodeIntro from '../../../_partials/how-tos/token/_example_code_intro.md'; + +# Get NFT Metadata + +This guide explains how to utilize the `getIRC27NFTData` function within a smart contract to fetch information about a specific IRC27 NFT on the IOTA Network. The function resides in the ISCSandbox contract and returns details pertaining to the requested NFT. + +1. 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. + +## Function Signature: +```solidity +function getIRC27NFTData(bytes memory nftID) public view returns (IRC27NFT memory irc27NftData); +``` +## Parameters: +`NFTID id`: This parameter represents the unique identifier of the IRC27 NFT you intend to retrieve information about. +## Return Value: +The function returns a data structure of type IRC27NFT. This structure incorporates two elements: +1. `nft`: This element provides details regarding the underlying on-chain NFT. It's of type `ISCNFT`. +2. `metadata`: This element offers information specific to the IRC27 standard. It's of type `IRC27NFTMetadata`. + +## Here's a step-by-step breakdown of how to leverage getIRC27NFTData to acquire IRC27 NFT metadata: + +2. Fetching IRC27 NFT Metadata: + +Create a function called fetchNFTData in your contract that calls getIRC27NFTData and processes its return value. + +```solidity +// Function to get NFT data + function fetchNFTData(bytes memory nftID) public view returns (IRC27NFT memory irc27NftData) { + bytes32 id = bytes32(nftID); + NFTID nftIDTyped = NFTID.wrap(id); + irc27NftData = ISC.sandbox.getIRC27NFTData(nftIDTyped); + return irc27NftData; + } +``` +3. Encoding URI Data in IRC27NFTMetadata + +The `IRC27NFTMetadata` struct holds detailed metadata, including the URI and other fields like name and description. Encoding this data correctly is crucial for ensuring the integrity and accessibility of the NFT's metadata. + +```solidity +struct IRC27NFTMetadata { + string uri; + string name; + string description; +} +``` + +4. Implementing URI Encoding + +The OpenZeppelin Contracts library provides a `Base64` utility that simplifies encoding URI data. Here's how to implement URI encoding: + +## Implementation: + +```solidity +function encodeNFTMetadata( + string memory _standard, + string memory _version, + string memory _mimeType, + string memory _uri, + string memory _name, + string memory _description +) + public + pure + returns (IRC27NFTMetadata memory) +{ + // Create JSON representation + string memory json = string(abi.encodePacked( + '{"name":"', _name, + '","description":"', _description, + '","image":"', _uri, + '"}' + )); + + // Base64 encode the JSON string + string memory encodedURI = string(abi.encodePacked( + "data:application/json;base64,", + Base64.encode(bytes(json)) + )); + + // Return the metadata struct + return IRC27NFTMetadata({ + standard: _standard, + version: _version, + mimeType: _mimeType, + uri: encodedURI, + name: _name, + description: _description + }); +} +``` + +## Full Example Contract +Combining all the above steps, here’s a complete example: + +```solidity +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.0; + +import "@openzeppelin/contracts/utils/Base64.sol"; +import "@iota/iscmagic/ISC.sol"; +import "@iota/iscmagic/ISCTypes.sol"; + +contract NFTMetadata { + +function fetchNFTData(bytes memory nftID) public view returns (IRC27NFT memory irc27NftData) { + require(nftID.length == 32, "NFT ID must be 32 bytes"); + bytes32 id = bytes32(nftID); + NFTID nftIDTyped = NFTID.wrap(id); + irc27NftData = ISC.sandbox.getIRC27NFTData(nftIDTyped); + return irc27NftData; + } + +function encodeNFTMetadata( + string memory _standard, + string memory _version, + string memory _mimeType, + string memory _uri, + string memory _name, + string memory _description +) + public + pure + returns (IRC27NFTMetadata memory) +{ + // Create JSON representation + string memory json = string(abi.encodePacked( + '{"name":"', _name, + '","description":"', _description, + '","image":"', _uri, + '"}' + )); + + // Base64 encode the JSON string + string memory encodedURI = string(abi.encodePacked( + "data:application/json;base64,", + Base64.encode(bytes(json)) + )); + + // Return the metadata struct + return IRC27NFTMetadata({ + standard: _standard, + version: _version, + mimeType: _mimeType, + uri: encodedURI, + name: _name + }); +} +} +``` +## Example Usage + +To mint a new NFT and fetch its metadata, you would use the above functions within a larger contract that handles NFT minting and management. + +MINT AN NFT + +Mint your first NFT following our Mint an NFT Guide \ No newline at end of file From 188ef22f53dab2e86408249b156561ef2092b348 Mon Sep 17 00:00:00 2001 From: Gino Date: Wed, 29 May 2024 12:37:11 +0100 Subject: [PATCH 02/14] add page to sidebar --- .../v1.1/docs/how-tos/core-contracts/nft/get-nft-metadata.md | 1 - docs/build/isc/v1.1/sidebars.js | 5 +++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/build/isc/v1.1/docs/how-tos/core-contracts/nft/get-nft-metadata.md b/docs/build/isc/v1.1/docs/how-tos/core-contracts/nft/get-nft-metadata.md index 3997fa0f7c1..5cca766ebba 100644 --- a/docs/build/isc/v1.1/docs/how-tos/core-contracts/nft/get-nft-metadata.md +++ b/docs/build/isc/v1.1/docs/how-tos/core-contracts/nft/get-nft-metadata.md @@ -6,7 +6,6 @@ tags: - EVM - how-to --- -import ExampleCodeIntro from '../../../_partials/how-tos/token/_example_code_intro.md'; # Get NFT Metadata diff --git a/docs/build/isc/v1.1/sidebars.js b/docs/build/isc/v1.1/sidebars.js index 9d07b38ff0b..9d20a677ccb 100644 --- a/docs/build/isc/v1.1/sidebars.js +++ b/docs/build/isc/v1.1/sidebars.js @@ -205,6 +205,11 @@ module.exports = { label: 'Use as ERC721', id: 'how-tos/core-contracts/nft/use-as-erc721', }, + { + type: 'doc', + label: 'Get NFT Metadata', + id: 'how-tos/core-contracts/nft/get-nft-metadata', + }, ], }, { From 28b8d68cee066a03668a0230663c8cd0aed48794 Mon Sep 17 00:00:00 2001 From: Gino Date: Mon, 3 Jun 2024 21:38:04 +0100 Subject: [PATCH 03/14] rebase to main --- .../how-tos/token/_get-nft-metadata.md | 5 +++ .../core-contracts/nft/get-nft-metadata.md | 38 +++++++------------ 2 files changed, 18 insertions(+), 25 deletions(-) create mode 100644 docs/build/isc/v1.1/docs/_partials/how-tos/token/_get-nft-metadata.md diff --git a/docs/build/isc/v1.1/docs/_partials/how-tos/token/_get-nft-metadata.md b/docs/build/isc/v1.1/docs/_partials/how-tos/token/_get-nft-metadata.md new file mode 100644 index 00000000000..693592d5718 --- /dev/null +++ b/docs/build/isc/v1.1/docs/_partials/how-tos/token/_get-nft-metadata.md @@ -0,0 +1,5 @@ +:::tip Mint an NFT + +Mint your first NFT following our how to [mint an NFT guide](/isc/how-tos/core-contracts/nft/mint-nft/#about-nfts). + +::: \ No newline at end of file diff --git a/docs/build/isc/v1.1/docs/how-tos/core-contracts/nft/get-nft-metadata.md b/docs/build/isc/v1.1/docs/how-tos/core-contracts/nft/get-nft-metadata.md index 5cca766ebba..7bb9924dbcb 100644 --- a/docs/build/isc/v1.1/docs/how-tos/core-contracts/nft/get-nft-metadata.md +++ b/docs/build/isc/v1.1/docs/how-tos/core-contracts/nft/get-nft-metadata.md @@ -6,12 +6,13 @@ tags: - EVM - how-to --- +import GetNftMetadata from '../../../_partials/how-tos/token/_get-nft-metadata.md'; # Get NFT Metadata This guide explains how to utilize the `getIRC27NFTData` function within a smart contract to fetch information about a specific IRC27 NFT on the IOTA Network. The function resides in the ISCSandbox contract and returns details pertaining to the requested NFT. -1. Understanding the `getIRC27NFTData` Function +## 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. @@ -23,12 +24,12 @@ function getIRC27NFTData(bytes memory nftID) public view returns (IRC27NFT memor `NFTID id`: This parameter represents the unique identifier of the IRC27 NFT you intend to retrieve information about. ## Return Value: The function returns a data structure of type IRC27NFT. This structure incorporates two elements: -1. `nft`: This element provides details regarding the underlying on-chain NFT. It's of type `ISCNFT`. -2. `metadata`: This element offers information specific to the IRC27 standard. It's of type `IRC27NFTMetadata`. +* `nft`: This element provides details regarding the underlying on-chain NFT. It's of type `ISCNFT`. +* `metadata`: This element offers information specific to the IRC27 standard. It's of type `IRC27NFTMetadata`. -## Here's a step-by-step breakdown of how to leverage getIRC27NFTData to acquire IRC27 NFT metadata: +### Here's a step-by-step breakdown of how to leverage getIRC27NFTData to acquire IRC27 NFT metadata: -2. Fetching IRC27 NFT Metadata: +1. Fetching IRC27 NFT Metadata: Create a function called fetchNFTData in your contract that calls getIRC27NFTData and processes its return value. @@ -41,36 +42,27 @@ Create a function called fetchNFTData in your contract that calls getIRC27NFTDat return irc27NftData; } ``` -3. Encoding URI Data in IRC27NFTMetadata +2. Encoding URI Data in IRC27NFTMetadata The `IRC27NFTMetadata` struct holds detailed metadata, including the URI and other fields like name and description. Encoding this data correctly is crucial for ensuring the integrity and accessibility of the NFT's metadata. ```solidity -struct IRC27NFTMetadata { - string uri; - string name; - string description; -} +struct IRC27NFTMetadata {string uri; string name;string description;} ``` -4. Implementing URI Encoding +3. Implementing URI Encoding The OpenZeppelin Contracts library provides a `Base64` utility that simplifies encoding URI data. Here's how to implement URI encoding: ## Implementation: ```solidity -function encodeNFTMetadata( - string memory _standard, - string memory _version, +function encodeNFTMetadata(string memory _standard, string memory _version, string memory _mimeType, string memory _uri, string memory _name, string memory _description -) - public - pure - returns (IRC27NFTMetadata memory) +) public pure returns (IRC27NFTMetadata memory) { // Create JSON representation string memory json = string(abi.encodePacked( @@ -127,9 +119,7 @@ function encodeNFTMetadata( string memory _name, string memory _description ) - public - pure - returns (IRC27NFTMetadata memory) + public pure returns (IRC27NFTMetadata memory) { // Create JSON representation string memory json = string(abi.encodePacked( @@ -160,6 +150,4 @@ function encodeNFTMetadata( To mint a new NFT and fetch its metadata, you would use the above functions within a larger contract that handles NFT minting and management. -MINT AN NFT - -Mint your first NFT following our Mint an NFT Guide \ No newline at end of file + \ No newline at end of file From f555e352432885c7a9939446343d34964393c7ed Mon Sep 17 00:00:00 2001 From: Gino Date: Thu, 30 May 2024 09:38:40 +0100 Subject: [PATCH 04/14] Addressed feedback from PR review --- .../core-contracts/nft/get-nft-metadata.md | 52 +++++++++---------- 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/docs/build/isc/v1.1/docs/how-tos/core-contracts/nft/get-nft-metadata.md b/docs/build/isc/v1.1/docs/how-tos/core-contracts/nft/get-nft-metadata.md index 7bb9924dbcb..e35226c4e30 100644 --- a/docs/build/isc/v1.1/docs/how-tos/core-contracts/nft/get-nft-metadata.md +++ b/docs/build/isc/v1.1/docs/how-tos/core-contracts/nft/get-nft-metadata.md @@ -10,39 +10,45 @@ import GetNftMetadata from '../../../_partials/how-tos/token/_get-nft-metadata.m # Get NFT Metadata -This guide explains how to utilize the `getIRC27NFTData` function within a smart contract to fetch information about a specific IRC27 NFT on the IOTA Network. The function resides in the ISCSandbox contract and returns details pertaining to the requested NFT. +This guide explains how to use the [`getIRC27NFTData`](../../../reference/magic-contract/ISCSandbox/#getirc27nftdata) function within a smart contract to fetch information about a specific IRC27 NFT on the IOTA Network. + + ## 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. -## Function Signature: +### Function Signature: + ```solidity function getIRC27NFTData(bytes memory nftID) public view returns (IRC27NFT memory irc27NftData); ``` -## Parameters: + +### Parameters: + `NFTID id`: This parameter represents the unique identifier of the IRC27 NFT you intend to retrieve information about. -## Return Value: + +### Return Value: + The function returns a data structure of type IRC27NFT. This structure incorporates two elements: * `nft`: This element provides details regarding the underlying on-chain NFT. It's of type `ISCNFT`. * `metadata`: This element offers information specific to the IRC27 standard. It's of type `IRC27NFTMetadata`. -### Here's a step-by-step breakdown of how to leverage getIRC27NFTData to acquire IRC27 NFT metadata: +## How To Use `getIRC27NFTData` -1. Fetching IRC27 NFT Metadata: +### 1. Fetch IRC27 NFT Metadata -Create a function called fetchNFTData in your contract that calls getIRC27NFTData and processes its return value. +Create a function called `fetchNFTData` in your contract that calls `getIRC27NFTData` and processes its return value. ```solidity -// Function to get NFT data - function fetchNFTData(bytes memory nftID) public view returns (IRC27NFT memory irc27NftData) { - bytes32 id = bytes32(nftID); - NFTID nftIDTyped = NFTID.wrap(id); - irc27NftData = ISC.sandbox.getIRC27NFTData(nftIDTyped); - return irc27NftData; - } +function fetchNFTData(bytes memory nftID) public view returns (IRC27NFT memory irc27NftData) { + bytes32 id = bytes32(nftID); + NFTID nftIDTyped = NFTID.wrap(id); + irc27NftData = ISC.sandbox.getIRC27NFTData(nftIDTyped); + return irc27NftData; +} ``` -2. Encoding URI Data in IRC27NFTMetadata +### 2. Encode the URI Data in `IRC27NFTMetadata` The `IRC27NFTMetadata` struct holds detailed metadata, including the URI and other fields like name and description. Encoding this data correctly is crucial for ensuring the integrity and accessibility of the NFT's metadata. @@ -50,11 +56,10 @@ The `IRC27NFTMetadata` struct holds detailed metadata, including the URI and oth struct IRC27NFTMetadata {string uri; string name;string description;} ``` -3. Implementing URI Encoding +### 3. Implement URI Encoding -The OpenZeppelin Contracts library provides a `Base64` utility that simplifies encoding URI data. Here's how to implement URI encoding: +The [OpenZeppelin Contracts](https://www.openzeppelin.com/) library provides a `Base64` utility that simplifies encoding URI data. Here's how to implement URI encoding: -## Implementation: ```solidity function encodeNFTMetadata(string memory _standard, string memory _version, @@ -64,7 +69,6 @@ function encodeNFTMetadata(string memory _standard, string memory _version, string memory _description ) public pure returns (IRC27NFTMetadata memory) { - // Create JSON representation string memory json = string(abi.encodePacked( '{"name":"', _name, '","description":"', _description, @@ -72,13 +76,11 @@ function encodeNFTMetadata(string memory _standard, string memory _version, '"}' )); - // Base64 encode the JSON string string memory encodedURI = string(abi.encodePacked( "data:application/json;base64,", Base64.encode(bytes(json)) )); - // Return the metadata struct return IRC27NFTMetadata({ standard: _standard, version: _version, @@ -91,6 +93,7 @@ function encodeNFTMetadata(string memory _standard, string memory _version, ``` ## Full Example Contract + Combining all the above steps, here’s a complete example: ```solidity @@ -121,7 +124,6 @@ function encodeNFTMetadata( ) public pure returns (IRC27NFTMetadata memory) { - // Create JSON representation string memory json = string(abi.encodePacked( '{"name":"', _name, '","description":"', _description, @@ -129,13 +131,11 @@ function encodeNFTMetadata( '"}' )); - // Base64 encode the JSON string string memory encodedURI = string(abi.encodePacked( "data:application/json;base64,", Base64.encode(bytes(json)) )); - // Return the metadata struct return IRC27NFTMetadata({ standard: _standard, version: _version, @@ -148,6 +148,4 @@ function encodeNFTMetadata( ``` ## Example Usage -To mint a new NFT and fetch its metadata, you would use the above functions within a larger contract that handles NFT minting and management. - - \ No newline at end of file +To mint a new NFT and fetch its metadata, you would use the above functions within a larger contract that handles NFT minting and management. \ No newline at end of file From 6e738b78bb70d2f7db5b59c17ddfd504f92aac5b Mon Sep 17 00:00:00 2001 From: Gino Date: Thu, 30 May 2024 11:39:09 +0100 Subject: [PATCH 05/14] fixed issue with broken url --- .../v1.1/docs/how-tos/core-contracts/nft/get-nft-metadata.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/build/isc/v1.1/docs/how-tos/core-contracts/nft/get-nft-metadata.md b/docs/build/isc/v1.1/docs/how-tos/core-contracts/nft/get-nft-metadata.md index e35226c4e30..383744333c8 100644 --- a/docs/build/isc/v1.1/docs/how-tos/core-contracts/nft/get-nft-metadata.md +++ b/docs/build/isc/v1.1/docs/how-tos/core-contracts/nft/get-nft-metadata.md @@ -10,7 +10,7 @@ import GetNftMetadata from '../../../_partials/how-tos/token/_get-nft-metadata.m # Get NFT Metadata -This guide explains how to use the [`getIRC27NFTData`](../../../reference/magic-contract/ISCSandbox/#getirc27nftdata) function within a smart contract to fetch information about a specific IRC27 NFT on the IOTA Network. +This guide explains how to use the [`getIRC27NFTData`](https://github.com/iotaledger/wasp/blob/develop/packages/vm/core/evm/iscmagic/ISCSandbox.sol#L118) function within a smart contract to fetch information about a specific IRC27 NFT on the IOTA Network. From 224e8fa7c71bc06197d01c7e7b0791d7099c6a70 Mon Sep 17 00:00:00 2001 From: Jeroen van den Hout Date: Fri, 31 May 2024 15:41:38 +0200 Subject: [PATCH 06/14] Fix link --- .../v1.1/docs/how-tos/core-contracts/nft/get-nft-metadata.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/build/isc/v1.1/docs/how-tos/core-contracts/nft/get-nft-metadata.md b/docs/build/isc/v1.1/docs/how-tos/core-contracts/nft/get-nft-metadata.md index 383744333c8..2837e574652 100644 --- a/docs/build/isc/v1.1/docs/how-tos/core-contracts/nft/get-nft-metadata.md +++ b/docs/build/isc/v1.1/docs/how-tos/core-contracts/nft/get-nft-metadata.md @@ -10,7 +10,7 @@ import GetNftMetadata from '../../../_partials/how-tos/token/_get-nft-metadata.m # Get NFT Metadata -This guide explains how to use the [`getIRC27NFTData`](https://github.com/iotaledger/wasp/blob/develop/packages/vm/core/evm/iscmagic/ISCSandbox.sol#L118) function within a smart contract to fetch information about a specific IRC27 NFT on the IOTA Network. +This guide explains how to use the [`getIRC27NFTData`](../../../reference/magic-contract/ISCSandbox.md#getirc27nftdata) function within a smart contract to fetch information about a specific IRC27 NFT on the IOTA Network. From 1018c0cdc280baba6a4d931b2102ae861efbd85d Mon Sep 17 00:00:00 2001 From: Gino Date: Thu, 6 Jun 2024 11:47:59 +0100 Subject: [PATCH 07/14] feat(ISC-DOC): decode metadata uri --- .../isc/v1.1/docs/_admonitions/_ERC721.md | 5 + .../how-tos/token/_get-nft-metadata.md | 2 +- .../core-contracts/nft/get-nft-metadata.md | 236 ++++++++++++------ 3 files changed, 165 insertions(+), 78 deletions(-) create mode 100644 docs/build/isc/v1.1/docs/_admonitions/_ERC721.md diff --git a/docs/build/isc/v1.1/docs/_admonitions/_ERC721.md b/docs/build/isc/v1.1/docs/_admonitions/_ERC721.md new file mode 100644 index 00000000000..76191eec6be --- /dev/null +++ b/docs/build/isc/v1.1/docs/_admonitions/_ERC721.md @@ -0,0 +1,5 @@ +:::info ERC721 + +As your L1 NFT is always registered as [ERC721](https://eips.ethereum.org/EIPS/eip-721), you might want to get the metadata like `tokenURI` from there. Using `getIRC27NFTData` is normally only needed if you need special [IRC27](https://wiki.iota.org/tips/tips/TIP-0027/) metadata. + +::: \ No newline at end of file diff --git a/docs/build/isc/v1.1/docs/_partials/how-tos/token/_get-nft-metadata.md b/docs/build/isc/v1.1/docs/_partials/how-tos/token/_get-nft-metadata.md index 693592d5718..1ed17749708 100644 --- a/docs/build/isc/v1.1/docs/_partials/how-tos/token/_get-nft-metadata.md +++ b/docs/build/isc/v1.1/docs/_partials/how-tos/token/_get-nft-metadata.md @@ -1,5 +1,5 @@ :::tip Mint an NFT -Mint your first NFT following our how to [mint an NFT guide](/isc/how-tos/core-contracts/nft/mint-nft/#about-nfts). +Mint your first NFT following our how to [mint an NFT guide](../how-tos/core-contracts/nft/mint-nft.md#about-nfts). ::: \ No newline at end of file diff --git a/docs/build/isc/v1.1/docs/how-tos/core-contracts/nft/get-nft-metadata.md b/docs/build/isc/v1.1/docs/how-tos/core-contracts/nft/get-nft-metadata.md index 2837e574652..4865baed78a 100644 --- a/docs/build/isc/v1.1/docs/how-tos/core-contracts/nft/get-nft-metadata.md +++ b/docs/build/isc/v1.1/docs/how-tos/core-contracts/nft/get-nft-metadata.md @@ -7,32 +7,19 @@ tags: - how-to --- import GetNftMetadata from '../../../_partials/how-tos/token/_get-nft-metadata.md'; +import ERC721Admonition from '../../../_admonitions/_ERC721.md'; # Get NFT Metadata + + This guide explains how to use the [`getIRC27NFTData`](../../../reference/magic-contract/ISCSandbox.md#getirc27nftdata) function within a smart contract to fetch information about a specific IRC27 NFT on the IOTA Network. ## 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. - -### Function Signature: - -```solidity -function getIRC27NFTData(bytes memory nftID) public view returns (IRC27NFT memory irc27NftData); -``` - -### Parameters: - -`NFTID id`: This parameter represents the unique identifier of the IRC27 NFT you intend to retrieve information about. - -### Return Value: - -The function returns a data structure of type IRC27NFT. This structure incorporates two elements: -* `nft`: This element provides details regarding the underlying on-chain NFT. It's of type `ISCNFT`. -* `metadata`: This element offers information specific to the IRC27 standard. It's of type `IRC27NFTMetadata`. +The [`getIRC27NFTData`](../../../reference/magic-contract/ISCSandbox.md#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` @@ -56,42 +43,92 @@ The `IRC27NFTMetadata` struct holds detailed metadata, including the URI and oth struct IRC27NFTMetadata {string uri; string name;string description;} ``` -### 3. Implement URI Encoding - -The [OpenZeppelin Contracts](https://www.openzeppelin.com/) library provides a `Base64` utility that simplifies encoding URI data. Here's how to implement URI encoding: +### 3. Decode the URI Data in IRC27NFTMetadata +The `IRC27NFTMetadata` struct holds detailed metadata, including the URI and other fields like name and description. Decoding this data correctly is crucial for ensuring the integrity and accessibility of the NFT's metadata. ```solidity -function encodeNFTMetadata(string memory _standard, string memory _version, - string memory _mimeType, - string memory _uri, - string memory _name, - string memory _description -) public pure returns (IRC27NFTMetadata memory) -{ - string memory json = string(abi.encodePacked( - '{"name":"', _name, - '","description":"', _description, - '","image":"', _uri, - '"}' - )); - - string memory encodedURI = string(abi.encodePacked( - "data:application/json;base64,", - Base64.encode(bytes(json)) - )); +function decodeNFTMetadataURI(string memory encodedURI) public pure returns (IRC27NFTMetadata memory) { + // Ensure the encodedURI has the correct prefix + require(bytes(encodedURI).length > 29, "Invalid encoded URI length"); + string memory base64JSON = substring(encodedURI, 29, bytes(encodedURI).length); + + // Decode the Base64-encoded JSON + bytes memory decodedBytes = Base64.decode(base64JSON); + string memory json = string(decodedBytes); + + // Extract fields from the JSON string + string memory name = extractValueFromJSON(json, "name"); + string memory description = extractValueFromJSON(json, "description"); + string memory uri = extractValueFromJSON(json, "image"); return IRC27NFTMetadata({ - standard: _standard, - version: _version, - mimeType: _mimeType, + standard: "IRC27", + version: "1.0", + mimeType: "application/json", uri: encodedURI, - name: _name, - description: _description + name: name, + description: description }); } ``` +### `substring` Function + +The substring function extracts a substring from a given string based on specified start and end indices. This is useful for isolating the Base64-encoded JSON part of the URI. + +```solidity + +function substring(string memory str, uint startIndex, uint endIndex) internal pure returns (string memory) { + bytes memory strBytes = bytes(str); + bytes memory result = new bytes(endIndex - startIndex); + for (uint i = startIndex; i < endIndex; i++) { + result[i - startIndex] = strBytes[i]; + } + return string(result); +} + +``` + +### `extractValueFromJSON` Function + +The `extractValueFromJSON` function extracts the value associated with a specific key from a JSON string. This function helps to retrieve individual fields like name, description, and image from the decoded JSON metadata. + +```solidity + +function extractValueFromJSON(string memory json, string memory key) internal pure returns (string memory) { + bytes memory jsonBytes = bytes(json); + bytes memory keyBytes = bytes(key); + bytes memory result = new bytes(jsonBytes.length); + uint256 resultIndex = 0; + bool keyFound = false; + + for (uint256 i = 0; i < jsonBytes.length; i++) { + if (jsonBytes[i] == keyBytes[0]) { + uint256 j = 0; + while (j < keyBytes.length && jsonBytes[i + j] == keyBytes[j]) { + j++; + } + if (j == keyBytes.length && jsonBytes[i + j] == ':') { + keyFound = true; + i += j + 1; + } + } + + if (keyFound && jsonBytes[i] == '"') { + i++; + while (jsonBytes[i] != '"') { + result[resultIndex++] = jsonBytes[i++]; + } + break; + } + } + + return string(result); +} + +``` + ## Full Example Contract Combining all the above steps, here’s a complete example: @@ -105,8 +142,23 @@ import "@iota/iscmagic/ISC.sol"; import "@iota/iscmagic/ISCTypes.sol"; contract NFTMetadata { + struct IRC27NFT { + bytes id; + string uri; + string name; + string description; + } -function fetchNFTData(bytes memory nftID) public view returns (IRC27NFT memory irc27NftData) { + struct IRC27NFTMetadata { + string standard; + string version; + string mimeType; + string uri; + string name; + string description; + } + + function fetchNFTData(bytes memory nftID) public view returns (IRC27NFT memory irc27NftData) { require(nftID.length == 32, "NFT ID must be 32 bytes"); bytes32 id = bytes32(nftID); NFTID nftIDTyped = NFTID.wrap(id); @@ -114,38 +166,68 @@ function fetchNFTData(bytes memory nftID) public view returns (IRC27NFT memory i return irc27NftData; } -function encodeNFTMetadata( - string memory _standard, - string memory _version, - string memory _mimeType, - string memory _uri, - string memory _name, - string memory _description -) - public pure returns (IRC27NFTMetadata memory) -{ - string memory json = string(abi.encodePacked( - '{"name":"', _name, - '","description":"', _description, - '","image":"', _uri, - '"}' - )); - - string memory encodedURI = string(abi.encodePacked( - "data:application/json;base64,", - Base64.encode(bytes(json)) - )); + function decodeNFTMetadataURI(string memory encodedURI) public pure returns (IRC27NFTMetadata memory) { + // Ensure the encodedURI has the correct prefix + require(bytes(encodedURI).length > 29, "Invalid encoded URI length"); + string memory base64JSON = substring(encodedURI, 29, bytes(encodedURI).length); + + // Decode the Base64-encoded JSON + bytes memory decodedBytes = Base64.decode(base64JSON); + string memory json = string(decodedBytes); + + // Extract fields from the JSON string + string memory name = extractValueFromJSON(json, "name"); + string memory description = extractValueFromJSON(json, "description"); + string memory uri = extractValueFromJSON(json, "image"); + + return IRC27NFTMetadata({ + standard: "IRC27", + version: "1.0", + mimeType: "application/json", + uri: encodedURI, + name: name, + description: description + }); + } - return IRC27NFTMetadata({ - standard: _standard, - version: _version, - mimeType: _mimeType, - uri: encodedURI, - name: _name - }); -} -} -``` -## Example Usage + function substring(string memory str, uint startIndex, uint endIndex) internal pure returns (string memory) { + bytes memory strBytes = bytes(str); + bytes memory result = new bytes(endIndex - startIndex); + for (uint i = startIndex; i < endIndex; i++) { + result[i - startIndex] = strBytes[i]; + } + return string(result); + } -To mint a new NFT and fetch its metadata, you would use the above functions within a larger contract that handles NFT minting and management. \ No newline at end of file + function extractValueFromJSON(string memory json, string memory key) internal pure returns (string memory) { + bytes memory jsonBytes = bytes(json); + bytes memory keyBytes = bytes(key); + bytes memory result = new bytes(jsonBytes.length); + uint256 resultIndex = 0; + bool keyFound = false; + + for (uint256 i = 0; i < jsonBytes.length; i++) { + if (jsonBytes[i] == keyBytes[0]) { + uint256 j = 0; + while (j < keyBytes.length && jsonBytes[i + j] == keyBytes[j]) { + j++; + } + if (j == keyBytes.length && jsonBytes[i + j] == ':') { + keyFound = true; + i += j + 1; + } + } + + if (keyFound && jsonBytes[i] == '"') { + i++; + while (jsonBytes[i] != '"') { + result[resultIndex++] = jsonBytes[i++]; + } + break; + } + } + + return string(result); + } +} +``` \ No newline at end of file From b91c619b6d9b9b463b69356471123c1d1c0f12bc Mon Sep 17 00:00:00 2001 From: Gino Date: Tue, 11 Jun 2024 02:20:56 +0100 Subject: [PATCH 08/14] docs(isc-wiki): implement review suggestions --- .../isc/v1.1/docs/_admonitions/_IRC27.md | 5 + .../core-contracts/nft/get-nft-metadata.md | 233 ------------------ .../core-contracts/nft/get-nft-metadata.mdx | 56 +++++ 3 files changed, 61 insertions(+), 233 deletions(-) create mode 100644 docs/build/isc/v1.1/docs/_admonitions/_IRC27.md delete mode 100644 docs/build/isc/v1.1/docs/how-tos/core-contracts/nft/get-nft-metadata.md create mode 100644 docs/build/isc/v1.1/docs/how-tos/core-contracts/nft/get-nft-metadata.mdx diff --git a/docs/build/isc/v1.1/docs/_admonitions/_IRC27.md b/docs/build/isc/v1.1/docs/_admonitions/_IRC27.md new file mode 100644 index 00000000000..7a23450fe5d --- /dev/null +++ b/docs/build/isc/v1.1/docs/_admonitions/_IRC27.md @@ -0,0 +1,5 @@ +:::info IRC27NFTMetadata URI + +The uri property contains a JSON object which follows the `ERC721` standard. This JSON is also returned by the [`tokenURI`](../../../reference/magic-contract/ERC721NFTs.md#tokenuri) function from the `ERC721NFTs` contract. + +::: \ No newline at end of file diff --git a/docs/build/isc/v1.1/docs/how-tos/core-contracts/nft/get-nft-metadata.md b/docs/build/isc/v1.1/docs/how-tos/core-contracts/nft/get-nft-metadata.md deleted file mode 100644 index 4865baed78a..00000000000 --- a/docs/build/isc/v1.1/docs/how-tos/core-contracts/nft/get-nft-metadata.md +++ /dev/null @@ -1,233 +0,0 @@ ---- -description: How to get NFT metadata on L1 -image: /img/logo/WASP_logo_dark.png -tags: - - NFT - - EVM - - how-to ---- -import GetNftMetadata from '../../../_partials/how-tos/token/_get-nft-metadata.md'; -import ERC721Admonition from '../../../_admonitions/_ERC721.md'; - -# Get NFT Metadata - - - -This guide explains how to use the [`getIRC27NFTData`](../../../reference/magic-contract/ISCSandbox.md#getirc27nftdata) function within a smart contract to fetch information about a specific IRC27 NFT on the IOTA Network. - - - -## Understanding the `getIRC27NFTData` Function - -The [`getIRC27NFTData`](../../../reference/magic-contract/ISCSandbox.md#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` - -### 1. Fetch IRC27 NFT Metadata - -Create a function called `fetchNFTData` in your contract that calls `getIRC27NFTData` and processes its return value. - -```solidity -function fetchNFTData(bytes memory nftID) public view returns (IRC27NFT memory irc27NftData) { - bytes32 id = bytes32(nftID); - NFTID nftIDTyped = NFTID.wrap(id); - irc27NftData = ISC.sandbox.getIRC27NFTData(nftIDTyped); - return irc27NftData; -} -``` -### 2. Encode the URI Data in `IRC27NFTMetadata` - -The `IRC27NFTMetadata` struct holds detailed metadata, including the URI and other fields like name and description. Encoding this data correctly is crucial for ensuring the integrity and accessibility of the NFT's metadata. - -```solidity -struct IRC27NFTMetadata {string uri; string name;string description;} -``` - -### 3. Decode the URI Data in IRC27NFTMetadata - -The `IRC27NFTMetadata` struct holds detailed metadata, including the URI and other fields like name and description. Decoding this data correctly is crucial for ensuring the integrity and accessibility of the NFT's metadata. - -```solidity -function decodeNFTMetadataURI(string memory encodedURI) public pure returns (IRC27NFTMetadata memory) { - // Ensure the encodedURI has the correct prefix - require(bytes(encodedURI).length > 29, "Invalid encoded URI length"); - string memory base64JSON = substring(encodedURI, 29, bytes(encodedURI).length); - - // Decode the Base64-encoded JSON - bytes memory decodedBytes = Base64.decode(base64JSON); - string memory json = string(decodedBytes); - - // Extract fields from the JSON string - string memory name = extractValueFromJSON(json, "name"); - string memory description = extractValueFromJSON(json, "description"); - string memory uri = extractValueFromJSON(json, "image"); - - return IRC27NFTMetadata({ - standard: "IRC27", - version: "1.0", - mimeType: "application/json", - uri: encodedURI, - name: name, - description: description - }); -} -``` - -### `substring` Function - -The substring function extracts a substring from a given string based on specified start and end indices. This is useful for isolating the Base64-encoded JSON part of the URI. - -```solidity - -function substring(string memory str, uint startIndex, uint endIndex) internal pure returns (string memory) { - bytes memory strBytes = bytes(str); - bytes memory result = new bytes(endIndex - startIndex); - for (uint i = startIndex; i < endIndex; i++) { - result[i - startIndex] = strBytes[i]; - } - return string(result); -} - -``` - -### `extractValueFromJSON` Function - -The `extractValueFromJSON` function extracts the value associated with a specific key from a JSON string. This function helps to retrieve individual fields like name, description, and image from the decoded JSON metadata. - -```solidity - -function extractValueFromJSON(string memory json, string memory key) internal pure returns (string memory) { - bytes memory jsonBytes = bytes(json); - bytes memory keyBytes = bytes(key); - bytes memory result = new bytes(jsonBytes.length); - uint256 resultIndex = 0; - bool keyFound = false; - - for (uint256 i = 0; i < jsonBytes.length; i++) { - if (jsonBytes[i] == keyBytes[0]) { - uint256 j = 0; - while (j < keyBytes.length && jsonBytes[i + j] == keyBytes[j]) { - j++; - } - if (j == keyBytes.length && jsonBytes[i + j] == ':') { - keyFound = true; - i += j + 1; - } - } - - if (keyFound && jsonBytes[i] == '"') { - i++; - while (jsonBytes[i] != '"') { - result[resultIndex++] = jsonBytes[i++]; - } - break; - } - } - - return string(result); -} - -``` - -## Full Example Contract - -Combining all the above steps, here’s a complete example: - -```solidity -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.0; - -import "@openzeppelin/contracts/utils/Base64.sol"; -import "@iota/iscmagic/ISC.sol"; -import "@iota/iscmagic/ISCTypes.sol"; - -contract NFTMetadata { - struct IRC27NFT { - bytes id; - string uri; - string name; - string description; - } - - struct IRC27NFTMetadata { - string standard; - string version; - string mimeType; - string uri; - string name; - string description; - } - - function fetchNFTData(bytes memory nftID) public view returns (IRC27NFT memory irc27NftData) { - require(nftID.length == 32, "NFT ID must be 32 bytes"); - bytes32 id = bytes32(nftID); - NFTID nftIDTyped = NFTID.wrap(id); - irc27NftData = ISC.sandbox.getIRC27NFTData(nftIDTyped); - return irc27NftData; - } - - function decodeNFTMetadataURI(string memory encodedURI) public pure returns (IRC27NFTMetadata memory) { - // Ensure the encodedURI has the correct prefix - require(bytes(encodedURI).length > 29, "Invalid encoded URI length"); - string memory base64JSON = substring(encodedURI, 29, bytes(encodedURI).length); - - // Decode the Base64-encoded JSON - bytes memory decodedBytes = Base64.decode(base64JSON); - string memory json = string(decodedBytes); - - // Extract fields from the JSON string - string memory name = extractValueFromJSON(json, "name"); - string memory description = extractValueFromJSON(json, "description"); - string memory uri = extractValueFromJSON(json, "image"); - - return IRC27NFTMetadata({ - standard: "IRC27", - version: "1.0", - mimeType: "application/json", - uri: encodedURI, - name: name, - description: description - }); - } - - function substring(string memory str, uint startIndex, uint endIndex) internal pure returns (string memory) { - bytes memory strBytes = bytes(str); - bytes memory result = new bytes(endIndex - startIndex); - for (uint i = startIndex; i < endIndex; i++) { - result[i - startIndex] = strBytes[i]; - } - return string(result); - } - - function extractValueFromJSON(string memory json, string memory key) internal pure returns (string memory) { - bytes memory jsonBytes = bytes(json); - bytes memory keyBytes = bytes(key); - bytes memory result = new bytes(jsonBytes.length); - uint256 resultIndex = 0; - bool keyFound = false; - - for (uint256 i = 0; i < jsonBytes.length; i++) { - if (jsonBytes[i] == keyBytes[0]) { - uint256 j = 0; - while (j < keyBytes.length && jsonBytes[i + j] == keyBytes[j]) { - j++; - } - if (j == keyBytes.length && jsonBytes[i + j] == ':') { - keyFound = true; - i += j + 1; - } - } - - if (keyFound && jsonBytes[i] == '"') { - i++; - while (jsonBytes[i] != '"') { - result[resultIndex++] = jsonBytes[i++]; - } - break; - } - } - - return string(result); - } -} -``` \ No newline at end of file diff --git a/docs/build/isc/v1.1/docs/how-tos/core-contracts/nft/get-nft-metadata.mdx b/docs/build/isc/v1.1/docs/how-tos/core-contracts/nft/get-nft-metadata.mdx new file mode 100644 index 00000000000..b5cc2711b1d --- /dev/null +++ b/docs/build/isc/v1.1/docs/how-tos/core-contracts/nft/get-nft-metadata.mdx @@ -0,0 +1,56 @@ +--- +description: How to get NFT metadata from a L1 NFT +image: /img/logo/WASP_logo_dark.png +tags: + - NFT + - EVM + - how-to +--- +import GetNftMetadata from '../../../_partials/how-tos/token/_get-nft-metadata.md'; +import ERC721Admonition from '../../../_admonitions/_ERC721.md'; +import IRC27Admonition from '../../../_admonitions/_IRC27.md'; + +# Get IRC27 NFT Metadata + + + +This guide explains how to use the [`getIRC27NFTData`](../../../reference/magic-contract/ISCSandbox.md#getirc27nftdata) function within a smart contract to fetch information about a specific IRC27 NFT on the IOTA Network. + + + +## Understanding the `getIRC27NFTData` Function + +The [`getIRC27NFTData`](../../../reference/magic-contract/ISCSandbox.md#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`](../../../reference/magic-contract/ISCTypes.md#irc27nftmetadata) which contains properties like the NFT name, uri and more. + + + +```solidity +function fetchIRC27NFTData(uint256 tokenId) public view returns (IRC27NFT memory irc27NftData) { + irc27NftData = ISC.sandbox.getIRC27NFTData(tokenId.asNFTID()); + return irc27NftData; +} +``` + +## Full Example Contract + +Combining all the above steps, here’s a complete example: + +```solidity +// 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(tokenId.asNFTID()); + return irc27NftData; + } +} +``` \ No newline at end of file From 81a63ec17b5d51e65643c33979550856874ba791 Mon Sep 17 00:00:00 2001 From: Gino Date: Tue, 11 Jun 2024 02:39:40 +0100 Subject: [PATCH 09/14] docs(isc-wiki): duplicate guide on V1.3-alpha --- .../v1.3-alpha/docs/_admonitions/_ERC721.md | 5 ++ .../v1.3-alpha/docs/_admonitions/_IRC27.md | 5 ++ .../how-tos/token/_get-nft-metadata.md | 5 ++ .../core-contracts/nft/get-nft-metadata.mdx | 56 +++++++++++++++++++ 4 files changed, 71 insertions(+) create mode 100644 docs/build/isc/v1.3-alpha/docs/_admonitions/_ERC721.md create mode 100644 docs/build/isc/v1.3-alpha/docs/_admonitions/_IRC27.md create mode 100644 docs/build/isc/v1.3-alpha/docs/_partials/how-tos/token/_get-nft-metadata.md create mode 100644 docs/build/isc/v1.3-alpha/docs/how-tos/core-contracts/nft/get-nft-metadata.mdx diff --git a/docs/build/isc/v1.3-alpha/docs/_admonitions/_ERC721.md b/docs/build/isc/v1.3-alpha/docs/_admonitions/_ERC721.md new file mode 100644 index 00000000000..76191eec6be --- /dev/null +++ b/docs/build/isc/v1.3-alpha/docs/_admonitions/_ERC721.md @@ -0,0 +1,5 @@ +:::info ERC721 + +As your L1 NFT is always registered as [ERC721](https://eips.ethereum.org/EIPS/eip-721), you might want to get the metadata like `tokenURI` from there. Using `getIRC27NFTData` is normally only needed if you need special [IRC27](https://wiki.iota.org/tips/tips/TIP-0027/) metadata. + +::: \ No newline at end of file diff --git a/docs/build/isc/v1.3-alpha/docs/_admonitions/_IRC27.md b/docs/build/isc/v1.3-alpha/docs/_admonitions/_IRC27.md new file mode 100644 index 00000000000..7a23450fe5d --- /dev/null +++ b/docs/build/isc/v1.3-alpha/docs/_admonitions/_IRC27.md @@ -0,0 +1,5 @@ +:::info IRC27NFTMetadata URI + +The uri property contains a JSON object which follows the `ERC721` standard. This JSON is also returned by the [`tokenURI`](../../../reference/magic-contract/ERC721NFTs.md#tokenuri) function from the `ERC721NFTs` contract. + +::: \ No newline at end of file diff --git a/docs/build/isc/v1.3-alpha/docs/_partials/how-tos/token/_get-nft-metadata.md b/docs/build/isc/v1.3-alpha/docs/_partials/how-tos/token/_get-nft-metadata.md new file mode 100644 index 00000000000..1ed17749708 --- /dev/null +++ b/docs/build/isc/v1.3-alpha/docs/_partials/how-tos/token/_get-nft-metadata.md @@ -0,0 +1,5 @@ +:::tip Mint an NFT + +Mint your first NFT following our how to [mint an NFT guide](../how-tos/core-contracts/nft/mint-nft.md#about-nfts). + +::: \ No newline at end of file diff --git a/docs/build/isc/v1.3-alpha/docs/how-tos/core-contracts/nft/get-nft-metadata.mdx b/docs/build/isc/v1.3-alpha/docs/how-tos/core-contracts/nft/get-nft-metadata.mdx new file mode 100644 index 00000000000..b5cc2711b1d --- /dev/null +++ b/docs/build/isc/v1.3-alpha/docs/how-tos/core-contracts/nft/get-nft-metadata.mdx @@ -0,0 +1,56 @@ +--- +description: How to get NFT metadata from a L1 NFT +image: /img/logo/WASP_logo_dark.png +tags: + - NFT + - EVM + - how-to +--- +import GetNftMetadata from '../../../_partials/how-tos/token/_get-nft-metadata.md'; +import ERC721Admonition from '../../../_admonitions/_ERC721.md'; +import IRC27Admonition from '../../../_admonitions/_IRC27.md'; + +# Get IRC27 NFT Metadata + + + +This guide explains how to use the [`getIRC27NFTData`](../../../reference/magic-contract/ISCSandbox.md#getirc27nftdata) function within a smart contract to fetch information about a specific IRC27 NFT on the IOTA Network. + + + +## Understanding the `getIRC27NFTData` Function + +The [`getIRC27NFTData`](../../../reference/magic-contract/ISCSandbox.md#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`](../../../reference/magic-contract/ISCTypes.md#irc27nftmetadata) which contains properties like the NFT name, uri and more. + + + +```solidity +function fetchIRC27NFTData(uint256 tokenId) public view returns (IRC27NFT memory irc27NftData) { + irc27NftData = ISC.sandbox.getIRC27NFTData(tokenId.asNFTID()); + return irc27NftData; +} +``` + +## Full Example Contract + +Combining all the above steps, here’s a complete example: + +```solidity +// 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(tokenId.asNFTID()); + return irc27NftData; + } +} +``` \ No newline at end of file From 3c4243be1fdd1106dae60e142962ddf5a2c086c9 Mon Sep 17 00:00:00 2001 From: Gino Date: Wed, 12 Jun 2024 08:10:27 +0100 Subject: [PATCH 10/14] docs(isc-wiki): fix link to mint-nft.md file --- .../isc/v1.1/docs/_partials/how-tos/token/_get-nft-metadata.md | 2 +- .../docs/_partials/how-tos/token/_get-nft-metadata.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/build/isc/v1.1/docs/_partials/how-tos/token/_get-nft-metadata.md b/docs/build/isc/v1.1/docs/_partials/how-tos/token/_get-nft-metadata.md index 1ed17749708..a13f2634c7d 100644 --- a/docs/build/isc/v1.1/docs/_partials/how-tos/token/_get-nft-metadata.md +++ b/docs/build/isc/v1.1/docs/_partials/how-tos/token/_get-nft-metadata.md @@ -1,5 +1,5 @@ :::tip Mint an NFT -Mint your first NFT following our how to [mint an NFT guide](../how-tos/core-contracts/nft/mint-nft.md#about-nfts). +Mint your first NFT following our how to [mint an NFT guide](../../../how-tos/core-contracts/nft/mint-nft.md#about-nfts). ::: \ No newline at end of file diff --git a/docs/build/isc/v1.3-alpha/docs/_partials/how-tos/token/_get-nft-metadata.md b/docs/build/isc/v1.3-alpha/docs/_partials/how-tos/token/_get-nft-metadata.md index 1ed17749708..a13f2634c7d 100644 --- a/docs/build/isc/v1.3-alpha/docs/_partials/how-tos/token/_get-nft-metadata.md +++ b/docs/build/isc/v1.3-alpha/docs/_partials/how-tos/token/_get-nft-metadata.md @@ -1,5 +1,5 @@ :::tip Mint an NFT -Mint your first NFT following our how to [mint an NFT guide](../how-tos/core-contracts/nft/mint-nft.md#about-nfts). +Mint your first NFT following our how to [mint an NFT guide](../../../how-tos/core-contracts/nft/mint-nft.md#about-nfts). ::: \ No newline at end of file From e2ae53d29a9daaa0b7a6d54b315c475143f8c47d Mon Sep 17 00:00:00 2001 From: Gino Osahon Date: Fri, 14 Jun 2024 10:51:49 +0100 Subject: [PATCH 11/14] Apply suggestions from code review Co-authored-by: Lucas Tortora <85233773+lucas-tortora@users.noreply.github.com> --- docs/build/isc/v1.1/docs/_admonitions/_IRC27.md | 2 +- docs/build/isc/v1.3-alpha/docs/_admonitions/_IRC27.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/build/isc/v1.1/docs/_admonitions/_IRC27.md b/docs/build/isc/v1.1/docs/_admonitions/_IRC27.md index 7a23450fe5d..1831e8fe100 100644 --- a/docs/build/isc/v1.1/docs/_admonitions/_IRC27.md +++ b/docs/build/isc/v1.1/docs/_admonitions/_IRC27.md @@ -1,5 +1,5 @@ :::info IRC27NFTMetadata URI -The uri property contains a JSON object which follows the `ERC721` standard. This JSON is also returned by the [`tokenURI`](../../../reference/magic-contract/ERC721NFTs.md#tokenuri) function from the `ERC721NFTs` contract. +The uri property contains a JSON object which follows the `ERC721` standard. This JSON is also returned by the [`tokenURI`](../reference/magic-contract/ERC721NFTs.md#tokenuri) function from the `ERC721NFTs` contract. ::: \ No newline at end of file diff --git a/docs/build/isc/v1.3-alpha/docs/_admonitions/_IRC27.md b/docs/build/isc/v1.3-alpha/docs/_admonitions/_IRC27.md index 7a23450fe5d..1831e8fe100 100644 --- a/docs/build/isc/v1.3-alpha/docs/_admonitions/_IRC27.md +++ b/docs/build/isc/v1.3-alpha/docs/_admonitions/_IRC27.md @@ -1,5 +1,5 @@ :::info IRC27NFTMetadata URI -The uri property contains a JSON object which follows the `ERC721` standard. This JSON is also returned by the [`tokenURI`](../../../reference/magic-contract/ERC721NFTs.md#tokenuri) function from the `ERC721NFTs` contract. +The uri property contains a JSON object which follows the `ERC721` standard. This JSON is also returned by the [`tokenURI`](../reference/magic-contract/ERC721NFTs.md#tokenuri) function from the `ERC721NFTs` contract. ::: \ No newline at end of file From a84c853991e4707a823d7badcccd4b3e1c7180d4 Mon Sep 17 00:00:00 2001 From: Gino Date: Fri, 14 Jun 2024 17:10:46 +0100 Subject: [PATCH 12/14] docs(isc-wiki): update fetchIRC27NFTData function --- .../v1.1/docs/how-tos/core-contracts/nft/get-nft-metadata.mdx | 4 ++-- .../docs/how-tos/core-contracts/nft/get-nft-metadata.mdx | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/build/isc/v1.1/docs/how-tos/core-contracts/nft/get-nft-metadata.mdx b/docs/build/isc/v1.1/docs/how-tos/core-contracts/nft/get-nft-metadata.mdx index b5cc2711b1d..dcdd62d5595 100644 --- a/docs/build/isc/v1.1/docs/how-tos/core-contracts/nft/get-nft-metadata.mdx +++ b/docs/build/isc/v1.1/docs/how-tos/core-contracts/nft/get-nft-metadata.mdx @@ -30,7 +30,7 @@ Create a function called `fetchIRC27NFTData` in your contract that calls `getIRC ```solidity function fetchIRC27NFTData(uint256 tokenId) public view returns (IRC27NFT memory irc27NftData) { - irc27NftData = ISC.sandbox.getIRC27NFTData(tokenId.asNFTID()); + irc27NftData = ISC.sandbox.getIRC27NFTData(ISCTypes.asNFTID(tokenId)); return irc27NftData; } ``` @@ -49,7 +49,7 @@ import "@iota/iscmagic/ISCTypes.sol"; contract IRCNFTMetadata { function fetchIRC27NFTData(uint256 tokenId) public view returns (IRC27NFT memory irc27NftData) { - irc27NftData = ISC.sandbox.getIRC27NFTData(tokenId.asNFTID()); + irc27NftData = ISC.sandbox.getIRC27NFTData(ISCTypes.asNFTID(tokenId)); return irc27NftData; } } diff --git a/docs/build/isc/v1.3-alpha/docs/how-tos/core-contracts/nft/get-nft-metadata.mdx b/docs/build/isc/v1.3-alpha/docs/how-tos/core-contracts/nft/get-nft-metadata.mdx index b5cc2711b1d..dcdd62d5595 100644 --- a/docs/build/isc/v1.3-alpha/docs/how-tos/core-contracts/nft/get-nft-metadata.mdx +++ b/docs/build/isc/v1.3-alpha/docs/how-tos/core-contracts/nft/get-nft-metadata.mdx @@ -30,7 +30,7 @@ Create a function called `fetchIRC27NFTData` in your contract that calls `getIRC ```solidity function fetchIRC27NFTData(uint256 tokenId) public view returns (IRC27NFT memory irc27NftData) { - irc27NftData = ISC.sandbox.getIRC27NFTData(tokenId.asNFTID()); + irc27NftData = ISC.sandbox.getIRC27NFTData(ISCTypes.asNFTID(tokenId)); return irc27NftData; } ``` @@ -49,7 +49,7 @@ import "@iota/iscmagic/ISCTypes.sol"; contract IRCNFTMetadata { function fetchIRC27NFTData(uint256 tokenId) public view returns (IRC27NFT memory irc27NftData) { - irc27NftData = ISC.sandbox.getIRC27NFTData(tokenId.asNFTID()); + irc27NftData = ISC.sandbox.getIRC27NFTData(ISCTypes.asNFTID(tokenId)); return irc27NftData; } } From 202cf8e2efe127dca5b89bd345a6419401edbf0f Mon Sep 17 00:00:00 2001 From: Dr-Electron Date: Tue, 18 Jun 2024 18:55:14 +0200 Subject: [PATCH 13/14] Format --- .../docs/how-tos/core-contracts/nft/get-nft-metadata.mdx | 7 +++---- .../docs/how-tos/core-contracts/nft/get-nft-metadata.mdx | 7 +++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/docs/build/isc/v1.1/docs/how-tos/core-contracts/nft/get-nft-metadata.mdx b/docs/build/isc/v1.1/docs/how-tos/core-contracts/nft/get-nft-metadata.mdx index dcdd62d5595..3795884916c 100644 --- a/docs/build/isc/v1.1/docs/how-tos/core-contracts/nft/get-nft-metadata.mdx +++ b/docs/build/isc/v1.1/docs/how-tos/core-contracts/nft/get-nft-metadata.mdx @@ -47,10 +47,9 @@ 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; + function fetchIRC27NFTData(uint256 tokenId) public view returns (IRC27NFT memory irc27NftData) { + irc27NftData = ISC.sandbox.getIRC27NFTData(ISCTypes.asNFTID(tokenId)); + return irc27NftData; } } ``` \ No newline at end of file diff --git a/docs/build/isc/v1.3-alpha/docs/how-tos/core-contracts/nft/get-nft-metadata.mdx b/docs/build/isc/v1.3-alpha/docs/how-tos/core-contracts/nft/get-nft-metadata.mdx index dcdd62d5595..3795884916c 100644 --- a/docs/build/isc/v1.3-alpha/docs/how-tos/core-contracts/nft/get-nft-metadata.mdx +++ b/docs/build/isc/v1.3-alpha/docs/how-tos/core-contracts/nft/get-nft-metadata.mdx @@ -47,10 +47,9 @@ 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; + function fetchIRC27NFTData(uint256 tokenId) public view returns (IRC27NFT memory irc27NftData) { + irc27NftData = ISC.sandbox.getIRC27NFTData(ISCTypes.asNFTID(tokenId)); + return irc27NftData; } } ``` \ No newline at end of file From 2c36294156400ac6200e82e750130ffd72a52a91 Mon Sep 17 00:00:00 2001 From: Dr-Electron Date: Tue, 18 Jun 2024 18:55:31 +0200 Subject: [PATCH 14/14] Fix sidebar --- docs/build/isc/v1.3-alpha/sidebars.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/build/isc/v1.3-alpha/sidebars.js b/docs/build/isc/v1.3-alpha/sidebars.js index 9d07b38ff0b..9d20a677ccb 100644 --- a/docs/build/isc/v1.3-alpha/sidebars.js +++ b/docs/build/isc/v1.3-alpha/sidebars.js @@ -205,6 +205,11 @@ module.exports = { label: 'Use as ERC721', id: 'how-tos/core-contracts/nft/use-as-erc721', }, + { + type: 'doc', + label: 'Get NFT Metadata', + id: 'how-tos/core-contracts/nft/get-nft-metadata', + }, ], }, {