diff --git a/docs/build/isc/v1.3/docs/how-tos/core-contracts/nft/get-nft-in-collection.mdx b/docs/build/isc/v1.3/docs/how-tos/core-contracts/nft/get-nft-in-collection.mdx new file mode 100644 index 00000000000..d146479f6dc --- /dev/null +++ b/docs/build/isc/v1.3/docs/how-tos/core-contracts/nft/get-nft-in-collection.mdx @@ -0,0 +1,108 @@ +--- +description: How to get the L2 NFTs in a collection. +image: /img/logo/WASP_logo_dark.png +tags: + - EVM + - how-to + - native tokens + - L2 NFTs + - Collection +--- +import GetNftMetadata from '../../../_partials/how-tos/token/_get-nft-metadata.md'; + +# Get NFTs of a Given Collection + +This guide will show you how to get the L2 NFTs of a given collection owned by an account using the [`ISCAccounts.getL2NFTsInCollection`](../../../reference/magic-contract/ISCAccounts.md#getl2nftsincollection) function from the [`ISCAccounts.getL2NFTsInCollection`](../../../reference/magic-contract/ISCAccounts.md) [magic contract](../../../reference/magic-contract/introduction.md). + + + +## Understanding the `getL2NFTsInCollection` Function + +The `getL2NFTsInCollection` function is a view function provided by the `ISCAccounts` interface. It takes two parameters: an `ISCAgentID` representing the owner of the NFTs, and an `NFTID` representing the collection. It returns an array of `NFTID` objects, representing the NFTs in the specified collection owned by the agent. + +## Why Retrieve NFTs in a Collection? + +Retrieving the NFTs in a collection can serve several purposes: + +- ### Portfolio Management: + + - Helps users manage their NFT collections effectively. + +- ### Market Analysis: + + - Enables users to analyze the contents of their collections for trading or valuation purposes. + +- ### Display Collections: + + - Users can display specific collections on platforms or personal galleries. + +- ### Organization: + + - Helps in organizing NFTs into different categories or collections for better accessibility and management. + +## Prerequisites + +### 1. Install the ISC Magic Library: + +Ensure you have the ISC Magic library installed in your project. + +```bash +npm install @iota/iscmagic +``` + +### 2. Import the ISCAccounts Interface: + +In your Solidity file, import the ISCAccounts interface. + +```Solidity +pragma solidity >=0.8.24; + +import "@iota/iscmagic/ISCAccounts.sol"; +// Import the ISCTypes where ISCAgentID and NFTID are defined +import "@iota/iscmagic/ISCTypes.sol"; +``` + +## Implement the `getL2NFTsInCollection` Function + +Here’s a sample implementation to retrieve L2 NFTs within a specific collection owned by an account: + +```solidity +function getNFTsInCollection(bytes memory agentData, NFTID memory collectionId) public view returns (NFTID[] memory) { + // Create the ISCAgentID object + ISCAgentID memory agentID = ISCAgentID({ + data: agentData + }); + // Call the getL2NFTsInCollection function from the ISCAccounts contract + NFTID[] memory nftsInCollection = ISC.accounts.getL2NFTsInCollection(agentID, collectionId); + + return nftsInCollection; +} +``` + +## Full Example Contract + +```solidity +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.24; + +import "@iota/iscmagic/ISCAccounts.sol"; +import "@iota/iscmagic/ISCTypes.sol"; + +contract MyNFTContract { + +function getNFTsInCollection(bytes memory agentData, NFTID memory collectionId) public view returns (NFTID[] memory) { + // Create the ISCAgentID object + ISCAgentID memory agentID = ISCAgentID({ + data: agentData + }); + // Call the getL2NFTsInCollection function from the ISCAccounts contract + NFTID[] memory nftsInCollection = ISC.accounts.getL2NFTsInCollection(agentID, collectionId); + + return nftsInCollection; + } +} +``` + +## Conclusion + +Using the `getL2NFTsInCollection` function from the `ISCAccounts` interface provides an efficient way to retrieve and manage NFTs within a specific collection owned by an account. By integrating this functionality into your smart contracts, you can enhance user experience by enabling features such as [portfolio management](#portfolio-management), [market analysis](#market-analysis), and [display collections](#display-collections). With this guide, you now have the foundational knowledge to implement and utilize the `getL2NFTsInCollection` function in your own projects, allowing for seamless interaction with `ISC` Magic and its associated NFTs. \ 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 675779b89b5..b3072e4b5bc 100644 --- a/docs/build/isc/v1.3/sidebars.js +++ b/docs/build/isc/v1.3/sidebars.js @@ -215,6 +215,11 @@ module.exports = { label: 'Get NFT Metadata', id: 'how-tos/core-contracts/nft/get-nft-metadata', }, + { + type: 'doc', + label: 'Get NFTs in Collection', + id: 'how-tos/core-contracts/nft/get-nft-in-collection', + }, ], }, {