From effde94ade4aa72d06d5058a4bd687f6b07473fd Mon Sep 17 00:00:00 2001 From: Gino Date: Mon, 8 Jul 2024 15:34:41 +0100 Subject: [PATCH 1/2] feat(wiki): create a guide for getting an on-chain NFT data --- .../core-contracts/nft/get-nft-data.mdx | 47 +++++++++++++++++++ docs/build/isc/v1.1/sidebars.js | 5 ++ .../core-contracts/nft/get-nft-data.mdx | 47 +++++++++++++++++++ docs/build/isc/v1.3/sidebars.js | 5 ++ 4 files changed, 104 insertions(+) create mode 100644 docs/build/isc/v1.1/docs/how-tos/core-contracts/nft/get-nft-data.mdx create mode 100644 docs/build/isc/v1.3/docs/how-tos/core-contracts/nft/get-nft-data.mdx diff --git a/docs/build/isc/v1.1/docs/how-tos/core-contracts/nft/get-nft-data.mdx b/docs/build/isc/v1.1/docs/how-tos/core-contracts/nft/get-nft-data.mdx new file mode 100644 index 00000000000..c1110a2a564 --- /dev/null +++ b/docs/build/isc/v1.1/docs/how-tos/core-contracts/nft/get-nft-data.mdx @@ -0,0 +1,47 @@ +--- +description: How to get information about an on-chain NFT. +image: /img/logo/WASP_logo_dark.png +tags: + - EVM + - how-to + - native tokens + - L2 NFTs +--- +import GetNftMetadata from '../../../_partials/how-tos/token/_get-nft-metadata.md'; + +# Get On-Chain NFT Data + +This guide explains how to use the [`getNFTData`](../../../reference/magic-contract/ISCSandbox.md#getnftdata) function within a smart contract to fetch information about a specific on-chain NFT on the IOTA network. + + +## 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`](../../../reference/magic-contract/ISCTypes.md#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. + +Here's an example of how to implement this: + +```solidity +function fetchNFTData(uint256 tokenId) public view returns (ISCNFT memory nftData) { + nftData = ISC.sandbox.getNFTData(ISCTypes.asNFTID(tokenId)); + return nftData; +} +``` + +## Full Example Code + +Combining the above step, 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 NFTMetadata { + function fetchNFTData(uint256 tokenId) public view returns (ISCNFT memory nftData) { + nftData = ISC.sandbox.getNFTData(ISCTypes.asNFTID(tokenId)); + return nftData; + } +} +``` \ No newline at end of file diff --git a/docs/build/isc/v1.1/sidebars.js b/docs/build/isc/v1.1/sidebars.js index 6e93e225937..76a9ed2b3eb 100644 --- a/docs/build/isc/v1.1/sidebars.js +++ b/docs/build/isc/v1.1/sidebars.js @@ -225,6 +225,11 @@ module.exports = { label: 'Get NFTs in Collection', id: 'how-tos/core-contracts/nft/get-nft-in-collection', }, + { + type: 'doc', + label: 'Get On-Chain NFT Data', + id: 'how-tos/core-contracts/nft/get-nft-data', + }, ], }, { diff --git a/docs/build/isc/v1.3/docs/how-tos/core-contracts/nft/get-nft-data.mdx b/docs/build/isc/v1.3/docs/how-tos/core-contracts/nft/get-nft-data.mdx new file mode 100644 index 00000000000..c1110a2a564 --- /dev/null +++ b/docs/build/isc/v1.3/docs/how-tos/core-contracts/nft/get-nft-data.mdx @@ -0,0 +1,47 @@ +--- +description: How to get information about an on-chain NFT. +image: /img/logo/WASP_logo_dark.png +tags: + - EVM + - how-to + - native tokens + - L2 NFTs +--- +import GetNftMetadata from '../../../_partials/how-tos/token/_get-nft-metadata.md'; + +# Get On-Chain NFT Data + +This guide explains how to use the [`getNFTData`](../../../reference/magic-contract/ISCSandbox.md#getnftdata) function within a smart contract to fetch information about a specific on-chain NFT on the IOTA network. + + +## 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`](../../../reference/magic-contract/ISCTypes.md#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. + +Here's an example of how to implement this: + +```solidity +function fetchNFTData(uint256 tokenId) public view returns (ISCNFT memory nftData) { + nftData = ISC.sandbox.getNFTData(ISCTypes.asNFTID(tokenId)); + return nftData; +} +``` + +## Full Example Code + +Combining the above step, 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 NFTMetadata { + function fetchNFTData(uint256 tokenId) public view returns (ISCNFT memory nftData) { + nftData = ISC.sandbox.getNFTData(ISCTypes.asNFTID(tokenId)); + return nftData; + } +} +``` \ No newline at end of file diff --git a/docs/build/isc/v1.3/sidebars.js b/docs/build/isc/v1.3/sidebars.js index 6e93e225937..76a9ed2b3eb 100644 --- a/docs/build/isc/v1.3/sidebars.js +++ b/docs/build/isc/v1.3/sidebars.js @@ -225,6 +225,11 @@ module.exports = { label: 'Get NFTs in Collection', id: 'how-tos/core-contracts/nft/get-nft-in-collection', }, + { + type: 'doc', + label: 'Get On-Chain NFT Data', + id: 'how-tos/core-contracts/nft/get-nft-data', + }, ], }, { From 06d39f8acd9f3792e7b188c33237315813461b22 Mon Sep 17 00:00:00 2001 From: Gino Date: Tue, 9 Jul 2024 11:27:04 +0100 Subject: [PATCH 2/2] refactor(wiki): implement review suggestions --- .../how-tos/core-contracts/nft/get-nft-data.mdx | 16 +++------------- .../how-tos/core-contracts/nft/get-nft-data.mdx | 16 +++------------- 2 files changed, 6 insertions(+), 26 deletions(-) diff --git a/docs/build/isc/v1.1/docs/how-tos/core-contracts/nft/get-nft-data.mdx b/docs/build/isc/v1.1/docs/how-tos/core-contracts/nft/get-nft-data.mdx index c1110a2a564..67e415112ed 100644 --- a/docs/build/isc/v1.1/docs/how-tos/core-contracts/nft/get-nft-data.mdx +++ b/docs/build/isc/v1.1/docs/how-tos/core-contracts/nft/get-nft-data.mdx @@ -12,24 +12,14 @@ import GetNftMetadata from '../../../_partials/how-tos/token/_get-nft-metadata.m # Get On-Chain NFT Data This guide explains how to use the [`getNFTData`](../../../reference/magic-contract/ISCSandbox.md#getnftdata) function within a smart contract to fetch information about a specific on-chain NFT on the IOTA network. + ## 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`](../../../reference/magic-contract/ISCTypes.md#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. - -Here's an example of how to implement this: - -```solidity -function fetchNFTData(uint256 tokenId) public view returns (ISCNFT memory nftData) { - nftData = ISC.sandbox.getNFTData(ISCTypes.asNFTID(tokenId)); - return nftData; -} -``` - -## Full Example Code +The `getNFTData` function retrieves data for an NFT based on its identifier. It returns a struct of type [`ISCNFT`](../../../reference/magic-contract/ISCTypes.md#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: -Combining the above step, here’s a complete example: +## Example Code ```solidity // SPDX-License-Identifier: MIT diff --git a/docs/build/isc/v1.3/docs/how-tos/core-contracts/nft/get-nft-data.mdx b/docs/build/isc/v1.3/docs/how-tos/core-contracts/nft/get-nft-data.mdx index c1110a2a564..67e415112ed 100644 --- a/docs/build/isc/v1.3/docs/how-tos/core-contracts/nft/get-nft-data.mdx +++ b/docs/build/isc/v1.3/docs/how-tos/core-contracts/nft/get-nft-data.mdx @@ -12,24 +12,14 @@ import GetNftMetadata from '../../../_partials/how-tos/token/_get-nft-metadata.m # Get On-Chain NFT Data This guide explains how to use the [`getNFTData`](../../../reference/magic-contract/ISCSandbox.md#getnftdata) function within a smart contract to fetch information about a specific on-chain NFT on the IOTA network. + ## 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`](../../../reference/magic-contract/ISCTypes.md#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. - -Here's an example of how to implement this: - -```solidity -function fetchNFTData(uint256 tokenId) public view returns (ISCNFT memory nftData) { - nftData = ISC.sandbox.getNFTData(ISCTypes.asNFTID(tokenId)); - return nftData; -} -``` - -## Full Example Code +The `getNFTData` function retrieves data for an NFT based on its identifier. It returns a struct of type [`ISCNFT`](../../../reference/magic-contract/ISCTypes.md#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: -Combining the above step, here’s a complete example: +## Example Code ```solidity // SPDX-License-Identifier: MIT