From 9ea8194f74ba95215549cccdb7a1c4c4106f8529 Mon Sep 17 00:00:00 2001 From: sarahwoods89 <147245059+sarahwoods89@users.noreply.github.com> Date: Wed, 29 May 2024 13:36:17 +0100 Subject: [PATCH] made changes to index and json and hoefully pushing them to github --- challenge/package.json | 6 +++++- index.ts | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 index.ts diff --git a/challenge/package.json b/challenge/package.json index bb407b8..07615e1 100644 --- a/challenge/package.json +++ b/challenge/package.json @@ -1,7 +1,8 @@ { "name": "algorand-puzzle-1", + "version": "1.0.0", "scripts": { - "start": "tsx -r dotenv/config index.ts" + "start": "tsx -r dotenv/config challenge/index.ts" }, "module": "index.ts", "type": "module", @@ -15,3 +16,6 @@ "tsx": "^4.7.0" } } + + + diff --git a/index.ts b/index.ts new file mode 100644 index 0000000..c2b8aa7 --- /dev/null +++ b/index.ts @@ -0,0 +1,33 @@ +import algosdk from "algosdk"; +import * as algokit from "@algorandfoundation/algokit-utils"; + +async function main() { + const algodClient = algokit.getAlgoClient(); + + // Retrieve 2 accounts from localnet kmd + const sender = await algokit.getLocalNetDispenserAccount(algodClient); + const receiver = await algokit.mnemonicAccountFromEnvironment( + { name: "RECEIVER", fundWith: algokit.algos(100) }, + algodClient + ); + + const suggestedParams = await algodClient.getTransactionParams().do(); + const txn = algosdk.makePaymentTxnWithSuggestedParamsFromObject({ + from: sender.addr, + suggestedParams, + to: receiver.addr, + amount: 1000000, + }); + + const signedTxn = txn.signTxn(sender.sk); + const { txId } = await algodClient.sendRawTransaction(signedTxn).do(); + const result = await algosdk.waitForConfirmation(algodClient, txId, 3); + + console.log( + `Payment of ${result.txn.txn.amt} microAlgos was sent to ${receiver.addr} at confirmed round ${result["confirmed-round"]}` + ); +} + +main().catch((error) => { + console.error("Error in main function:", error); +}); \ No newline at end of file