Quantcast
Channel: Recent Questions - Solana Stack Exchange
Viewing all articles
Browse latest Browse all 7925

How to remove duplicate instructions

$
0
0

I have the following code snippet to generate mint instructions and add them to a transactions

    let instructions: TransactionInstruction[] = [];    let assets: KeypairSigner[] = [];    for (let i = 0; i < 5; i++) {        const asset = generateSigner(umi);        console.log("le asset", asset.publicKey);        let mintIXs = await transactionBuilder()            .add(setComputeUnitLimit(umi, { units: 90_000 }))            .add(                MintV1CoreAsset(umi, {                    candyMachine: UMIPublicKey(candyMachine),                    asset,                    collection: UMIPublicKey(collection),                    mintArgs: {                        solPayment: some({                            destination: UMIPublicKey(treasury),                        }),                    },                })            )            .getInstructions();        mintIXs.forEach((ix) => instructions.push(toWeb3JsInstruction(ix)));        assets.push(asset);    }    const messageV0 = new TransactionMessage({        payerKey: new web3PublicKey(umi.identity.publicKey),        recentBlockhash: (await umi.rpc.getLatestBlockhash()).blockhash,        instructions: [...instructions],    }).compileToV0Message([]);    const tx = new VersionedTransaction(messageV0);    assets.forEach((asset) =>        tx.sign([Keypair.fromSecretKey(asset.secretKey)])    );    tx.sign([me]);    await connection.sendTransaction(tx, {});

Unfortunately, this transaction cannot be send because of the duplicate compute budget instructions, returning with the error

SendTransactionError: failed to send transaction: Transaction simulation failed: Transaction contains a duplicate instruction (2) that is not allowed    at Connection.sendEncodedTransaction (/home/jimii/Documents/webcode/test-umi/node_modules/@solana/web3.js/src/connection.ts:5923:13)    at processTicksAndRejections (node:internal/process/task_queues:95:5)    at async Connection.sendRawTransaction (/home/jimii/Documents/webcode/test-umi/node_modules/@solana/web3.js/src/connection.ts:5880:20)    at async Connection.sendTransaction (/home/jimii/Documents/webcode/test-umi/node_modules/@solana/web3.js/src/connection.ts:5829:14)    at async mintFromCoreCM (/home/jimii/Documents/webcode/test-umi/src/core-cm.ts:306:2) {  logs: []}

My questions are:

  1. Aren't transaction instructions deduplicated of similar instruction or am I wrong?
  2. Is there another way of removing duplicate instructions without removing the duplicate instruction manually?

Viewing all articles
Browse latest Browse all 7925

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>