On Solana, we can obtain all tokens owned by a public key thanks to that method:
connection
.getParsedTokenAccountsByOwner(
new PublicKey(publicKey.toBase58()),
{
programId: TOKEN_PROGRAM_ID
}
)
.then((b) => {
const owner = b?.value?.[0].account.owner;
const pb = b?.value?.[0].pubkey;
const nonZeroAccounts = b?.value?.filter(
(obj) => obj.account.data.parsed.info.tokenAmount.uiAmount > 0
);
setTokens(JSON.stringify(nonZeroAccounts, null, 2));
and we can retrieve the metadata of that token using this:
import * as metadata from "@metaplex-foundation/mpl-token-metadata";
const nftsmetadata:metadata.MetadataData[] = await metadata.Metadata.findDataByOwner(connection, publicKey);
But before we can access this metadata, the token need to be minted. Is there a way to retrieve all the metadata (minted NFTs and unminted NFTs) of a collection using the CandyMachine ID or Token Metadata Program?
Replacing
ENTER_YOUR_CANDY_MACHINE_ID_HERE
with the candy machine you want info from, this will get all the mints associated.