npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

bitcoin3

v1.0.4

Published

Manage Bitcoin utxo

Downloads

11

Readme

Bitcoin3

Manage Bitcoin utxo

Install

npm install bitcoin3

Getting started

Create a bitcoin3 instance

const Bitcoin3 = require("bitcoin3")
const btc3     = new Bitcoin3("testnet")

//OPTIONAL: default blockcypher API
btc3.setProvider("blockcypher")

Get the balance

// Get balance of address
btc3.getBalance("2N8hwP1WmJrFF5QWABn38y63uYLhnJYJYTF").then(console.log)

Unlock the privatekey

//set the privatekey for signing
btc3.privateKeyToAccount("<privateKey>")

//Now the default account has been set
console.log(btc3.defaultAccount)

Send a transaction to a Bitcoin address

//Send the actual transaction to an address with the amount of satoshi comprhensive of actual value + fee
btc3.sendTransaction(addressTo, 20000).then(console.log).catch(console.log)

Bitcoin3 JavaScript API

All getters returns a Promise

Index

Setters

Getters

Utils

API


btc3.setProvider

Parameters
  1. String - The blockexplorer API provider. Only blockcypher supported
Returns

none

Example
btc3.setProvider("blockcypher")

btc3.setNetwork

Parameters
  1. String - The Bitcoin blockchain to work against. One of testnet and mainnet
Returns

none

Example
btc3.setNetwork("testnet")

btc3.privateKeyToAccount

Parameters
  1. String - The WIF encoded private key. Mandatory for using sendTransaction
Returns

none

Example
btc3.privateKeyToAccount("e331b6d69882b4cb4ea581d88e0b604039a3de5967688d3dcffdd2270c0fd109")

btc3.getBalance

Parameters
  1. String - The base58 Bitcoin address to watch the balance for.
Returns
  • Promise:String|String - Returns the balance in satoshis or catch the error
Example
btc3.getBalance("2N8hwP1WmJrFF5QWABn38y63uYLhnJYJYTF")
  .then( satoshis => console.log('The balance is ' + satoshis))
  .catch( reason => console.log(reason))

//The balance is 1500000

btc3.getUtxo

Parameters
  1. String - The base58 Bitcoin address to get the utxos of.
Returns
  • Promise:Array|String - Returns the array of utxos per address in the standard format {txid, vout, satoshis, confirmations}
Example
btc3.getUtxo("2N8hwP1WmJrFF5QWABn38y63uYLhnJYJYTF")
  .then( utxos => console.log(utxos))
  .catch( reason => console.log(reason))

//[...]

btc3.estimateFee

Parameters

none

Returns
  • Promise:String|String - Returns the amount in satoshi for the fastest fee
Example
btc3.estimateFee()
  .then( fastestFee => console.log(fastestFee))
  .catch( reason => console.log(reason))

//20000

btc3.isValidAddress

Parameters
  1. String - The Bitcoin address to validate
Returns
  • bool - Returns true if it is a valid base58 address
Example
const isValid = btc3.isValidAddress("000")
console.log(isValid)
//false

btc3.sendTransaction

Parameters
  1. String - The Bitcoin address to sent sathosis
  2. Number - The integer value of satoshis to be sent
Returns
  • Promise:Object|String - Return the transaction object receipt
Example
const dest = "2N8hwP1WmJrFF5QWABn38y63uYLhnJYJYTF"
const amount = 15000000

btc3.sendTransaction(dest, amount)
.then(console.log)

// {...} 

btc3.createMultisig

Parameters
  1. Array - Array of public keys in hex format
  2. m - treshold needed for sign a valid transaction
Returns
  • String - Return a m-of-n P2SH Multisig Address
Example

const keys = [
      '032b4c06c06c3ec0b7fa29519dfa5aae193ee2cc35ca127f29f14ec605d62fb63d',
      '0216c92abe433106491bdeb4a261226f20f5a4ac86220cc6e37655aac6bf3c1f2a',
      '039e05da8b8ea4f9868ecebb25998c7701542986233f4401799551fbecf316b18f'
]
const m = 2

const address = btc3.createMultisig(keys, 2)
console.log(address)
// testnet: 2N2VHjejHUCbJSRnoVyoesXMDsaiUey5ptp
//mainnet 3Aw5fuoFrk5xEeAFprBnFaMxfEWJp6vqNX