JavaScript code for build signed transaction and generating wallet and address
const xels = require('/src');Call getWallet method of address object without passing any parameter for generating address and private key randomly
let wallet1 = xels.address.getWalelt() //random
console.log('Wallet(Random)',wallet1);Call fromPrivateKey method of address obejct by passing private key string to gererate wallet
let wallet2 = xels.address.fromPrivateKey(private_key) //from private key
console.log('Wallet(From Private key)',wallet2);pass any string to generate wallet from the string
let wallet3 = xels.address.getWalelt('Random String') //from static string
console.log('Wallet(From String)',wallet3);Require Transaction class from src folder to build a raw transaction
const { Transaction } = require('/src')
let txobj = new Transaction()
let FEE = 10000; // in satoshi
let send_amount1 = 12*100000000; // in satoshiCall addInput method multiple times by object for multiple input or passing a array of object for multiple inputs
txobj.addInput(utxos);Call this addOutput method of Transaction object to add output address.you can call this method multiple times for multiple output to send xels
txobj.addOutput(xels_address,send_amount1)
//If you sent satoshi to multiple addresses the total amount will be the sum of those.
let total_send_amount = send_amount1;Calculate and add chagne address by call addChange method of Transaction object to receive rest of balance amount of the address
let change_amount = txobj.balance - (total_send_amount+FEE);
if(change_amount<0){
throw 'Insufficient Balance';
}
if(change_amount>0){
txobj.addChange(chaneg_address,change_amount)
}Signing all inputs by sender's private key.Call signInput method of Transaction object.
txobj.signInput(private_key);Call toHex method of Transaction object for getting transction hexa string
let hex = txobj.toHex() // Need to publish this transaction hex- You will get transaction id after broadcast a transaction*
let xelsNode = new XelsNode('http://localhost:37221');
xelsNode.getUtxos(from_address).then(utxos=>{
console.log(utxos)
})xelsNode.broadcast(hex).then(resp=>{
console.log(resp)
}).catch(err=>{
console.log(err);
})