2

Currently, the following call will return nft metadata that contains uri.

export async function fetchAsset(
  context: Pick<Context, 'eddsa' | 'programs' | 'rpc'>,
  mint: PublicKey,
): Promise<Asset | undefined> {
  const metadata = findMetadataPda(context, { mint });
  const edition = findMasterEditionPda(context, { mint });

  const [mintAccount, metadataAccount, editionAccount] =
    (await context.rpc.getAccounts([mint, metadata[0], edition[0]])) as [
      MaybeRpcAccount,
      MaybeRpcAccount,
      MaybeRpcAccount,
    ];

  if (!metadataAccount.exists) {
    return;
  }

  assertAccountExists(mintAccount, 'Mint');

  const mintData = deserializeMint(mintAccount);
  const metadataData = deserializeMetadata(metadataAccount);

  let editionData: Edition | undefined;

  // Check if the asset is an NFT.
  if (
    editionAccount.exists &&
    unwrapOption(mintData.mintAuthority) == editionAccount.publicKey
  ) {
    editionData = deserializeEdition(editionAccount);
  }

  return {
    publicKey: mint,
    mint: mintData,
    metadata: metadataData,
    edition: editionData,
  };
}

Is there a way to fetch all the nft images in the same call instead of using the uri one by one?

1 Answer 1

3

you can use the DAS api from triton, helius or metaplex for example. Here are the helius docs for it: https://docs.helius.dev/compression-and-das-api/digital-asset-standard-das-api

This is how you can load up to 1000 nfts at once:

async function getAssetsByOwner(ownerAddress: PublicKey) {
    const sortBy = {
      sortBy: "created",
      sortDirection: "asc",
    };
    const limit = 1000;
    const page = 1;
    const before = "";
    const after = "";
    const allAssetsOwned = await CONNECTION.getAssetsByOwner(
      ownerAddress.toBase58(),
      sortBy,
      limit,
      page,
      before,
      after
    );

    setNftState(allAssetsOwned);
    console.log(allAssetsOwned);
  }

Here is a react example of it: https://github.com/solana-developers/solana_game_preset/blob/main/app/contexts/NftProvider.tsx

2
  • Is there a way to get Helius to return the programmableConfig as well?
    – Hyetigran
    Commented Jan 9 at 19:06
  • I dont know. Best check their docs or their discord.
    – Jonas H.
    Commented Jan 9 at 19:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.