Bitcoin3
Manage Bitcoin utxo
Install
npm install bitcoin3
Getting started
Create a bitcoin3
instance
const Bitcoin3 = const btc3 = "testnet" //OPTIONAL: default blockcypher APIbtc3
Get the balance
// Get balance of addressbtc3
Unlock the privatekey
//set the privatekey for signingbtc3 //Now the default account has been setconsole
Send a transaction to a Bitcoin address
//Send the actual transaction to an address with the amount of satoshi comprhensive of actual value + feebtc3
Bitcoin3 JavaScript API
All getters returns a Promise
Index
Setters
Getters
Utils
API
btc3.setProvider
Parameters
String
- The blockexplorer API provider. Only blockcypher supported
Returns
none
Example
btc3
btc3.setNetwork
Parameters
String
- The Bitcoin blockchain to work against. One of testnet and mainnet
Returns
none
Example
btc3
btc3.privateKeyToAccount
Parameters
String
- The WIF encoded private key. Mandatory for usingsendTransaction
Returns
none
Example
btc3
btc3.getBalance
Parameters
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 //The balance is 1500000
btc3.getUtxo
Parameters
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 //[...]
btc3.estimateFee
Parameters
none
Returns
Promise:String|String
- Returns the amount in satoshi for the fastest fee
Example
btc3 //20000
btc3.isValidAddress
Parameters
String
- The Bitcoin address to validate
Returns
bool
- Returns true if it is a valid base58 address
Example
const isValid = btc3console//false
btc3.sendTransaction
Parameters
String
- The Bitcoin address to sent sathosisNumber
- 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 // {...}
btc3.createMultisig
Parameters
Array
- Array of public keys in hex formatm
- 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 = btc3console// testnet: 2N2VHjejHUCbJSRnoVyoesXMDsaiUey5ptp//mainnet 3Aw5fuoFrk5xEeAFprBnFaMxfEWJp6vqNX