Skip to content

Instantly share code, notes, and snippets.

@kctam
Created November 9, 2020 01:39
Show Gist options
  • Save kctam/7cd30c4c474c71906d34eefe6b3845b5 to your computer and use it in GitHub Desktop.
Save kctam/7cd30c4c474c71906d34eefe6b3845b5 to your computer and use it in GitHub Desktop.
Algorand demonstration with JS SDK
const algosdk=require('algosdk');
const server="https://testnet-algorand.api.purestake.io/ps2";
const port="";
const token={
"x-api-key": "mV *** BY"
};
let client=new algosdk.Algodv2(token,server,port);
let mnemonic1='attract unit *** above trip'; // 25-word mnemonic
let account1 = algosdk.mnemonicToSecretKey(mnemonic1);
( async() => {
let params = await client.getTransactionParams().do();
let txn = {
"from": account1.addr,
"to": "6NAKWTCPPHB4RZFYS26RT5QDCO6BFNVY3OYJV4WPMGOPDPFOB2GCSR5Z4M",
"fee": 1,
"amount": 10000000, // 10 algos
"firstRound": params.firstRound,
"lastRound": params.lastRound,
"genesisID": params.genesisID,
"genesisHash": params.genesisHash,
"note": new Uint8Array(0)
}
let signedTxn = algosdk.signTransaction(txn, account1.sk);
let sendTx = await client.sendRawTransaction(signedTxn.blob).do();
console.log("Transaction: " + sendTx.txId);
})().catch( e => {
console.log(e)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment