I need to fetch all printed editions that were created from a master NFT on Solana. The documentation mentions there’s a Program Derived Address (PDA) that connects editions back to their master, but I can’t figure out how to use this relationship with the Solana/Metaplex SDK.
Right now I’m using a workaround where I go through all transactions on the master NFT and look for edition creation events:
import {JsonMetadata, Metadata, Metaplex, TaskStatus} from "@metaplex-foundation/js";
import {Connection, PublicKey, ConfirmedSignatureInfo} from "@solana/web3.js";
import * as fs from "fs";
const ENDPOINT = 'https://...';
const MASTER_NFT_KEY = '';
(async () => {
const conn = new Connection(ENDPOINT);
const mx = new Metaplex(conn);
const timestamp = new Date().toISOString()
// Get all transaction signatures
const txSignatures: { signature: string; }[] = []
let beforeSig: string | undefined = undefined;
while (true) {
const results: ConfirmedSignatureInfo[] = await mx.connection.getSignaturesForAddress(
new PublicKey(MASTER_NFT_KEY),
{
before: beforeSig
},
'finalized'
)
if (!results.length) break
txSignatures.push(...results)
beforeSig = results[results.length - 1].signature
}
// Check each transaction for edition creation
const editionMints: string[] = []
for (let j = 0; j < txSignatures.length; j++) {
console.log(`${j}/${txSignatures.length}`);
await mx.connection.getParsedTransaction(txSignatures[j].signature).then(transaction => {
if (!transaction) return
if (JSON.stringify(transaction).toLowerCase().includes('error')) return
if (JSON.stringify(transaction).includes('Mint New Edition from Master Edition')) {
console.log(JSON.stringify(transaction, null, 4))
editionMints.push(transaction.transaction.message.accountKeys[1].pubkey.toString());
}
});
}
console.log('discovered:', editionMints.length, 'editions')
})()
This method gets really slow when there are lots of transactions. Is there a better way to do this?
Note: The first creator isn’t unique since it’s not from a Candy Machine, and the update authority might be shared across collections.