Back
+10 XP
6/12
Challenge: Build a Transfer Function
Create a function that builds a SOL transfer transaction. The function should take a sender public key, recipient public key, and amount in SOL, then return the transaction object ready to be signed.
Requirements
- Accept sender (PublicKey), recipient (PublicKey), and amount (number, in SOL)
- Convert SOL amount to lamports
- Create and return a Transaction with a SystemProgram.transfer instruction
Test Cases
Returns a Transaction
Input:
sender, recipient, 1.0Expected: result instanceof TransactionContains exactly one instruction
Input:
sender, recipient, 1.0Expected: result.instructions.length === 1Converts SOL to the correct lamports amount
Input:
sender, recipient, 1.0Expected: result.instructions[0].lamports === 1000000000