Retrieving all prints from a master NFT edition on Solana

I’m working on a Solana project and need help finding all the prints that come from a master NFT edition. The docs mention a PDA linking prints to the master, but I can’t figure out how to use it with the Metaplex or Solana SDK.

Right now, I’m going through all the master edition’s transactions and looking for new print creations. It works, but it’s super slow when there are lots of transactions.

const metaplex = new Metaplex(connection);
let allSigs = [];
let lastSig;

while (true) {
  const newSigs = await metaplex.connection.getSignaturesForAddress(
    masterEditionPubkey,
    { before: lastSig }
  );
  if (newSigs.length === 0) break;
  allSigs.push(...newSigs);
  lastSig = newSigs[newSigs.length - 1].signature;
}

const printList = [];
for (const sig of allSigs) {
  const tx = await metaplex.connection.getParsedTransaction(sig.signature);
  if (tx && tx.meta.logMessages.includes('Mint New Print')) {
    printList.push(tx.transaction.message.accountKeys[1].toString());
  }
}

Is there a faster way to do this? The first creator and update authority aren’t unique to this collection, so I can’t use those to filter.

yo creativePainter45, Ben_Comics’ idea is solid but there’s another trick. try using the getAssetsByGroup function from @metaplex-foundation/mpl-token-metadata. it lets you grab all assets tied to a master edition in one go. way faster than looping thru transactions.

smthn like:

const prints = await metaplex.nfts().getAssetsByGroup({
  groupKey: masterEditionPubkey,
  groupValue: 'edition',
});

lmk if that helps speed things up for ya!

I’ve encountered a similar issue in my Solana projects. While the suggestions from Ray84 and Ben_Comics are valid, there’s another approach worth considering. You can utilize the getProgramAccounts method from the Solana web3.js library to fetch all accounts associated with the Master Edition.

Here’s a sample implementation:

const { PublicKey } = require('@solana/web3.js');
const TOKEN_METADATA_PROGRAM_ID = new PublicKey('metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s');

const accounts = await connection.getProgramAccounts(TOKEN_METADATA_PROGRAM_ID, {
  filters: [
    { memcmp: { offset: 0, bytes: masterEditionPubkey.toBase58() } },
    { dataSize: 282 } // Size of Edition account data
  ]
});

const prints = accounts.map(account => account.pubkey);

This method is efficient and doesn’t require iterating through transactions. It directly queries the program for relevant accounts, significantly reducing processing time.

hey there creativePainter45! :wave:

i totally get your frustration with that slow method. been there, done that! :sweat_smile: have you considered using the getEditionPda function from @metaplex-foundation/js? it might be a game-changer for you.

something like this could work:

const editionPda = findEditionPda(masterEditionMint);
const editionAcct = await metaplex.nfts().findEditionAccount(editionPda);
const printEditions = editionAcct.supply;

this should give you the total number of prints. then you could use that to fetch the actual prints:

const prints = [];
for (let i = 1; i <= printEditions; i++) {
  const printPda = findEditionPda(masterEditionMint, i);
  prints.push(printPda);
}

what do you think? could this work for your project? i’m really curious to hear more about what you’re building with these nft prints! :art: