Skip to content
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
37 changes: 21 additions & 16 deletions challenge/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import algosdk from "algosdk";
import * as algokit from '@algorandfoundation/algokit-utils';
import algosdk from "algosdk";
import * as algokit from "@algorandfoundation/algokit-utils";

const algodClient = algokit.getAlgoClient()
const algodClient = algokit.getAlgoClient();

// Retrieve 2 accounts from localnet kmd
const sender = await algokit.getLocalNetDispenserAccount(algodClient)
const sender = await algokit.getLocalNetDispenserAccount(algodClient);
const receiver = await algokit.mnemonicAccountFromEnvironment(
{name: 'RECEIVER', fundWith: algokit.algos(100)},
algodClient,
)
{ name: "RECEIVER", fundWith: algokit.algos(100) },
algodClient
);

/*
TODO: edit code below
Expand All @@ -23,17 +23,22 @@ When solved correctly, the console should print out the following:
*/
const suggestedParams = await algodClient.getTransactionParams().do();
const txn = algosdk.makePaymentTxnWithSuggestedParamsFromObject({
from: sender.addr,
suggestedParams,
to: receiver.addr,
amount: 1000000,
from: sender.addr,
suggestedParams,
to: receiver.addr,
amount: 1000000,
});

await algodClient.sendRawTransaction(txn).do();
// transaction is not yet signed, signing it with sender's sk
const signedTxn = txn.signTxn(sender.sk);

await algodClient.sendRawTransaction(signedTxn).do();
const result = await algosdk.waitForConfirmation(
algodClient,
txn.txID().toString(),
3
algodClient,
txn.txID().toString(),
3
);

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"]}`
);