Converting Bitcoin Cash units to satoshi units
- bitcoinCash
number
: unit to be converted
satoshi number
: bitcoinCash unit converted to satoshis
// convert 9 $BCH to satoshis
bitbox.BitcoinCash.toSatoshi(9)
// 900000000
// convert 1 $BCH to satoshis
bitbox.BitcoinCash.toSatoshi(1)
// 100000000
// convert 100 $BCH to satoshis
bitbox.BitcoinCash.toSatoshi(100)
// 10000000000
// convert 42 $BCH to satoshis
bitbox.BitcoinCash.toSatoshi(42)
// 4200000000
// convert 507 $BCH to satoshis
bitbox.BitcoinCash.toSatoshi(507)
// 50700000000
Converting satoshi units to Bitcoin Cash units
- satoshi
number
: unit to be converted
bitcoinCash number
: satoshi unit converted to Bitcoin Cash
// convert 900000000 satoshis to $BCH
bitbox.BitcoinCash.toBitcoinCash(900000000)
// 9
// convert 100000000 satoshis to $BCH
bitbox.BitcoinCash.toBitcoinCash(100000000)
// 1
// convert 10000000000 satoshis to $BCH
bitbox.BitcoinCash.toBitcoinCash(10000000000)
// 100
// convert 4200000000 satoshis to $BCH
bitbox.BitcoinCash.toBitcoinCash(4200000000)
// 42
// convert 50700000000 satoshis to $BCH
bitbox.BitcoinCash.toBitcoinCash(50700000000)
// 507
Converting satoshi units to Bits denomination
- satoshi
Number
: unit to be converted
bits Number
: satoshi unit converted to Bits
// convert 4242323400 satoshis to 42423.234 bits
BITBOX.BitcoinCash.toBits(4242323400)
// 42423.234
// convert 100000000 satoshis to 1000 bits
BITBOX.BitcoinCash.toBits(100000000)
// 1000
// convert 314000000 satoshis to 3140 bits
BITBOX.BitcoinCash.toBits(314000000)
// 3140
// convert 987600000000 satoshis to 9876000 bits
BITBOX.BitcoinCash.toBits(987600000000)
// 9876000
// convert 12300 satoshis to 0.123 bits
BITBOX.BitcoinCash.toBits(12300)
// 0.123
Converting bits units to satoshi denomination
- bits
Number
: unit to be converted
satoshi Number
: bits unit converted to satoshi
// convert 42423.234 bits to 4242323400 satoshis
BITBOX.BitcoinCash.fromBits(42423.234)
// 4242323400
// convert 1000 bits to 100000000 satoshis
BITBOX.BitcoinCash.fromBits(1000)
// 100000000
// convert 3140 bits to 314000000 satoshis
BITBOX.BitcoinCash.fromBits(3140)
// 314000000
// convert 9876000 bits to 987600000000 satoshis
BITBOX.BitcoinCash.fromBits(9876000)
// 987600000000
// convert 0.123 bits to 12300 satoshis
BITBOX.BitcoinCash.fromBits(0.123)
// 12300
Sign message with private key
- privateKeyWIF
string
: private key in wallet import format - message
string
: message to sign
signature string
: cryptographic signature
bitbox.BitcoinCash.signMessageWithPrivKey(
"KxtpRDUJDiutLaTV8Vuavhb6h7zq9YV9ZKA3dU79PCgYmNVmkkvS",
"EARTH"
)
// IIYVhlo2Z6TWFjYX1+YM+7vQKz0m+zYdSe4eYpFLuAQDEZXqll7lZC8Au22VI2LLP5x+IerZckVk3QQPsA3e8/8=
Verify message
- address
string
: public cashaddr or legacy address which signed the message - signature
string
: cryptographic signature - message
string
: to verify
isVerified boolean
: if message is verified or not
bitbox.BitcoinCash.verifyMessage(
"bitcoincash:qp2zvw3zpk5xx43w4tve7mtekd9kaxwj4uenq9eupv",
"IIYVhlo2Z6TWFjYX1+YM+7vQKz0m+zYdSe4eYpFLuAQDEZXqll7lZC8Au22VI2LLP5x+IerZckVk3QQPsA3e8/8=",
"EARTH"
)
// true
Encodes hex string as base58Check
- hex
string
: hex encoded bytes to encode as base58check
base58check string
: base58check encoded string
// encode 0079bd35d306f648350818470c9f18903df6e06902a026f2a7 as base58check
let hex = "0079bd35d306f648350818470c9f18903df6e06902a026f2a7"
bitbox.BitcoinCash.encodeBase58Check(hex)
// 1C6hRmfzvWst5WA7bFRCVAqHt5gE2g7Qar
// encode 006da742680accf2282df5fade8e9b7a01a517e779289b52cc as base58check
let hex = "006da742680accf2282df5fade8e9b7a01a517e779289b52cc"
bitbox.BitcoinCash.encodeBase58Check(hex)
// 1Azo2JBz2JswboeY9xSMcp14BAfhjnD9SK
// encode 00c68a6a07ccdaf1669cfd8d244d80ff36b713551c6208f672 as base58check
let hex = "00c68a6a07ccdaf1669cfd8d244d80ff36b713551c6208f672"
bitbox.BitcoinCash.encodeBase58Check(hex)
// 1K6ncAmMEyQrKUYosZRD9swyZNXECu2aKs
// encode 00d0a6b5e3dd43d0fb895b3b3df565bb8266c5ab00a25dbeb5 as base58check
let hex = "00d0a6b5e3dd43d0fb895b3b3df565bb8266c5ab00a25dbeb5"
bitbox.BitcoinCash.encodeBase58Check(hex)
// 1L2FG9hH3bwchhxHaCs5cg1QNbhmbaeAs6
// encode 00db04c2e6f104997cb04c956bf25da6078e559d303127f08b as base58check
let hex = "00db04c2e6f104997cb04c956bf25da6078e559d303127f08b"
bitbox.BitcoinCash.encodeBase58Check(hex)
// 1Ly4gqPddveYHMNkfjoXHanVszXpD3duKg
Decodes base58Check encoded string to hex
- base58check
string
: base58check encoded string to decode to hex
hex string
: hex encoded string
// decode 1C6hRmfzvWst5WA7bFRCVAqHt5gE2g7Qar to hex
let base58check = "1C6hRmfzvWst5WA7bFRCVAqHt5gE2g7Qar"
bitbox.BitcoinCash.decodeBase58Check(base58check)
// 0079bd35d306f648350818470c9f18903df6e06902a026f2a7
// decode 1Azo2JBz2JswboeY9xSMcp14BAfhjnD9SK to hex
let base58check = "1Azo2JBz2JswboeY9xSMcp14BAfhjnD9SK"
bitbox.BitcoinCash.decodeBase58Check(base58check)
// 006da742680accf2282df5fade8e9b7a01a517e779289b52cc
// decode 1K6ncAmMEyQrKUYosZRD9swyZNXECu2aKs to hex
let base58check = "1K6ncAmMEyQrKUYosZRD9swyZNXECu2aKs"
bitbox.BitcoinCash.decodeBase58Check(base58check)
// 00c68a6a07ccdaf1669cfd8d244d80ff36b713551c6208f672
// decode 1L2FG9hH3bwchhxHaCs5cg1QNbhmbaeAs6 to hex
let base58check = "1L2FG9hH3bwchhxHaCs5cg1QNbhmbaeAs6"
bitbox.BitcoinCash.decodeBase58Check(base58check)
// 00d0a6b5e3dd43d0fb895b3b3df565bb8266c5ab00a25dbeb5
// decode 1Ly4gqPddveYHMNkfjoXHanVszXpD3duKg to hex
let base58check = "1Ly4gqPddveYHMNkfjoXHanVszXpD3duKg"
bitbox.BitcoinCash.decodeBase58Check(base58check)
// 00db04c2e6f104997cb04c956bf25da6078e559d303127f08b
Encodes address and options as BIP21 uri
- address
string
: cashaddr (w/ or w/out prefix) or legacy base58check encoded address - options
EncodeBIP21Options
: options such as amount, label, message etc - regtest
boolean
optional
bip21 string
: bip21 encoded uri
let address = "bitcoincash:qrdsfshx7yzfjl9sfj2khuja5crcu4vaxqrt2qkz5s"
let options = {
amount: 1,
label: "#BCHForEveryone",
}
bitbox.BitcoinCash.encodeBIP21(address, options)
// bitcoincash:qrdsfshx7yzfjl9sfj2khuja5crcu4vaxqrt2qkz5s?amount=1&label=%23BCHForEveryone
let address = "1C6hRmfzvWst5WA7bFRCVAqHt5gE2g7Qar"
let options = {
amount: 12.5,
label: "coinbase donation",
message: "and ya don't stop",
}
bitbox.BitcoinCash.encodeBIP21(address, options)
// bitcoincash:qpum6dwnqmmysdggrprse8ccjq7ldcrfqgmmtgcmny?amount=12.5&label=coinbase%20donation&message=and%20ya%20don%27t%20stop
let address = "qzw6tfrh8p0jh834uf9rhg77pjg5rgnt3qw0e54u03"
let options = {
amount: 42,
label: "no prefix",
}
bitbox.BitcoinCash.encodeBIP21(address, options)
// bitcoincash:qzw6tfrh8p0jh834uf9rhg77pjg5rgnt3qw0e54u03?amount=42&label=no%20prefix
Decodes BIP21 uri
- bip21
string
: bip21 encoded uri
results BIP21Object
: decoded bip21 uri
let bip21 =
"bitcoincash:qrdsfshx7yzfjl9sfj2khuja5crcu4vaxqrt2qkz5s?amount=1&label=%23BCHForEveryone"
bitbox.BitcoinCash.decodeBIP21(bip21)
// { address: 'qrdsfshx7yzfjl9sfj2khuja5crcu4vaxqrt2qkz5s', options: { amount: 1, label: '#BCHForEveryone' } }
let bip21 =
"bitcoincash:qpum6dwnqmmysdggrprse8ccjq7ldcrfqgmmtgcmny?amount=12.5&label=coinbase%20donation&message=and%20ya%20don%27t%20stop"
bitbox.BitcoinCash.decodeBIP21(bip21)
// { address: 'qpum6dwnqmmysdggrprse8ccjq7ldcrfqgmmtgcmny',
// options:
// { amount: 12.5,
// label: 'coinbase donation',
// message: 'and ya don\'t stop'
// }
// }
let bip21 =
"bitcoincash:qzw6tfrh8p0jh834uf9rhg77pjg5rgnt3qw0e54u03?amount=42&label=no%20prefix"
bitbox.BitcoinCash.decodeBIP21(bip21)
// { address: 'qzw6tfrh8p0jh834uf9rhg77pjg5rgnt3qw0e54u03', options: { amount: 42, label: 'no prefix' } }
Get byte count of transaction
- inputs
ByteCountInput
: object w/ keys describing input types and counts. 'MULTISIG-P2SH' and 'P2PKH'. "MULTISIG-P2SH" also should include the required and total number of signatures. EX: "MULTISIG-P2SH:2-4" - outputs
ByteCountOutput
: object w/ keys describing output types and counts. 'P2SH' and 'P2PKH'
byteCount number
: number of bytes
// 1 P2PKH input
let inputs = {
P2PKH: 1,
}
// 1 P2SH output
let outputs = {
P2SH: 1,
}
bitbox.BitcoinCash.getByteCount(inputs, outputs)
// 190
// 4 MULTISIG-P2SH 2-of-4 and 10 P2PKH inputs
let inputs = {
"MULTISIG-P2SH:2-4": 4,
P2PKH: 10,
}
// 23 P2PKH outputs
let outputs = {
P2PKH: 23,
}
bitbox.BitcoinCash.getByteCount(inputs, outputs)
// 2750
// 2 MULTISIG-P2SH 3-of-5 inputs
let inputs = {
"MULTISIG-P2SH:3-5": 2,
}
// 2 P2PKH outputs
let outputs = {
P2PKH: 2,
}
bitbox.BitcoinCash.getByteCount(inputs, outputs)
// 565
// 111 P2PKH inputs
let inputs = {
P2PKH: 111,
}
// 2 P2PKH outputs
let outputs = {
P2PKH: 2,
}
bitbox.BitcoinCash.getByteCount(inputs, outputs)
// 16506
// 10 P2PKH and 1 MULTISIG-P2SH 1-of-2 input
let inputs = {
P2PKH: 10,
"MULTISIG-P2SH:1-2": 1,
}
// 2 P2PKH and 1 P2SH outputs
let outputs = {
P2PKH: 2,
P2SH: 1,
}
bitbox.BitcoinCash.getByteCount(inputs, outputs)
// 1780
BIP38 encrypt privkey WIFs
- wif
string
: privkey WIF on mainnet or testnet - password
string
: password to encrypt wif with
encryptedKey string
: privkey WIF encrypted w/ password
// mainnet
bitbox.BitcoinCash.encryptBIP38(
"L1phBREbhL4vb1uHHHCAse8bdGE5c7ic2PFjRxMawLzQCsiFVbvu",
"9GKVkabAHBMyAf"
)
// 6PYU2fDHRVF2194gKDGkbFbeu4mFgkWtVvg2RPd2Sp6KmZx3RCHFpgBB2G
// testnet
bitbox.BitcoinCash.encryptBIP38(
"cSx7KzdH9EcvDEireu2WYpGnXdFYpta7sJUNt5kVCJgA7kcAU8Gm",
"1EBPIyj55eR8bVUov9"
)
// 6PYUAPLwLSEjWSAfoe9NTSPkMZXnJA8j8EFJtKaeSnP18RCouutBrS2735
BIP38 decrypt privkey WIFs
- encryptedKey
string
: encrypted privkey WIF - password
string
: password to decrypt wif with - network
string
: mainnet or testnet. Default: mainnet
wif string
: decrypted privkey WIF on mainnet or testnet
// mainnet
bitbox.BitcoinCash.decryptBIP38(
"6PYU2fDHRVF2194gKDGkbFbeu4mFgkWtVvg2RPd2Sp6KmZx3RCHFpgBB2G",
"9GKVkabAHBMyAf",
"mainnet"
)
// L1phBREbhL4vb1uHHHCAse8bdGE5c7ic2PFjRxMawLzQCsiFVbvu
// testnet
bitbox.BitcoinCash.decryptBIP38(
"6PYUAPLwLSEjWSAfoe9NTSPkMZXnJA8j8EFJtKaeSnP18RCouutBrS2735",
"1EBPIyj55eR8bVUov9",
"testnet"
)
// cSx7KzdH9EcvDEireu2WYpGnXdFYpta7sJUNt5kVCJgA7kcAU8Gm
{
amount?: number
label?: string
message?: string
}
{
address: string
options?: EncodeBIP21Options
}
{
P2PKH?: number
}
{
P2PKH?: number
P2SH?: number
}