Comprehensive JavaScript SDK for building Solana blockchain applications with modern architecture and type safety
93
Evaluation — 93%
↑ 1.29xAgent success when using this tile
Build a transaction builder that constructs Solana transactions with multiple program instructions.
Solana transactions can contain multiple instructions that are executed atomically. Each instruction includes:
Implement a module that creates a transaction with three instructions that will:
The module should:
buildMultiInstructionTransaction(params) that takes:
sourceKeypair: The keypair that will sign and pay for the transactiondestination1: Public key of the first transfer recipientdestination2: Public key of the second transfer recipientnewAccountKeypair: Keypair for the new account to be createdprogramId: Public key of the program that will own the new accountrecentBlockhash: A recent blockhash to use for the transactionTest File: transaction-builder.test.js
const { buildMultiInstructionTransaction } = require('./transaction-builder');
const { Keypair, PublicKey } = require('@solana/web3.js');
const source = Keypair.generate();
const dest1 = Keypair.generate().publicKey;
const dest2 = Keypair.generate().publicKey;
const newAccount = Keypair.generate();
const programId = Keypair.generate().publicKey;
const blockhash = 'EkSnNWid2cvwEVnVx9aBqawnmiCNiDgp3gUdkDPTKN1N';
const tx = buildMultiInstructionTransaction({
sourceKeypair: source,
destination1: dest1,
destination2: dest2,
newAccountKeypair: newAccount,
programId: programId,
recentBlockhash: blockhash
});
console.assert(tx.instructions.length === 3, 'Transaction should have 3 instructions');
console.assert(tx.recentBlockhash === blockhash, 'Transaction should have correct blockhash');
console.log('Test Case 1: PASSED');Expected Output:
Test Case 1: PASSEDTest File: transaction-builder.test.js
const { buildMultiInstructionTransaction } = require('./transaction-builder');
const { Keypair, PublicKey, SystemProgram } = require('@solana/web3.js');
const source = Keypair.generate();
const dest1 = Keypair.generate().publicKey;
const dest2 = Keypair.generate().publicKey;
const newAccount = Keypair.generate();
const programId = Keypair.generate().publicKey;
const blockhash = 'EkSnNWid2cvwEVnVx9aBqawnmiCNiDgp3gUdkDPTKN1N';
const tx = buildMultiInstructionTransaction({
sourceKeypair: source,
destination1: dest1,
destination2: dest2,
newAccountKeypair: newAccount,
programId: programId,
recentBlockhash: blockhash
});
// First two instructions should be transfers to SystemProgram
console.assert(
tx.instructions[0].programId.equals(SystemProgram.programId),
'First instruction should target SystemProgram'
);
console.assert(
tx.instructions[1].programId.equals(SystemProgram.programId),
'Second instruction should target SystemProgram'
);
console.assert(
tx.instructions[2].programId.equals(SystemProgram.programId),
'Third instruction should target SystemProgram for account creation'
);
console.log('Test Case 2: PASSED');Expected Output:
Test Case 2: PASSEDProvides Solana blockchain interaction capabilities including transaction construction, instruction creation, and account management.
Install with Tessl CLI
npx tessl i tessl/npm-solana--web3-jsdocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10