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

const algodClient = algokit.getAlgoClient()
const algodToken = 'a'.repeat(64);
const algodServer = 'http://localhost';
const algodPort = 4001;

const algodClient = new algosdk.Algodv2(algodToken, algodServer, algodPort);

// 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,);

let acctInfS = await algodClient.accountInformation(sender.addr).do();
let acctInfR = await algodClient.accountInformation(receiver.addr).do();
console.log(`Sender Address: ${sender.addr}\nBalance: ${acctInfS.amount/1000000}`);
console.log(`Receiver Address: ${receiver.addr}\nBalance: ${acctInfR.amount/1000000}`);

/*
TODO: edit code below
Expand All @@ -21,19 +28,30 @@ 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,
suggestedParams,
});

await algodClient.sendRawTransaction(txn).do();
//console.log(`Transaction: ${JSON.stringify(txn.from)}`);


const signTx = txn.signTxn(sender.sk);

await algodClient.sendRawTransaction(signTx).do();

acctInfS = await algodClient.accountInformation(sender.addr).do();
acctInfR = await algodClient.accountInformation(receiver.addr).do();

console.log(`New bal sender: ${acctInfS.amount/1000000}`);
console.log(`New bal receiver: ${acctInfR.amount/1000000}`);

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(`Info: ${result.txn}`);
console.log(`Payment of ${result.txn.txn.amt} microAlgos was sent to ${receiver.addr} at confirmed round ${result['confirmed-round']}`);