I'm new to this community, so feel free to delete this/downvote if it's not allowed.
I'm trying to work out a node.js program to send payments from one wallet to another. I'm new to JS and Node, so I need to know what packages to install to node as well. The code is for educational purposes, so some good comments are wanted. Ideally it could be shown via replit, so we could watch it run. Is that something I can do here? Is 120400 sats enough to get someone to make this?
psuedo code
/**
* create a spending transaction with the parameters,
* sign it and send it. Return txID or ERROR:
* @param {*} toAddress
* @param {*} amount
* @param {*} key
*/
function sendSignedTransction(toAddress,amount,key){
// determine fee
// create a signed transcation
// send it
// if success return txID
// if error return "ERROR:" + error.message
// if there's common mistakes here, document what they are and how to handle them
}
/**
* Gets the balance of a wallet given it's key or address
* @param {*} key private key of wallet
*/
function getBalance(key){
//return some balance from the blockchain (or is a blockchain explorer better for this?)
}
/**
* Make a payment with the following
* @param {*} toAddress
* @param {*} amount
* @param {*} key, private key for sending wallet
*/
function MakePayment(toAddress, amount, key){
var network = testing// choose test chain or mainchain
// get the balance of the sending wallet
const sendingBalance = getBalance(key)
if(amount<sendingBalance){
// send it
tx = sendSignedTransction(toAddress,amount,key)
// on confirmation
if(tx.search("ERROR"<0) ){
txLink = "https://mempool.space/tx/" + tx
console.log(`Payment Sent:{txLink}`)
} else{
console.log(tx)
}
} else{
console.log(`Balance too low, balance: ${sendingBalance}, payment: ${amount}`)
}
MakePayment(testAddress, testAmount, testKey)
// export MakePayment function to make it public
}