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
] function from the [ISCAccounts
]magic contract.
Mint an NFT
Mint your first NFT following our how to mint an NFT guide.
Implement the getL2NFTsInCollection
Function
Here’s a sample implementation to retrieve L2 NFTs within a specific collection owned by an account:
function getNFTsInCollection(NFTID memory collectionId) public view returns (NFTID[] memory) {
// Get the ISCAgentID
ISCAgentID memory agentID = ISC.sandbox.getSenderAccount();
// Call the getL2NFTsInCollection function from the ISCAccounts contract
NFTID[] memory nftsInCollection = ISC.accounts.getL2NFTsInCollection(agentID, collectionId);
return nftsInCollection;
}