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 }
https://github.com/bitcoinjs/bitcoinjs-lib is a great starting point. Note that stepping through sample code is a little funky as some functions go off to nowhere - I found that I need to run directly over certain cryptographic functions before I got a result. It also helps to have your own node (or use something like Quicknode) to augment whatever it is you're trying to do on-chain.
Another option to send over lightning is to leverage the Opennode service - you can go straight to their endpoints or use their npm lib.
The other option is to stand up your own LN infra - lots of resources (lnbits I think is a great start).
reply
use this library: https://github.com/bitcoinjs/bitcoinjs-lib there are samples there for exactly what you want to do.
when in doubt you can also ask https://chat.openai.com/chat for help (sign up with https://sms4sats.com if you dont want to share your phone number)
reply
I think what's missing is to set which fee (sats/vB) you want to use before sending.
Normally, that is decided by the user before sending.
Even though (or exactly because) it's only for education, I think tx fees is an important detail to understand how Bitcoin works so they should already be included in basic education and not come later as "advanced" knowledge.#
However, I can understand if this makes is too complicated at first. Then the fee should be chosen reasonably. Then you have to decide for the user if he really wants to be included in the next block or if next 3, 5, 20 blocks would also be okay.
Depending on the fee you chose, people can be a bit irritated if it takes too long to confirm or the fee was way more than they expected.
reply
reply
Yeah, the lightening network would be a great addition, but I'm writing this for larger payments ($500-$2000) between people who may not understand lightning. I'd like to keep it as simple as possible for now.
reply
There are onchain functions in that library (SendCoins, GetChainBalance). It uses LND as a connector to Bitcoin Core.
reply