Pure stake API service in javascript - General - Algorand
Pure stake API service in javascript
post by harish on Jul 12, 2021
I got error in this line
let params = await algodclient.getTransactionParams();
console.log(params);
This line returns [object object].
Below is the full code:
const algosdk = require('algosdk');
//Retrieve the token, server, and port values for your installation in the algod.net
//and algod.token files within the data directory or use a standup instance if available
//TestNet
const token = "your token";
const server = "http://your.server";
const port = 8080;
//Recover the account
var mnemonic = "awake used crawl list cruel harvest useful flag essay speed glad salmon camp sudden ride symptom test kind version together project inquiry diet abandon budget";
var recoveredAccount = algosdk.mnemonicToSecretKey(mnemonic);
console.log(recoveredAccount.addr);
//check to see if account is valid
var isValid = algosdk.isValidAddress(recoveredAccount.addr);
console.log("Is this a valid address: " + isValid);
//instantiate the algod wrapper
let algodclient = new algosdk.Algod(token, server, port);
//submit the transaction
(async() => {
//Get the relevant params from the algod
let params = await algodclient.getTransactionParams();
console.log("here" + params);
let endRound = params.lastRound + parseInt(1000);
let fee = await algodclient.suggestedFee();
// create LogicSig object and sign with our secret key
let program = new Uint8Array(Buffer.from("ASABICI=", "base64"));
console.log("program " + program);
let lsig = algosdk.makeLogicSig(program);
lsig.sign(recoveredAccount.sk);
//create a transaction
let txn = {
"from": recoveredAccount.addr,
"to": "SOEI4UA72A7ZL5P25GNISSVWW724YABSGZ7GHW5ERV4QKK2XSXLXGXPG5Y",
"fee": params.fee,
"amount": 200000,
"firstRound": params.lastRound,
"lastRound": endRound,
"genesisID": params.genesisID,
"genesisHash": params.genesishashb64
};
// create logic signed transaction.
let rawSignedTxn = algosdk.signLogicSigTransaction(txn, lsig);
//Submit the lsig signed transaction
let tx = (await algodclient.sendRawTransaction(rawSignedTxn.blob));
console.log("Transaction : " + tx.txId);
})().catch(e => {
console.log(e);
});
What I have to change?
post by fabrice on Jul 12, 2021
If you are using PureStake API, you need to use the code samples there:
https://developer.purestake.io/code-samples
The way the token is sent in PureStake API is slightly different.