@pipeline-ui-2/pipeline
Version:
Class to send transactions to Algorand network with MyAlgo Connect
51 lines (41 loc) • 1.44 kB
JavaScript
import algosdk from "algosdk";
import Pipeline from "./index.js";
export default class Escrow {
static address = ""
static secret = undefined
static importAccount(mnemonicString){
let account = algosdk.mnemonicToSecretKey(mnemonicString)
this.address = account.addr
this.secret = account.sk
}
static createAccount(){
let newAccount = algosdk.generateAccount();
let mnemonic = algosdk.secretKeyToMnemonic(newAccount.sk)
this.address = newAccount.addr
this.secret = newAccount.sk
return {
address: newAccount.addr,
mnemonic: mnemonic,
sk:newAccount.sk
}
}
static sign(mytxnb, group = false) {
if (!group) {
let signedTxn = algosdk.signTransaction(mytxnb, this.secret)
return signedTxn.blob;
} else {
let signedGroup = [];
mytxnb.forEach((transaction) => {
let signed = algosdk.signTransaction(transaction, this.secret);
signedGroup.push(signed.blob);
});
console.log("Signed Group:");
console.log(signedGroup);
return signedGroup;
}
}
static async fund(amount){
let txid = await Pipeline.send(this.address,parseInt(amount),"",undefined,undefined,0)
return txid
}
}