Skip to content

Commit

Permalink
Guide to get NFTs Owned by an Account
Browse files Browse the repository at this point in the history
  • Loading branch information
Ginowine authored Jul 5, 2024
1 parent f9fb64d commit 8ed59c5
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 0 deletions.
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

0 comments on commit 8ed59c5

Please sign in to comment.