Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

coinselect

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

coinselect

A transaction input selection module for bitcoin.

  • 3.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
16K
decreased by-6.47%
Maintainers
1
Weekly downloads
 
Created
Source

coinselect

TRAVIS NPM

js-standard-style

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 // satoshis per byte
let utxos = [
	...,
	{
		txId: '...',
		vout: 0,
		...,
		value: 10000
	}
]
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 txb = new bitcoin.TransactionBuilder()

inputs.forEach(input => txb.addInput(input.txId, input.vout))
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()
	}

	txb.addOutput(output.address, output.value)
})

Feedback welcome on the API, I'm not sure if I like it.

License MIT

Keywords

FAQs

Package last updated on 13 Oct 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc