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

Guide to get NFTs Owned by an Account #1631

Merged
merged 8 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions docs/build/isc/v1.1/docs/_admonitions/_AgentID.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
:::info ISC Agent ID

The `ISCAgentID` represents the identifier of the agent (user or contract) whose NFTs you want to retrieve. You can get the [`AgentID`](../explanations/how-accounts-work.md) from the sender by calling `ISC.sandbox.getSenderAccount()`.

:::
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
description: How to get the L2 NFTs owned by an account.
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';
import ISCAgentID from '../../../_admonitions/_AgentID.md';

# Get NFTs Owned by an Account

This guide will show you how to get the L2 NFTs owned by an account using the [`ISCAccounts.getL2NFTs`](../../../reference/magic-contract/ISCAccounts.md#getl2nfts) function from the [`ISCAccounts`](../../../reference/magic-contract/ISCAccounts.md) [magic contract](../../../reference/magic-contract/introduction.md).
<GetNftMetadata/>

## Understanding the `getL2NFTs` Function

The `getL2NFTs` function is a view function provided by the `ISCAccounts` interface. It takes an `ISCAgentID` as an argument and returns an array of `NFTID` objects. This function allows users to query and retrieve the list of L2 NFTs owned by a specified agent.
<ISCAgentID/>

The returned array contains the identifiers of the NFTs, which can then be used to fetch more details about each NFT if needed.

## Implement the `getL2NFTs` Function

Here’s a sample implementation to retrieve L2 NFTs owned by an account:

```solidity
function getOwnedNFTs(ISCAgentID memory agentID) public view returns (NFTID[] memory) {
// Call the getL2NFTs function from the ISCAccounts contract
NFTID[] memory ownedNFTs = ISC.accounts.getL2NFTs(agenID);
return ownedNFTs;
}
```

## Full Example Contract

```solidity
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.24;

import "@iota/iscmagic/ISC.sol";

contract MyNFTContract {

function getOwnedNFTs(ISCAgentID memory agentID) public view returns (NFTID[] memory) {
// Call the getL2NFTs function from the ISCAccounts contract
NFTID[] memory ownedNFTs = ISC.accounts.getL2NFTs(agenID);
return ownedNFTs;
}
}
```
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 @@ -215,6 +215,11 @@ module.exports = {
label: 'Get NFT Metadata',
id: 'how-tos/core-contracts/nft/get-nft-metadata',
},
{
type: 'doc',
label: 'Get NFTs Owned by an Account',
id: 'how-tos/core-contracts/nft/get-L2-nfts',
},
],
},
{
Expand Down
5 changes: 5 additions & 0 deletions docs/build/isc/v1.3/docs/_admonitions/_AgentID.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
:::info ISC Agent ID

The `ISCAgentID` represents the identifier of the agent (user or contract) whose NFTs you want to retrieve. You can get the [`AgentID`](../explanations/how-accounts-work.md) from the sender by calling `ISC.sandbox.getSenderAccount()`.

:::
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
description: How to get the L2 NFTs owned by an account.
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';
import ISCAgentID from '../../../_admonitions/_AgentID.md';

# Get NFTs Owned by an Account

This guide will show you how to get the L2 NFTs owned by an account using the [`ISCAccounts.getL2NFTs`](../../../reference/magic-contract/ISCAccounts.md#getl2nfts) function from the [`ISCAccounts`](../../../reference/magic-contract/ISCAccounts.md) [magic contract](../../../reference/magic-contract/introduction.md).
<GetNftMetadata/>

## Understanding the `getL2NFTs` Function

The `getL2NFTs` function is a view function provided by the `ISCAccounts` interface. It takes an `ISCAgentID` as an argument and returns an array of `NFTID` objects. This function allows users to query and retrieve the list of L2 NFTs owned by a specified agent.
<ISCAgentID/>

The returned array contains the identifiers of the NFTs, which can then be used to fetch more details about each NFT if needed.

## Implement the `getL2NFTs` Function

Here’s a sample implementation to retrieve L2 NFTs owned by an account:

```solidity
function getOwnedNFTs(ISCAgentID memory agentID) public view returns (NFTID[] memory) {
// Call the getL2NFTs function from the ISCAccounts contract
NFTID[] memory ownedNFTs = ISC.accounts.getL2NFTs(agenID);
return ownedNFTs;
}
```

## Full Example Contract

```solidity
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.24;

import "@iota/iscmagic/ISC.sol";

contract MyNFTContract {

function getOwnedNFTs(ISCAgentID memory agentID) public view returns (NFTID[] memory) {
// Call the getL2NFTs function from the ISCAccounts contract
NFTID[] memory ownedNFTs = ISC.accounts.getL2NFTs(agenID);
return ownedNFTs;
}
}
```
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 Owned by an Account',
id: 'how-tos/core-contracts/nft/get-L2-nfts',
},
],
},
{
Expand Down
Loading