I'm trying to get all the editions that come from a master edition NFT. According to the docs there is a PDA that links the edition back to the master edition but I can't find this relationship programatically with the Metaplex/Solana sdk.
My current solution is to parse all the transactions of the master edition and filter through looking for editions created:
import {JsonMetadata, Metadata, Metaplex, TaskStatus} from "@metaplex-foundation/js";
import {Connection, PublicKey, ConfirmedSignatureInfo} from "@solana/web3.js";
import * as fs from "fs";
const RPC_URL = 'https://...';
const MASTER_EDITION_ADDRESS = '';
(async () => {
const connection = new Connection(RPC_URL);
const metaplex = new Metaplex(connection);
const start = new Date().toISOString()
// Paginate transactions from Master Edition
const signatures: { signature: string; }[] = []
let before: string | undefined = undefined;
while (true) {
const sigs: ConfirmedSignatureInfo[] = await metaplex.connection.getSignaturesForAddress(
new PublicKey(MASTER_EDITION_ADDRESS),
{
before: before
},
'finalized'
)
if (!sigs.length) break
signatures.push(...sigs)
before = sigs[sigs.length - 1].signature
}
// Parse Transactions and find new edition mints
const hashlist: string[] = []
for (let i = 0; i < signatures.length; i++) {
console.log(`${i}/${signatures.length}`);
await metaplex.connection.getParsedTransaction(signatures[i].signature).then(tx => {
if (!tx) return
if (JSON.stringify(tx).toLowerCase().includes('error')) return
if (JSON.stringify(tx).includes('Mint New Edition from Master Edition')) {
console.log(JSON.stringify(tx, null, 4))
hashlist.push(tx.transaction.message.accountKeys[1].pubkey.toString());
}
});
}
console.log('found:', hashlist.length, 'items')
})()
However this becomes exponentially slow once the transactions are at a certain size. Is there a fast and reliable way to do this.
Assumptions:
- The first creator is not unique to this collection as its not a Candy Machine
- The update authority is not unique as it could be used by other collections too