undercoin

0.0.5-b • Public • Published

undercoin

Bitcoin utility belt

usage

npm install undercoin

In node or browser

const undercoin = require('undercoin')

api

For functions that accept a testnet parameter, said parameter needs be just true (otherwise the function will default to mainnet).

newAddress
undercoin.newAddress(testnet)
Creates a new Bitcoin address.

undercoin.newAddress() // 3FM1J7HkVcZeHTcWadxCN9UyTLYDpUxjJn

Note that no private key is provided (you can never spend funds sent to this address).

newKeypair
undercoin.newKeypair(testnet)
Creates a new Bitcoin keypair; an object containing a private and public key

undercoin.newKeypair() 
// {
//   private : 12b9a63d4b0d355b2b26d62a56bc165bae2850785d0584d28f1d6db86c66616e,
//   public : 03ec7db1055f42f6ea1baf2206ffe90d354a18654774fa4cbc8c36390dfdab73ee
// }

newWIF
undercoin.newWIF(testnet)
Creates a new WIF

undercoin.newWIF() 
// KxvdPD4tYwiiDsjMTNNgDiXWx2jK4p3mnLhaATx5NzaMPwMakquy

addressFromWIF
undercoin.addressFromWIF(wif, testnet)
Output a public Bitcoin address from a WIF

undercoin.addressFromWIF(wif)
// 1AoUMgXS3YV5LcJCuCjNzXEctL73cR8FgJ

getAddress
undercoin.getAddress(testnet, callback)
Get a (recent) address on the blockchain

undercoin.getAddress((err, address) => console.log(address))
// 3FM1J7HkVcZeHTcWadxCN9UyTLYDpUxjJn

isSegwit undercoin.isSegwit(address) Determines if address is Segwit (Bech32) or not.

undercoin.isSegwit('bc1qx9lplhcemust5q7vjejmfaglg8h6knu7a92r5p')
// true

feeEstimate Get an estimate on the fee required to complete a transaction within x hours

Conversion functions

The following conversion functions are directly from fmtbtc, see also that repo for more conversions beyond this selection below:


btc2sat
undercoin.btc2sat(btcAmount)
Converts BTC to satoshis

undercoin.btc2sat(1) // '100000000'

sat2btc
undercoin.sat2btc(satoshis)
Converts satoshis to BTC

undercoin.sat2btc(15000000) // '0.15'

btc2msat
undercoin.btc2msat(btcAmount)
Converts BTC to 1/1000th of a satoshi

undercoin.btc2msat(1) // '100000000000'

msat2btc
undercoin.msat2btc(mSatoshis)
Converts mSatoshis to BTC.

undercoin.msat2btc(1) // '0.00000000001'

msat2sat
undercoin.msat2sat(mSatoshis)
Converts mSatoshis to regular satoshis.

undercoin.msat2sat(1000) // '1'

sat2msat
undercoin.msat2sat(satoshis)
Converts satoshis to mSatoshis.

undercoin.sat2msat(1) // '1000'

MIT

Package Sidebar

Install

npm i undercoin

Weekly Downloads

7

Version

0.0.5-b

License

MIT

Unpacked Size

11.9 kB

Total Files

4

Last publish

Collaborators

  • drschwabe