All Projects → bitcoinjs → Coinselect

bitcoinjs / Coinselect

Licence: mit
An unspent transaction output (UTXO) selection module for bitcoin.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Coinselect

Awesome Coins
₿ A guide (for humans!) to cryto-currencies and their algos.
Stars: ✭ 3,469 (+2766.94%)
Mutual labels:  bitcoin, wallet, coin
Walletwasabi
Open-source, non-custodial, privacy focused Bitcoin wallet for Windows, Linux, and Mac. Built-in Tor, CoinJoin, and coin control features.
Stars: ✭ 1,197 (+889.26%)
Mutual labels:  bitcoin, wallet, coin
Ddn
DDN, Data Delivery Network, a next generation blockchain system
Stars: ✭ 118 (-2.48%)
Mutual labels:  bitcoin, wallet
Cated
CATEd - Cryptocurrency Analytics and Trading Engine for Django
Stars: ✭ 84 (-30.58%)
Mutual labels:  bitcoin, wallet
Opendime
Opendime is a small USB stick that allows you to spend Bitcoin like a dollar bill
Stars: ✭ 93 (-23.14%)
Mutual labels:  bitcoin, wallet
Nowallet
This project is a secure Bitcoin brainwallet app written in Python.
Stars: ✭ 52 (-57.02%)
Mutual labels:  bitcoin, wallet
Airgap Wallet
The AirGap Wallet is installed on an everyday smartphone. This app has only access to public information.
Stars: ✭ 78 (-35.54%)
Mutual labels:  bitcoin, wallet
Dotcoin
A simple and integrity blockchain implementation in Golang
Stars: ✭ 89 (-26.45%)
Mutual labels:  bitcoin, coin
Miner Monitor
Miner, balance, wallet and pool monitoring software
Stars: ✭ 38 (-68.6%)
Mutual labels:  bitcoin, wallet
Cryptocurrency Cli
💰 Cryptocurrency Portfolio On The Command Line 💰
Stars: ✭ 99 (-18.18%)
Mutual labels:  bitcoin, coin
Bitbox Wallet App
The BitBoxApp for desktop and mobile.
Stars: ✭ 98 (-19.01%)
Mutual labels:  bitcoin, wallet
Lnwallet
Bitcoin Lightning Wallet for Android
Stars: ✭ 118 (-2.48%)
Mutual labels:  bitcoin, wallet
Bitcoinaddress
Bitcoin Wallet Address Generator
Stars: ✭ 52 (-57.02%)
Mutual labels:  bitcoin, wallet
Paymint
The Paymint Wallet is a secure and user friendly Bitcoin wallet
Stars: ✭ 48 (-60.33%)
Mutual labels:  bitcoin, wallet
Blixt Wallet
Bitcoin Lightning Wallet with focus on usability and user experience
Stars: ✭ 40 (-66.94%)
Mutual labels:  bitcoin, wallet
Coin registry
A global registry of JSON formatted files on 1500+ cryptocurrency tokens. Provides information like chat rooms, communities, explorers, and contact information on each coin. Used by https://blockmodo.com, DEXs, developers, and exchanges.
Stars: ✭ 85 (-29.75%)
Mutual labels:  bitcoin, coin
Django Cc
Django wallet for Bitcoin and other cryptocurrencies
Stars: ✭ 105 (-13.22%)
Mutual labels:  bitcoin, wallet
Blockchain
区块链技术
Stars: ✭ 28 (-76.86%)
Mutual labels:  bitcoin, wallet
Arcbit Android
arcbit - Android bitcoin wallet http://arcbit.io
Stars: ✭ 34 (-71.9%)
Mutual labels:  bitcoin, wallet
Etherwalletkit
Ethereum Wallet Toolkit for iOS - You can implement an Ethereum wallet without a server and blockchain knowledge.
Stars: ✭ 96 (-20.66%)
Mutual labels:  wallet, coin

coinselect

TRAVIS NPM

js-standard-style

An unspent transaction output (UTXO) selection module for bitcoin.

WARNING: Value units are in satoshis, not Bitcoin.

Algorithms

Module Algorithm Re-orders UTXOs?
require('coinselect') Blackjack, with Accumulative fallback By Descending Value
require('coinselect/accumulative') Accumulative - accumulates inputs until the target value (+fees) is reached, skipping detrimental inputs -
require('coinselect/blackjack') Blackjack - accumulates inputs until the target value (+fees) is matched, does not accumulate inputs that go over the target value (within a threshold) -
require('coinselect/break') Break - breaks the input values into equal denominations of output (as provided) -
require('coinselect/split') Split - splits the input values evenly between all outputs, any provided output with .value remains unchanged -

Note: Each algorithm will add a change output if the input - output - fee value difference is over a dust threshold. This is calculated independently by utils.finalize, irrespective of the algorithm chosen, for the purposes of safety.

Pro-tip: if you want to send-all inputs to an output address, coinselect/split with a partial output (.address defined, no .value) can be used to send-all, while leaving an appropriate amount for the fee.

Example

let coinSelect = require('coinselect')
let feeRate = 55 // satoshis per byte
let utxos = [
  ...,
  {
    txId: '...',
    vout: 0,
    ...,
    value: 10000,
    // For use with PSBT:
    // not needed for coinSelect, but will be passed on to inputs later
    nonWitnessUtxo: Buffer.from('...full raw hex of txId tx...', 'hex'),
    // OR
    // if your utxo is a segwit output, you can use witnessUtxo instead
    witnessUtxo: {
      script: Buffer.from('... scriptPubkey hex...', 'hex'),
      value: 10000 // 0.0001 BTC and is the exact same as the value above
    }
  }
]
let targets = [
  ...,
  {
    address: '1EHNa6Q4Jz2uvNExL497mE43ikXhwF6kZm',
    value: 5000
  }
]

// ...
let { inputs, outputs, fee } = coinSelect(utxos, targets, feeRate)

// the accumulated fee is always returned for analysis
console.log(fee)

// .inputs and .outputs will be undefined if no solution was found
if (!inputs || !outputs) return

let psbt = new bitcoin.Psbt()

inputs.forEach(input =>
  psbt.addInput({
    hash: input.txId,
    index: input.vout,
    nonWitnessUtxo: input.nonWitnessUtxo,
    // OR (not both)
    witnessUtxo: input.witnessUtxo,
  })
)
outputs.forEach(output => {
  // watch out, outputs may have been added that you need to provide
  // an output address/script for
  if (!output.address) {
    output.address = wallet.getChangeAddress()
    wallet.nextChangeAddress()
  }

  psbt.addOutput({
    address: output.address,
    value: output.value,
  })
})

License MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].