Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix transaction signing issue in payment process #112

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 11 additions & 16 deletions challenge/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import algosdk from "algosdk";
import algosdk from "algosdk";
import * as algokit from '@algorandfoundation/algokit-utils';

const algodClient = algokit.getAlgoClient()
Expand All @@ -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']}`);
console.log(`Payment of ${result.txn.txn.amt} microAlgos was sent to ${receiver.addr} at confirmed round ${result['confirmed-round']}`);