Skip to content

Commit

Permalink
feat(wiki): duplicate on v1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Ginowine committed Jun 27, 2024
1 parent e3f1531 commit 5991689
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 0 deletions.
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.
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 @@ -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',
},
],
},
{
Expand Down

0 comments on commit 5991689

Please sign in to comment.