diff --git a/challenge/index.ts b/challenge/index.ts index 73e28a5..cd101f6 100644 --- a/challenge/index.ts +++ b/challenge/index.ts @@ -1,4 +1,4 @@ -import algosdk from "algosdk"; +import algosdk from "algosdk"; import * as algokit from '@algorandfoundation/algokit-utils'; const algodClient = algokit.getAlgoClient() @@ -10,30 +10,25 @@ const receiver = await algokit.mnemonicAccountFromEnvironment( algodClient, ) -/* -TODO: edit code below - -Puzzle: -The below code is trying to send a payment from accounts[0] to accounts[1]. -However, the code is not working. fix the code so that the payment is sent -successfully. - -When solved correctly, the console should print out the following: -"Payment of 1000000 microAlgos was sent to RRYKB23LFR62G3P4SFINZDQ4FVDUNWWQ4NOF7K6TP5GO65BQCHYMNTR3CU at confirmed round 59" -*/ const suggestedParams = await algodClient.getTransactionParams().do(); const txn = algosdk.makePaymentTxnWithSuggestedParamsFromObject({ from: sender.addr, suggestedParams, to: receiver.addr, - amount: 1000000, + amount: 1000000, // amount is in microAlgos }); -await algodClient.sendRawTransaction(txn).do(); +// Sign the transaction with sender's secret key +const signedTxn = txn.signTxn(sender.sk); + +// Send the signed transaction (raw transaction bytes) +await algodClient.sendRawTransaction(signedTxn).do(); + +// Wait for confirmation const result = await algosdk.waitForConfirmation( algodClient, txn.txID().toString(), - 3 + 3 // number of rounds to wait ); -console.log(`Payment of ${result.txn.txn.amt} microAlgos was sent to ${receiver.addr} at confirmed round ${result['confirmed-round']}`); \ No newline at end of file +console.log(`Payment of ${result.txn.txn.amt} microAlgos was sent to ${receiver.addr} at confirmed round ${result['confirmed-round']}`);