Skip to main content
Superteam Brasil
Back
+10 XP
12/12

Challenge: Build a Custom Instruction

Construct a custom Solana instruction that could be used to interact with a program. You'll define the program ID, the accounts involved, and the instruction data.

Requirements

  • Create a function that accepts programId (PublicKey), payer (PublicKey), dataAccount (PublicKey), and amount (number)
  • Return an instruction object with:
    • programId: the program to call
    • keys: an array of AccountMeta objects (payer as signer + writable, dataAccount as writable)
    • data: a Uint8Array containing the amount encoded as 8 bytes (little-endian u64)
  • Use DataView to encode the amount as a little-endian 64-bit unsigned integer

Test Cases

Should return object with programId, keys array, and data Uint8Array
Input: programId, sender, recipient, 1000Expected: result.programId && Array.isArray(result.keys) && result.data instanceof Uint8Array
First key should be a signer
Input: programId, sender, recipient, 1000Expected: result.keys.length >= 2 && result.keys[0].isSigner === true

Discussion