coinselect
An unspent transaction output (UTXO) selection module for bitcoin.
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)
})
License MIT