Skip to content

Instantly share code, notes, and snippets.

@sunguru98
Last active December 19, 2021 22:26
Show Gist options
  • Save sunguru98/969f0b4543d37c9ee2d714f222e00589 to your computer and use it in GitHub Desktop.
Save sunguru98/969f0b4543d37c9ee2d714f222e00589 to your computer and use it in GitHub Desktop.
Get a Mint list based on a Candy machine Address
import { Metadata } from '@metaplex-foundation/mpl-token-metadata';
import { writeJSON } from 'fs-extra';
import { PublicKey } from '@solana/web3.js';
import { PROGRAMS, SOLANA_CONNECTION } from '../constants';
(async function () {
const CANDY_MACHINE_ACCOUNT_KEY = new PublicKey(
'Bi9A9brhkTXRMwq9aBimNZNefLkcMFHobtkwqBjTeqc5'
);
const res = await SOLANA_CONNECTION.getParsedProgramAccounts(
PROGRAMS['metadata'],
{
filters: [
{
memcmp: {
offset: 1 + 32 + 32 + 4 + 32 + 4 + 200 + 4 + 10 + 2 + 1 + 4,
bytes: CANDY_MACHINE_ACCOUNT_KEY.toBase58(),
},
},
],
}
);
const mintList = (
await Promise.all(
res.map(async (indRes) => Metadata.load(SOLANA_CONNECTION, indRes.pubkey))
)
)
.filter((metadata) =>
metadata.data.data.creators?.find(
(c) => c.address === CANDY_MACHINE_ACCOUNT_KEY.toString() && c.verified
)
)
.map((metadata) => metadata.data.mint);
await writeJSON(
`${__dirname}/../mints/${CANDY_MACHINE_ACCOUNT_KEY}-mints.json`,
mintList,
{ spaces: 2 }
);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment