coinselect
A transaction input selection module for bitcoin.
The code is stable.
The module's interface is not.
Please let me know if you are using this package.
Example
let coinSelect = require('coinselect')
let feeRate = 55
let utxos = [
...,
{
txId: '...',
vout: 0,
...,
value: 10000
}
]
let targets = [
...,
{
address: '1EHNa6Q4Jz2uvNExL497mE43ikXhwF6kZm',
value: 5000
}
]
let { inputs, outputs, fee } = coinSelect(utxos, targets, feeRate)
console.log(fee)
if (!inputs || !outputs) return
let txb = new bitcoin.TransactionBuilder()
inputs.forEach(input => txb.addInput(input.txId, input.vout))
outputs.forEach(output => {
if (!output.address) {
output.address = wallet.getChangeAddress()
}
txb.addOutput(output.address, output.value)
})
Feedback welcome on the API, I'm not sure if I like it.
License MIT