Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DevEx - Docs: create a guide for getting an on-chain NFT data #1648

Merged
merged 2 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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.
<GetNftMetadata />
Ginowine marked this conversation as resolved.
Show resolved Hide resolved

## 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.
Ginowine marked this conversation as resolved.
Show resolved Hide resolved

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:
Ginowine marked this conversation as resolved.
Show resolved Hide resolved

```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;
}
}
```
5 changes: 5 additions & 0 deletions docs/build/isc/v1.1/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
],
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
<GetNftMetadata />

## 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;
}
}
```
5 changes: 5 additions & 0 deletions docs/build/isc/v1.3/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
],
},
{
Expand Down
Loading