-
Notifications
You must be signed in to change notification settings - Fork 290
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
108 changes: 108 additions & 0 deletions
108
docs/build/isc/v1.3/docs/how-tos/core-contracts/nft/get-nft-in-collection.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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). | ||
|
||
<GetNftMetadata /> | ||
|
||
## 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters