NPM Package
Last updated
Last updated
View On NPM:
This is the documentation for the BTC NPM package that communicates with the Cardware device.
The library requires an electrs endpoint to query the bitcoin blockchain.
It allows users to create a Watch-Only Wallet on Web.
All data that is transferred between the web wallet and the Cardware device is done through scanning QR codes.
Users must first pair the web wallet with their Cardware device.
Once paired they are then able to view the BTC address of their Cardware device, see their confirmed and unconfirmed BTC balances and send BTC from their Cardware device.
When sending, the watch only wallet will create an unsigned transaction which will be split up into QR codes. The user will then be prompted to scan these QRcodes with their Cardware device. The user will then confirm the transactions details which will then create a signed transaction which their Cardware device will split up into QR codes. The web wallet then scans these QR codes, decodes them and broadcasts the transaction.
This function initializes a wallet object in your web wallet. The zpub is received from the Cardware device after successfully pairing the web wallet and Cardware device. The pairing process involves scanning the pair QR codes from the Cardware device, extracting the zpub, then using it in creating the wallet object.
zpub
string
The zpub of the the hardware wallet.
"vpub5ZNhc5KKM6hACK6QDuo6UG1749XUeXf9Gbu8rcZQnNDeMJwUPrwzEVKsF7X7EzZe5yqwymfMA1tGJ9qAmjdmGHSkRW7SruCEDz9mgEkwWvN"
esplora_url
string
The address of the esplora you are using.
"https://blockstream.info/api"
network
string
The network you are using (mainnet or testnet).
"mainnet"
No outputs.
This function syncs your web wallet to make sure it has all the correct information to be able to get balances, construct unsigned transactions and broadcast transactions.
No parameters.
The output is a string.
success
The wallet has synced successfully.
"Sync successful."
error
There is an issue fetching the fee estimates.
"Error: Fee sync error."
error
There is an issue with connecting to the esplora url.
"Error: Failed to connect to full node (Esplora)."
error
There is an issue deserializing the transaction.
"Error: Failed to deserialize transaction."
This function syncs your web wallet with max depth as a parameter to make sure it has all the correct information to be able to get balances, construct unsigned transactions and broadcast transactions.
max_depth
string
The max depth of the addresses you need to sync.
"m/0/0"
The output is a string.
success
The wallet has synced successfully.
"Sync successful."
error
There is an issue fetching the fee estimates.
"Error: Fee sync error."
error
There is an issue with connecting to the esplora url.
"Error: Failed to connect to full node (Esplora)."
error
There is an issue deserializing the transaction.
"Error: Failed to deserialize transaction."
This function estimates fees for a send transaction which takes a variable called number of blocks where the lower the number of blocks, the higher the estimated fee and the faster the transaction will confirm. Users can batch send transactions by populating multiple addresses and multiple amounts however the user must make sure both arrays have the same length.
addresses
array[string]
The addresses to send to.
["bc1q82d5gkw4xa0dgs55khfx0y4s7ntjwtfxu4h4fg"]
amounts
array[int64]
The send amounts in satoshis.
[1480]
number_of_blocks
int32
The number of blocks for fee estimation. The lower the number, the higher the fee.
3
The output is a uint64.
success
The fee estimation for a transaction (in satoshis).
1480
error
The addresses array and the amounts array are not the same length.
0
error
There is an issue parsing the network.
1
error
There is an invalid recipient address.
2
error
There is an issue fetching the fee estimates.
3
error
There is insufficient BTC to make this transaction.
4
error
There are no UTXOs to spend.
5
This function estimates fees for a max send transaction which takes a variable called number of blocks where the lower the number of blocks, the higher the estimated fee and the faster the transaction will confirm. This is called a sweep when a user wants to empty their wallet.
number_of_blocks
int32
The number of blocks for fee estimation. The lower the number, the higher the fee.
3
The output is a uint64.
success
The fee estimation for a transaction (in satoshis).
1480
error
There is an issue parsing the network.
1
error
There is an issue fetching the fee estimates.
3
error
There are no UTXOs to spend.
5
This function creates an unsigned transaction which it converts into a base64 string which it then splits up into chunks to be put into multiple QR codes. At the beginning of each chunk extra information is added. The extra information has the format of ( + index of QR code + / + total QR codes + ) + part of the unsigned transaction as a base64 string.
addresses
array[string]
The addresses to send to.
["bc1q82d5gkw4xa0dgs55khfx0y4s7ntjwtfxu4h4fg"]
amounts
array[int64]
The send amounts (in satoshis).
[1000]
fee
int64
The transaction fee worked out in estimate_fee (in satoshis).
1480
The output is an array of strings.
success
An array of base64 strings which can be shown as QR codes.
["(0/6)AgAAAAJCfJSUSIPEKOeG56APmMCEP6zPRPCz1/zyBsnFR5", "(1/6)gNNAAAAAAA/////4j8W+GTLq29Of7VdtqzMmkGpLJocgYd", "(2/6)1l/n4Crlse8vAAAAAAD/////AtAHAAAAAAAAFgAU3HfuEr", "(3/6)x48JEWN7r+DtOnmtCUXWBCWgAAAAAAABYAFDqbRFnVN17U", "(4/6)QpS10meSsPTXJy0mAAAAAA==:AAAAAOgDAAAAAAAAAAAAA", "(5/6)KhhAAAAAAAA"]
error
The addresses array and the amounts array are not the same length.
["Error: Recipients and amounts arrays must be the same length."]
error
The address is not associated with the BTC network.
["Error: Failed to parse network."]
error
The send amount is under the dust limit of 546.
["Error: Send amount under dust limit."]
error
There is insufficient BTC to make this transaction.
["Error: Insufficient funds."]
error
There are no UTXOs to spend.
["Error: No UTXOs to spend."]
error
There is an issue with the derivation path.
["Error: Derivation path error."]
error
There is an invalid recipient address.
["Error: Invalid recipient address."]
error
There is an issue with the multi-sig size and threshold.
"Error: Invalid multi-sig size and threshold, please use n/n eg. 2/3."
error
There is an issue deriving the zpub.
"Error: Zpub derivation error."
error
There are no zpubs to create a wallet.
"Error: Wallet requires at least one zpub."
This function needs a signed transaction as a base64 string. It gets this by scanning the QR codes on the Cardware device. When scanning the QR codes of the signed transaction from the Cardware device it follows the format of ( + index of QR code + / + total QR codes + ) + part of the signed transaction as a base64 string.
signed_transaction
string
The signed transaction in base64 that needs to be broadcasted.
"AgAAAAABAUJ8lJRIg8Qo54bnoA+YwIQ/rM9E8LPX/PIGycVHmA00AQAAAAD/////AugDAAAAAAAAFgAUOptEWdU3XtRClLXSZ5Kw9NcnLSabIwAAAAAAABYAFDWIiG3dUA5i2rzZg529bq4aQWPFAkgwRQIhAPk1OEfut27Z/YZsu5Xeik10inhcYYfXDXFRkOnqz/Y8AiBvx0Uqw3q3+LV8MA/cJZKComCL/2r/zXIx9cay94JXIwEhA4HigQXlfm+OMUk3YXW5cGxWOYZqfPzF0dMNLyWSHw+FAAAAAA=="
The output is a strings.
success
The transaction ID of the broadcasted transaction.
"340d9847c5c906f2fcd7b3f044cfac3f84c0980fa0e786e728c4834894947c42"
error
There is an issue parsing the base64 transaction string.
"Error: Failed to parse base64 transaction."
error
There is an issue decoding the hex transaction.
"Error: Decoding failed."
error
The signed transaction is invalid.
"Error: Invalid transaction."
error
There is an issue broadcasting the transaction.
"Error: Failed to broadcast transaction."
This function needs an array of signed transactions as a list of base64 strings. It gets these by scanning the QR codes on the Cardware devices that are part of the multisig. When scanning the QR codes of the signed transaction from the Cardware device it follows the format of ( + index of QR code + / + total QR codes + ) + part of the signed transaction as a base64 string.
transaction_signatures
array[string]
An array of signed transactions in base64 which will be used to broadcast the multisig transaction.
["AgAAAAABAbIVaiUeeL10JflXCbw4727RyErZ8/+ERs9hdIrVmrpNAQAAAAD/////AegDAAAAAAAAFgAUg3fJmFw+Xphk3Et2NlpZUoP4XycDSDBFAiEAk5onGG5supY9hsaXdgNIFOoT//95KXLdsO66FIZyo1gCIFmOTSc/6AIGc5hi1d5hBD9dCeApNs2b/frRSLq4VOc/ASECcikWYSZ3j4ahirRPBY3ZAasVUf7KelhHCdevmCn5MgVHUiECGXDMUG+QxA779XjIsWRTtZfDH1A3SV/KrTvZh6e9CJUhAnIpFmEmd4+GoYq0TwWN2QGrFVH+ynpYRwnXr5gp+TIFUq4AAAAA", "AgAAAAABAbIVaiUeeL10JflXCbw4727RyErZ8/+ERs9hdIrVmrpNAQAAAAD/////AegDAAAAAAAAFgAUg3fJmFw+Xphk3Et2NlpZUoP4XycDSDBFAiEAw/GaAfnJhAEmdWl8wuCN73qXcgBrcdxMp6/+xMVCPdECIEQIrLKA8tONmhswU1FU7HSDthx/pIxj1PXvGaVq7h7EASECGXDMUG+QxA779XjIsWRTtZfDH1A3SV/KrTvZh6e9CJVHUiECGXDMUG+QxA779XjIsWRTtZfDH1A3SV/KrTvZh6e9CJUhAnIpFmEmd4+GoYq0TwWN2QGrFVH+ynpYRwnXr5gp+TIFUq4AAAAA"]
The output is a string.
success
The transaction ID of the broadcasted transaction.
"340d9847c5c906f2fcd7b3f044cfac3f84c0980fa0e786e728c4834894947c42"
error
There is an issue deriving the zpub.
"Error: Zpub derivation error."
error
There is an issue parsing the base64 transaction string.
"Error: Failed to parse base64 transaction."
error
There is an issue decoding the hex transaction.
"Error: Decoding failed."
error
The signed transaction is invalid.
"Error: Invalid transaction."
error
One or more of the signed transactions is invalid.
"Error: Invalid transaction signatures."
error
There is an issue broadcasting the transaction.
"Error: Failed to broadcast transaction."
This function returns the address of your Cardware device.
No parameters.
The output is a string.
success
The address of the wallet.
"bc1qxkygsmwa2q8x9k4umxpem0tw4cdyzc79kn5r5p"
error
There is an invalid extended public key.
"Error: Invalid extended public key."
error
There is an issue deriving the zpub.
"Error: Zpub derivation error."
This function returns the address of your Cardware device at a certain depth.
derivation_path
string
The derivation path the new address must be derived from.
"m/0/0"
success
The address of the wallet.
"bc1qxkygsmwa2q8x9k4umxpem0tw4cdyzc79kn5r5p"
error
There is an invalid extended public key.
"Error: Invalid extended public key."
error
There is an issue deriving the zpub.
"Error: Zpub derivation error."
error
There is an issue with the multi-sig size and threshold.
"Error: Invalid multi-sig size and threshold, please use n/n eg. 2/3."
error
There are no zpubs to create a wallet.
"Error: Wallet requires at least one zpub."
This function returns confirmed balance of your Cardware device.
No parameters.
The output is a unint64.
success
The confirmed balance of your wallet (in satoshis).
"11225"
This function returns unconfirmed balance of your Cardware device.
No parameters.
The output is a unint64.
success
The unconfirmed balance of your wallet (in satoshis).
"1000"