1

I have the following code now and it works fine. However, it can only mint 1 NFT per time.

        await transactionBuilder()
          .add(setComputeUnitLimit(umi, { units: 800_000 }))
          .add(
            mintV2(umi, {
              candyMachine: candyMachine.publicKey,
              nftMint,
              collectionMint: publicKey(candyMachine.collectionMint),
              collectionUpdateAuthority: publicKey(candyMachine.authority),
              group: some(this.currentStageLabel),
              tokenStandard: candyMachine.tokenStandard,
              candyGuard: publicKey(candyMachine.mintAuthority),
              minter: umi.identity,
              mintArgs: {
                mintLimit: some({ id: this.nftMaxLimitId }),
                solPayment: some({ destination: publicKey(this.treasury) }),
                allowList: some({ merkleRoot: getMerkleRoot(allowList) }),
              },
            })
          )
          .sendAndConfirm(umi).then(({ signature }) => {
            console.log("Signature: ", signature);
            sig = signature;
          });

How do I mint more than 1 NFT at a time without adding another mintV2 instruction?

Thanks!

1 Answer 1

2

I don't think this is possible.

You'll need to use a loop and make sure you aren't spamming the RPC and exceeding the set RPC rate limits.

Alternatively, you can try putting multiple mint IXs in one transaction but because of the 1232 size limit, the no of instructions you can load is limited. In my testing, using the core program the maximum you can mint is 5 before hitting the tx size limit. Not sure what that number will look like for the old TM program but it'll be lower than this number.

async function tryMintMultiple() {
    let instructions: TransactionInstruction[] = [];
    let assetSigs: Uint8Array[] = [];

    for (let i = 0; i < 4; i++) { // adjust the max to see how many mint ix you can fit in one tx
        const nftMint = generateSigner(umi);

        let mintTxBuilder = await transactionBuilder()
            .add(setComputeUnitLimit(umi, { units: 800_000 }))
            .add(
                mintV2(umi, {
                    candyMachine: candyMachine.publicKey,
                    nftMint,
                    collectionMint: publicKey(candyMachine.collectionMint),
                    collectionUpdateAuthority: publicKey(
                        candyMachine.authority
                    ),
                    group: some(this.currentStageLabel),
                    tokenStandard: candyMachine.tokenStandard,
                    candyGuard: publicKey(candyMachine.mintAuthority),
                    minter: umi.identity,
                    mintArgs: {
                        mintLimit: some({ id: this.nftMaxLimitId }),
                        solPayment: some({
                            destination: publicKey(this.treasury),
                        }),
                        allowList: some({
                            merkleRoot: getMerkleRoot(allowList),
                        }),
                    },
                })
            )
            .buildWithLatestBlockhash(umi);

        let mintAssetIx = TransactionMessage.decompile(
            toWeb3JsMessage(mintTxBuilder.message)
        ).instructions;

        instructions.push(...mintAssetIx);
        assetSigs.push(nftMint.secretKey);
    }

    const messageV0 = new TransactionMessage({
        payerKey: new web3PublicKey(umi.identity.publicKey),
        recentBlockhash: (await umi.rpc.getLatestBlockhash()).blockhash,
        instructions: [...instructions],
    }).compileToV0Message();
    const tx = new VersionedTransaction(messageV0);

    assetSigs.forEach((secret) => tx.sign([Keypair.fromSecretKey(secret)]));
    tx.sign(["YOU UINT KEYPAIR GOES HERE"]); // sign with your keypair

    const txId = await connection.sendTransaction(tx);
    console.log(`https://explorer.solana.com/tx/${txId}?cluster=devnet`);
}
1
  • Thank you! Let me try that out first. The current project limits only 2 NFTs per guard group. Perhaps it won't exceed the 1232 size limit. I will try both the loop and the 3-instructioned solutions.
    – darksun113
    Commented Jul 30 at 1:51

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.