Array of UTXOs for the transaction. Each UTXO includes an OutputInstance
and its value.
Array of transaction targets. If specified, remainder
is used
as the change address.
OutputInstance
used as the change address when targets are specified,
or as the recipient address for maximum fund transactions.
Optional
dustFee rate used to calculate the dust threshold for transaction outputs. Defaults to standard dust relay fee rate if not specified.
3
Object with selected UTXOs, targets, fee, and estimated vsize, or undefined if no solution is found.
const { utxos, targets, fee, vsize } = coinselect({
utxos: [
{ output: new Output({ descriptor: 'addr(...)' }), value: 2000 },
{ output: new Output({ descriptor: 'addr(...)' }), value: 4000 }
],
targets: [
{ output: new Output({ descriptor: 'addr(...)' }), value: 3000 }
],
remainder: new Output({ descriptor: 'addr(...)' }),
feeRate: 1.34
});
https://bitcoinerlab.com/modules/descriptors for descriptor info.
Selects UTXOs for a Bitcoin transaction.
Sorts UTXOs by their descending net value (each UTXO's value minus the fees needed to spend it).
It initially attempts to find a solution using the avoidChange algorithm, which aims to select UTXOs such that no change is required. If this is not possible, it then applies the addUntilReach algorithm, which adds UTXOs until the total value exceeds the target value plus fees. Change is added only if it's above the dustThreshold).
UTXOs that do not provide enough value to cover their respective fee contributions are automatically excluded.
NOTE: When the descriptor in an input is
addr(address)
, it is assumed that anyaddr(SH_TYPE_ADDRESS)
is in fact a SegwitSH_WPKH
(Script Hash-Witness Public Key Hash). For inputs using arbitrary scripts (not standard addresses), use a descriptor in the formatsh(MINISCRIPT)
.