Introduction
Welcome to the bcoin API!
The default bcoin HTTP server listens on the standard RPC port (8332
for main, 18332
for testnet, 48332
for regtest, and 18556
default for simnet). It exposes a REST JSON, as well as a JSON-RPC api.
Authentication
Auth
# default regtest port is 48332 (may be reconfigured by user), API key is required in URL
curl http://x:api-key@127.0.0.1:48332/
# examples in these docs will use an environment variable:
url=http://x:api-key@127.0.0.1:48332/
curl $url
bcoin-cli --api-key=api-key --network=regtest info
# store API key and network type in environment variables:
export BCOIN_API_KEY=api-key
export BCOIN_NETWORK=regtest
bcoin-cli info
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
// network type derived from bcoin object, client object stores API key
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
const clientinfo = await client.getInfo();
console.log(clientinfo);
})();
Make sure to replace
api-key
with your own key.
Auth is accomplished via HTTP Basic Auth, using your node's API key.
Configuring Clients
Default Listeners
# With curl you just send HTTP Requests based on further docs
curl http://127.0.0.1:48332/ # will get info from regtest
By default the API server listens on these localhost
ports:
Network | API Port |
---|---|
main | 8332 |
testnet | 18332 |
regtest | 48332 |
simnet | 18556 |
You can interact with bcoin with its REST API as well as with RPC. There are couple of ways you can use the API:
bcoin-cli
- methods built specifically into bcoin by its developersbcoin-cli rpc
- adds functionality that mimics Bitcoin Core RPCjavascript
- methods used bybcoin-cli
can be accessed directly from javascriptcurl
- you can use direct HTTP calls for invoking both REST and RPC API calls
Only thing to keep in mind is authentication, which is described in the "Authentication" section.
Configuring bcoin-cli
# You can configure it by passing arguments:
bcoin-cli --network=regtest info
bcoin-cli info --network=regtest
# Or use environment variables (Starting with BCOIN_)
export BCOIN_NETWORK=regtest
export BCOIN_API_KEY=$YOUR-API-KEY
bcoin-cli info
Install bcoin-cli
and bwallet-cli
command line tools with the bclient
package.
Included with bcoin
by default, but can be installed separately:
npm install -g bclient
bcoin-cli
params:
General configurations are:
Config | Options | Description |
---|---|---|
network | main , testnet , regtest |
This will configure which network to load, also where to look for bcoin.conf file |
uri, url | Base HTTP URI | This can be used for custom port |
api-key | string | Secret used by RPC for authorization |
Wallet Specific
Config | Options | Description |
---|---|---|
id | string | specify which account to use by default |
token | string | Token specific wallet |
# Example bcoin.conf syntax:
network: main
prefix: ~/.bcoin
api-key: <api-key>
bcoin.conf and wallet.conf files
These files may contain any of the configuration parameters, and will be interpreted by bclient at startup. The node and wallet clients look for their own respective conf files.
A sample bcoin.conf file is included in the code repository
Detailed configuration documentation is available in docs/configuration
Using Javascript Clients
const {NodeClient, WalletClient} = require('bclient');
const {Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
const wallet = new WalletClient(walletOptions);
You can also use the API with a Javascript library (used by bcoin-cli
).
There are two objects: NodeClient
for general API and WalletClient
for wallet API.
bcoin
also provides an object Network
and its method get
which will return the default configuration parameters for a specified network.
Custom port numbers are also configurable by the user.
NodeClient
and WalletClient
options:
Config | Type | Description |
---|---|---|
network | string | Network to use: main , testnet , regtest |
port | int | bcoin socket port (defaults specific for each network) |
host | string | bcoin API host URI (defaults to 127.0.0.1) |
apiKey | string | API secret |
ssl | boolean | TLS (defaults to false: http , unless url has https ) |
bcoin - Node
bcoin client requests
Click a command to see its complete description and usage.
Command | cURL method | Description |
---|---|---|
/ |
GET |
Get basic info |
/tx/:hash |
GET |
TX by hash |
/tx/address/:address |
GET |
TX by address |
/coin/:hash/:index |
GET |
UTXO by txid and index |
/block/:block |
GET |
Block by hash or height |
/header/:block |
GET |
Block header by hash or height |
/filter/:block |
GET |
BIP158 block filter by hash or height |
/mempool |
GET |
Mempool snapshot |
/broadcast |
POST |
Broadcast TX |
/fee |
GET |
Estimate fee |
/reset |
POST |
Reset chain to specific height |
Get server info
curl $url/
bcoin-cli info
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
const clientinfo = await client.getInfo();
console.log(clientinfo);
})();
The above command returns JSON structured like this:
{
"version": "2.0.0-dev",
"network": "regtest",
"chain": {
"height": 208,
"tip": "283163d3fdf2591ea79fafe110a34e8c735e69c98046e46eeba795fa65d2a2ab",
"progress": 0.9997082948837989
},
"indexes": {
"addr": {
"enabled": true,
"height": 208
},
"tx": {
"enabled": true,
"height": 208
},
"filter": {
"enabled": true,
"height": 208
}
},
"pool": {
"host": "100.200.50.10",
"port": 48444,
"agent": "/bcoin:2.0.0-dev/",
"services": "1001",
"outbound": 0,
"inbound": 0
},
"mempool": {
"tx": 0,
"size": 0,
"orphans": 0
},
"time": {
"uptime": 109,
"system": 1571749599,
"adjusted": 1571749599,
"offset": 0
},
"memory": {
"total": 55,
"jsHeap": 19,
"jsHeapTotal": 33,
"nativeHeap": 22,
"external": 7
}
}
Get server Info.
HTTP Request
Get server info. No params.
GET /
No Params.
Get mempool snapshot
curl $url/mempool
bcoin-cli mempool
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
const mempool = await client.getMempool();
console.log(mempool);
})().catch((err) => {
console.error(err.stack);
});
The above command returns JSON structured like this:
[
"2ef8051e6c38e136ba4d195c048e78f9077751758db710475fa532b9d9489324",
"bc3308b61959664b71ac7fb8e9ee17d13476b5a32926f512882851b7631884f9",
"53faa103e8217e1520f5149a4e8c84aeb58e55bdab11164a95e69a8ca50f8fcc",
"fff647849be7408faedda377eea6c37718ab39d656af8926e0b4b74453624f32",
"b3c71dd8959ea97d41324779604b210ae881cdaa5d5abfcbfb3502a0e75c1283",
...
]
Get mempool snapshot (array of json txs).
HTTP Request
GET /mempool
No Params.
Get block by hash or height
let blockHash, blockHeight;
blockHash='78f86c294d1ffc640f1783e2b3cc3dcdfbe1da9fe885f35de286f94db8cfac72';
blockHeight='50';
curl $url/block/$blockHash # by hash
curl $url/block/$blockHeight # by height
bcoin-cli block $blockHash # by hash
bcoin-cli block $blockHeight # by height
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
const blockByHeight = await client.getBlock(blockHeight);
const blockByHash = await client.getBlock(blockHash);
console.log("By height: \n", blockByHeight);
console.log("By hash: \n", blockByHash);
})();
The above command returns JSON structured like this:
{
"hash": "78f86c294d1ffc640f1783e2b3cc3dcdfbe1da9fe885f35de286f94db8cfac72",
"height": 50,
"depth": 484,
"version": 536870912,
"prevBlock": "4e186ead55dfe014baee8bab96805c88c03032ba1e92be86709ca9f65ea5003a",
"merkleRoot": "5bca36ac149947e8f545d28ae2d34b6f6f170d36dd5289766e08813f5d183678",
"time": 1571759960,
"bits": 545259519,
"nonce": 0,
"txs": [
{
"hash": "5bca36ac149947e8f545d28ae2d34b6f6f170d36dd5289766e08813f5d183678",
"witnessHash": "c3401a27680aebb0603f50c0bafbe22c492ec9e65aea754a179f10b3f537d2c6",
"fee": 0,
"rate": 0,
"mtime": 1571762225,
"index": 0,
"version": 1,
"inputs": [
{
"prevout": {
"hash": "0000000000000000000000000000000000000000000000000000000000000000",
"index": 4294967295
},
"script": "01320e6d696e65642062792062636f696e0431d5f7bf080000000000000000",
"witness": "01200000000000000000000000000000000000000000000000000000000000000000",
"sequence": 4294967295,
"address": null
}
],
"outputs": [
{
"value": 5000000000,
"script": "76a91415f34e5cc7c4d7cc5a896611af8fb242847e003d88ac",
"address": "mhX1xHbKGzw3r8FoN5bUkmRixHPEDNywxh"
},
{
"value": 0,
"script": "6a24aa21a9ede2f61c3f71d1defd3fa999dfa36953755c690689799962b48bebd836974e8cf9",
"address": null
}
],
"locktime": 0,
"hex": "010000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff1f01320e6d696e65642062792062636f696e0431d5f7bf080000000000000000ffffffff0200f2052a010000001976a91415f34e5cc7c4d7cc5a896611af8fb242847e003d88ac0000000000000000266a24aa21a9ede2f61c3f71d1defd3fa999dfa36953755c690689799962b48bebd836974e8cf90120000000000000000000000000000000000000000000000000000000000000000000000000"
}
]
}
Returns block info by block hash or height.
HTTP Request
GET /block/:blockhashOrHeight
URL Parameters
Parameter | Description |
---|---|
:blockhashOrHeight | Hash or Height of block |
Get block header by hash or height
let blockHash, blockHeight;
blockHash='6f1003edd05cad861395225415160b5236968cc223fe982796b6e959c9651d44';
blockHeight='100';
curl $url/header/$blockHash # by hash
curl $url/header/$blockHeight # by height
bcoin-cli header $blockHash # by hash
bcoin-cli header $blockHeight # by height
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
const headerByHeight = await client.getBlockHeader(blockHeight);
const headerByHash = await client.getBlockHeader(blockHash);
console.log("By height: \n", headerByHeight);
console.log("By hash: \n", headerByHash);
})();
The above command returns JSON structured like this:
{
"hash": "6f1003edd05cad861395225415160b5236968cc223fe982796b6e959c9651d44",
"version": 536870912,
"prevBlock": "0c4ea5e675941eca1909275f21903cef755069a03c57c10f4d4dadcdd7146daf",
"merkleRoot": "9a249c682aba07943c8a1f9bd774a15d71372fcd7f3f9ee99e8c7aa022ae6aa0",
"time": 1571661863,
"bits": 545259519,
"nonce": 8,
"height": 100,
"chainwork": "00000000000000000000000000000000000000000000000000000000000000ca"
}
Returns block header by block hash or height.
HTTP Request
GET /header/:blockhashOrHeight
URL Parameters
Parameter | Description |
---|---|
:blockhashOrHeight | Hash or Height of block |
Get block filter by hash or height
let blockHash, blockHeight;
blockHash='6f1003edd05cad861395225415160b5236968cc223fe982796b6e959c9651d44';
blockHeight='100';
curl $url/filter/$blockHash # by hash
curl $url/filter/$blockHeight # by height
bcoin-cli filter $blockHash # by hash
bcoin-cli filter $blockHeight # by height
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
const filterByHeight = await client.getFilter(blockHeight);
const filterByHash = await client.getFilter(blockHash);
console.log("By height: \n", filterByHeight);
console.log("By hash: \n", filterByHash);
})();
The above command returns JSON structured like this:
{
"filter": "011ece10",
"header": "14940c1a3a7c764a1939300c386ceb378abfa581c243ad2c19bf7e0b52a09a09"
}
Returns BIP158 block filter by block hash or height.
HTTP Request
GET /filter/:blockhashOrHeight
URL Parameters
Parameter | Description |
---|---|
:blockhashOrHeight | Hash or Height of block |
Broadcast transaction
let tx;
tx='010000000106b014e37704109fefe2c5c9f4227d68840c3497fc89a9832db8504df039a6c7000000006a47304402207dc8173fbd7d23c3950aaf91b1bc78c0ed9bf910d47a977b24a8478a91b28e69022024860f942a16bc67ec54884e338b5b87f4a9518a80f9402564061a3649019319012103cb25dc2929ea58675113e60f4c08d084904189ab44a9a142179684c6cdd8d46affffffff0280c3c901000000001976a91400ba915c3d18907b79e6cfcd8b9fdf69edc7a7db88acc41c3c28010000001976a91437f306a0154e1f0de4e54d6cf9d46e07722b722688ac00000000';
curl $url/broadcast \
-H 'Content-Type: application/json' \
-X POST \
--data '{ "tx": "'$tx'" }'
bcoin-cli broadcast $tx
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
const result = await client.broadcast(tx);
console.log(result);
})();
The above command returns JSON structured like this:
{
"success": true
}
Broadcast a transaction by adding it to the node's mempool. If mempool verification fails, the node will still forcefully advertise and relay the transaction for the next 60 seconds.
HTTP Request
POST /broadcast
POST Parameters (JSON)
Parameter | Description |
---|---|
tx | raw transaction in hex |
Estimate fee
let blocks;
blocks=3
curl $url/fee?blocks=$blocks
bcoin-cli fee $blocks
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
const result = await client.estimateFee(blocks);
console.log(result);
})();
The above command returns JSON structured like this:
{
"rate": 13795
}
Estimate the fee required (in Satoshis per kB) for a transaction to be confirmed by the network within a targeted number of blocks (default 1).
HTTP Request
GET /fee
GET Parameters
Parameter | Description |
---|---|
blocks | Number of blocks to target confirmation |
Reset blockchain
let height;
height=1000;
curl $url/reset \
-H 'Content-Type: application/json' \
-X POST \
--data '{ "height": '$height' }'
bcoin-cli reset $height
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
const result = await client.reset(height);
console.log(result);
})();
The above command returns JSON structured like this:
{
"success": true
}
Triggers a hard-reset of the blockchain. All blocks are disconnected from the tip down to the provided height. Indexes and Chain Entries are removed. Useful for "rescanning" an SPV wallet. Since there are no blocks stored on disk, the only way to rescan the blockchain is to re-request [merkle]blocks from peers.
HTTP Request
POST /reset
POST Parameters (JSON)
Parameter | Description |
---|---|
height | block height to reset chain to |
bcoin - Coins
Getting coin information via API.
Coin stands for UTXO (unspent transaction output)
Get coin by Outpoint
let hash, index;
hash='53faa103e8217e1520f5149a4e8c84aeb58e55bdab11164a95e69a8ca50f8fcc';
index=0;
curl $url/coin/$hash/$index
bcoin-cli coin $hash $index
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
const result = await client.getCoin(hash, index);
console.log(result);
})();
The above command returns JSON structured like this:
{
"version": 1,
"height": 533,
"value": 67377,
"script": "76a9147356fde8f0a321dd114d947495d1f4b9f3cb050088ac",
"address": "mr2pDQvLN7eGv6xinBgSUmQpYSYdTEWyTf",
"coinbase": false,
"hash": "c747afe7aea229ae2aed7135eb768fd2dc1d8172cd7463bf3906e8321baa5608",
"index": 0
}
Get coin by outpoint (hash and index). Returns coin in bcoin coin JSON format.
value
is always expressed in satoshis.
HTTP Request
GET /coin/:hash/:index
URL Parameters
Parameter | Description |
---|---|
:hash | Hash of tx |
:index | Output's index in tx |
bcoin - Transactions
Getting transaction information via API.
Get tx by hash
let txhash;
txhash='77a39583060aa3ff2a705d401fea0c07e77e95d66cc10b744dc95098cad1bee1';
curl $url/tx/$txhash
bcoin-cli tx $txhash
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
const result = await client.getTX(txhash);
console.log(result);
})().catch((err) => {
console.error(err.stack);
});
The above command returns JSON structured like this:
{
"hash": "77a39583060aa3ff2a705d401fea0c07e77e95d66cc10b744dc95098cad1bee1",
"witnessHash": "130bd86dccf06142b6134c7c38997d8babc2104a94d7a84da021d587740ed1c8",
"fee": 1740,
"rate": 9942,
"mtime": 1571763474,
"height": 530,
"block": "34d0385c667319c5225c7f82e025681bae2fb5df28809cc7cf432b491125c83c",
"time": 1571760040,
"index": 8,
"version": 1,
"inputs": [
{
"prevout": {
"hash": "9d2330c36814d20ccdba1b6fc5153ed3b294cb34fa99fc8199552014250ea285",
"index": 3
},
"script": "",
"witness": "02473044022008765f15a62f283c06082dfea6a6f413eae4190dbbfd57efae1813432b66613e0220163b708d4e1ccd6a439da2d222f72e4231bdfd877fcdfb73ac85566e6358c559012103d2d0677a136821cb92361501570173e2c6b0d8b12e584737ffc991d2d1ccf026",
"sequence": 4294967295,
"coin": {
"version": 1,
"height": 528,
"value": 34297185559,
"script": "0014268a968f7d4d1d72bbecc0ebca21d890901ba312",
"address": "bcrt1qy69fdrmaf5wh9wlvcr4u5gwcjzgphgcjswyuvn",
"coinbase": false
}
}
],
"outputs": [
{
"value": 37547,
"script": "00143ce6c756ef2f35d61aab99d1619aab2f48da6987",
"address": "bcrt1q8nnvw4h09u6avx4tn8gkrx4t9ayd56v86q7ceg"
},
{
"value": 50131,
"script": "76a914e53103ac18b5d274dcea14e6b0c856182ce7021688ac",
"address": "n2QokZQd8Fn6a82vwXtndYy88HeUk3BZio"
},
{
"value": 34297096141,
"script": "0014f0ddfca1c6023538c032f6fb46a35703099319fe",
"address": "bcrt1q7rwlegwxqg6n3spj7ma5dg6hqvyexx07zmt40j"
}
],
"locktime": 0,
"hex": "0100000000010185a20e251420559981fc99fa34cb94b2d33e15c56f1bbacd0cd21468c330239d0300000000ffffffff03ab920000000000001600143ce6c756ef2f35d61aab99d1619aab2f48da6987d3c30000000000001976a914e53103ac18b5d274dcea14e6b0c856182ce7021688accd2744fc07000000160014f0ddfca1c6023538c032f6fb46a35703099319fe02473044022008765f15a62f283c06082dfea6a6f413eae4190dbbfd57efae1813432b66613e0220163b708d4e1ccd6a439da2d222f72e4231bdfd877fcdfb73ac85566e6358c559012103d2d0677a136821cb92361501570173e2c6b0d8b12e584737ffc991d2d1ccf02600000000",
"confirmations": 6
}
HTTP Request
GET /tx/:txhash
URL Parameters
Parameter | Description |
---|---|
:txhash | Hash of tx. |
Get tx by address
let address;
address='bcrt1q8nnvw4h09u6avx4tn8gkrx4t9ayd56v86q7ceg';
curl $url/tx/address/$address
bcoin-cli tx $address
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
const result = await client.getTXByAddress(address);
console.log(result);
})().catch((err) => {
console.error(err.stack);
});
The above command returns JSON structured like this:
[
{
"hash": "77a39583060aa3ff2a705d401fea0c07e77e95d66cc10b744dc95098cad1bee1",
"witnessHash": "130bd86dccf06142b6134c7c38997d8babc2104a94d7a84da021d587740ed1c8",
"fee": 1740,
"rate": 9942,
"mtime": 1571763513,
"height": 530,
"block": "34d0385c667319c5225c7f82e025681bae2fb5df28809cc7cf432b491125c83c",
"time": 1571760040,
"index": 8,
"version": 1,
"inputs": [
{
"prevout": {
"hash": "9d2330c36814d20ccdba1b6fc5153ed3b294cb34fa99fc8199552014250ea285",
"index": 3
},
"script": "",
"witness": "02473044022008765f15a62f283c06082dfea6a6f413eae4190dbbfd57efae1813432b66613e0220163b708d4e1ccd6a439da2d222f72e4231bdfd877fcdfb73ac85566e6358c559012103d2d0677a136821cb92361501570173e2c6b0d8b12e584737ffc991d2d1ccf026",
"sequence": 4294967295,
"coin": {
"version": 1,
"height": 528,
"value": 34297185559,
"script": "0014268a968f7d4d1d72bbecc0ebca21d890901ba312",
"address": "bcrt1qy69fdrmaf5wh9wlvcr4u5gwcjzgphgcjswyuvn",
"coinbase": false
}
}
],
"outputs": [
{
"value": 37547,
"script": "00143ce6c756ef2f35d61aab99d1619aab2f48da6987",
"address": "bcrt1q8nnvw4h09u6avx4tn8gkrx4t9ayd56v86q7ceg"
},
{
"value": 50131,
"script": "76a914e53103ac18b5d274dcea14e6b0c856182ce7021688ac",
"address": "n2QokZQd8Fn6a82vwXtndYy88HeUk3BZio"
},
{
"value": 34297096141,
"script": "0014f0ddfca1c6023538c032f6fb46a35703099319fe",
"address": "bcrt1q7rwlegwxqg6n3spj7ma5dg6hqvyexx07zmt40j"
}
],
"locktime": 0,
"hex": "0100000000010185a20e251420559981fc99fa34cb94b2d33e15c56f1bbacd0cd21468c330239d0300000000ffffffff03ab920000000000001600143ce6c756ef2f35d61aab99d1619aab2f48da6987d3c30000000000001976a914e53103ac18b5d274dcea14e6b0c856182ce7021688accd2744fc07000000160014f0ddfca1c6023538c032f6fb46a35703099319fe02473044022008765f15a62f283c06082dfea6a6f413eae4190dbbfd57efae1813432b66613e0220163b708d4e1ccd6a439da2d222f72e4231bdfd877fcdfb73ac85566e6358c559012103d2d0677a136821cb92361501570173e2c6b0d8b12e584737ffc991d2d1ccf02600000000",
"confirmations": 6
},
...
]
Returns transaction objects array by address with support for segwit. The
supported address types include p2pkh
, p2sh
, p2wpkh
, and p2wsh
.
Addresses with hundreds, thousands or millions of transactions, will need
to make multiple queries to request all transactions using the after
query parameter. If no results are found an empty array will be returned.
Results include both confirmed and unconfirmed transactions.
HTTP Request
GET /tx/address/:address
URL Parameters
Parameter | Description |
---|---|
:address | Bitcoin address (base58 or bech32). |
Query string
Parameter | Description |
---|---|
after string |
A txid to include transactions after, this is often the last txid of a previous query. |
limit int |
The maximum number of results to return. |
reverse boolean |
Reverse the order of transactions, default is false and from oldest to latest. |
RPC Calls - Node
curl $url \
-X POST \
--data '{ "method": "<method>", "params": [...] "id": "some-id" }'
bcoin-cli rpc <method> <params>
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
const result = await client.execute('<method>', [ <params> ]);
console.log(result);
})();
The above cURL command returns JSON structured like this:
{"result": resultObject ,"error": errorObject, "id": passedID}
Further examples will only include "result" part. CLI and Javascript calls return just the "result" or an error.
bcoin RPC calls mimic Bitcoin Core's RPC.
RPC Calls are accepted at:
POST /
Notes:
bcoin-cli rpc and Javascript will either return an error OR the result.
Javascript result will return the "result" part of the object, not the id or error
If a Javascript error is encountered it will be thrown instead of returned in JSON
Be sure to check the debug log for error reports as well!
POST Parameters RPC
Parameter | Description |
---|---|
method | Name of the RPC call |
params | Parameters accepted by method |
id | int Will be returned with the response (cURL only) |
stop
curl $url/ \
-H 'Content-Type: application/json' \
-X POST \
--data '{ "method": "stop" }'
bcoin-cli rpc stop
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
const result = await client.execute('stop');
console.log(result);
})();
The above command returns JSON "result" like this:
"Stopping."
Stops the running node.
Params
N. | Name | Default | Description |
---|---|---|---|
None. |
getinfo
curl $url \
-X POST \
--data '{ "method": "getinfo" }'
bcoin-cli rpc getinfo
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
const result = await client.execute('getinfo');
console.log(result);
})();
The above command returns JSON "result" like this:
{
"version": "2.0.0-dev",
"protocolversion": 70015,
"walletversion": 0,
"balance": 0,
"blocks": 533,
"timeoffset": 0,
"connections": 0,
"proxy": "",
"difficulty": 4.6565423739069247e-10,
"testnet": true,
"keypoololdest": 0,
"keypoolsize": 0,
"unlocked_until": 0,
"paytxfee": 0.0002,
"relayfee": 0.00001,
"errors": ""
}
Returns general info
Params
N. | Name | Default | Description |
---|---|---|---|
None. |
getmemoryinfo
curl $url \
-X POST \
--data '{ "method": "getmemoryinfo" }'
bcoin-cli rpc getmemoryinfo
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
const result = await client.execute('getmemoryinfo');
console.log(result);
})();
The above command returns JSON "result" like this:
{
"total": 72,
"jsHeap": 14,
"jsHeapTotal": 17,
"nativeHeap": 54,
"external": 12
}
Returns Memory usage info. Identical to node RPC call wallet-getmemoryinfo.
Params
N. | Name | Default | Description |
---|---|---|---|
None. |
setloglevel
curl $url \
-X POST \
--data '{
"method": "setloglevel",
"params": [ "none" ]
}'
bcoin-cli rpc setloglevel none
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
const result = await client.execute('setloglevel', [ 'none' ]);
console.log(result);
})();
The above command returns JSON "result" like this:
null
Change Log level of the running node.
Levels are: NONE
, ERROR
, WARNING
, INFO
, DEBUG
, SPAM
Params
N. | Name | Default | Description |
---|---|---|---|
1 | level | Required | Level for the logger |
validateaddress
let address;
address='mhX1xHbKGzw3r8FoN5bUkmRixHPEDNywxh"';
curl $url/ \
-X POST \
--data '{
"method": "validateaddress",
"params": [ "'$address'" ]
}'
bcoin-cli rpc validateaddress $address
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
const result = await client.execute('validateaddress', [ address ]);
console.log(result);
})();
The above command returns JSON "result" like this:
{
"isvalid": true,
"address": "mhX1xHbKGzw3r8FoN5bUkmRixHPEDNywxh",
"scriptPubKey": "76a91415f34e5cc7c4d7cc5a896611af8fb242847e003d88ac",
"isscript": false,
"iswitness": false
}
Validates address.
Params
N. | Name | Default | Description |
---|---|---|---|
1 | address | Required | Address to validate |
createmultisig
let nrequired, pubkey0, pubkey1, pubkey2;
nrequired=2;
pubkey0='02e3d6bb36b0261628101ee67abd89d678522dc1199912512f814e70803652f395';
pubkey1='03d7ded41bb871936bf4d411371b25d706c572f28ef8d2613b45392e9f9c4348a5';
pubkey2='034bc2280e68d3bdd0ef0664e0ad2949a467344d8e59e435fe2d9be81e39f70f76';
curl $url \
-X POST \
--data '{
"method": "createmultisig",
"params": [ '$nrequired', [ "'$pubkey0'", "'$pubkey1'", "'$pubkey2'" ] ]
}'
bcoin-cli rpc createmultisig $nrequired '[ "'$pubkey0'", "'$pubkey1'", "'$pubkey2'" ]'
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
const result = await client.execute('createmultisig', [ nrequired, [ pubkey0, pubkey1, pubkey2 ] ]);
console.log(result);
})();
The above command returns JSON "result" like this:
{
"address": "2NEn8sKGW2hZHF5Wyq4mJMAMqoPiGUMf3PB",
"redeemScript": "522102e3d6bb36b0261628101ee67abd89d678522dc1199912512f814e70803652f39521034bc2280e68d3bdd0ef0664e0ad2949a467344d8e59e435fe2d9be81e39f70f762103d7ded41bb871936bf4d411371b25d706c572f28ef8d2613b45392e9f9c4348a553ae"
}
create multisig address
Params
N. | Name | Default | Description |
---|---|---|---|
1 | nrequired | Required | Required number of approvals for spending |
2 | keyArray | Required | Array of public keys |
createwitnessaddress
let script;
script='5221021f1dbc575db95a44e016fe6ecf00231109e7799d9b1e007dbe8814017cf0d65c2102b3280e779a7c849f9d6460e926097fe4b0f6280fa6fd038ce8e1236a4688c358210315613667e3ebe065c0b8d86ae0443d97de56545bdf38c99a6ee584f300206d9a53ae';
curl $url \
-X POST \
--data '{
"method": "createwitnessaddress",
"params": [ "'$script'" ]
}'
bcoin-cli rpc createwitnessaddress $script
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
const result = await client.execute('createwitnessaddress', [ script ]);
console.log(result);
})();
The above command returns JSON "result" like this:
{
"address": "bcrt1qlfgqame3n0dt2ldjl2m9qjg6n2vut26jw3ezm25hqx9ez4m9wp5qer5sas",
"witnessScript": "0020fa500eef319bdab57db2fab650491a9a99c5ab5274722daa97018b9157657068"
}
Creates witness address.
Params
N. | Name | Default | Description |
---|---|---|---|
1 | script | Required | Bitcoin script. |
signmessagewithprivkey
let privkey, message;
privkey='cNmBeL4kpjLtNZcvjSezftq4ks6ajzZRi1z2AGpuBGy6XjxzytiQ';
message='hello';
curl $url \
-X POST \
--data '{
"method": "signmessagewithprivkey",
"params": [ "'$privkey'", "'$message'"]
}'
bcoin-cli rpc signmessagewithprivkey $privkey $message
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
const result = await client.execute('signmessagewithprivkey', [ privkey, message ]);
console.log(result);
})();
The above command returns JSON "result" like this:
"MEUCIQCsjaPbo1jOWBFdFGfmQnfQEdmRQP3vTi/wY2gbhxkEKgIgeZIm9+bMqZsiK4Ry5w3IgWycrcmKTzmuBtcvVCEguOM="
Signs message with private key.
Params
N. | Name | Default | Description |
---|---|---|---|
1 | privkey | Required | Private key |
1 | message | Required | Message you want to sign. |
verifymessage
let address, signature, message;
address='mhX1xHbKGzw3r8FoN5bUkmRixHPEDNywxh';
signature='MEUCIQCsjaPbo1jOWBFdFGfmQnfQEdmRQP3vTi/wY2gbhxkEKgIgeZIm9+bMqZsiK4Ry5w3IgWycrcmKTzmuBtcvVCEguOM=';
message='hello';
curl $url \
-X POST \
--data '{
"method": "verifymessage",
"params": [ "'$address'", "'$signature'", "$message" ]
}'
bcoin-cli rpc verifymessage $address $signature "$message"
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
const result = await client.execute('verifymessage', [ address, signature, message ]);
console.log(result);
})();
The above command returns JSON "result" like this:
true
Verify signature.
Params
N. | Name | Default | Description |
---|---|---|---|
1 | address | Required | Address of the signer |
2 | signature | Required | Signature of signed message |
3 | message | Required | Message that was signed |
setmocktime
let timestamp;
timestamp=1503058155;
curl $url \
-X POST \
--data '{
"method": "setmocktime",
"params": [ '$timestamp' ]
}'
bcoin-cli rpc setmocktime $timestamp
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
const result = await client.execute('setmocktime', [ timestamp ]);
console.log(result);
})();
The above command returns JSON "result" like this:
null
Changes network time (This is consensus-critical)
Params
N. | Name | Default | Description |
---|---|---|---|
1 | timestamp | Required | timestamp to change to |
RPC Calls - Chain
pruneblockchain
curl $url \
-X POST \
--data '{
"method": "pruneblockchain",
"params": []
}'
bcoin-cli rpc pruneblockchain
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
const result = await client.execute('pruneblockchain');
console.log(result);
})();
Prunes the blockchain, it will keep blocks specified in Network Configurations.
Default Prune Options
Network | keepBlocks | pruneAfter |
---|---|---|
main | 288 | 1000 |
testnet | 10000 | 1000 |
regtest | 10000 | 1000 |
Params
N. | Name | Default | Description |
---|---|---|---|
None. |
invalidateblock
let blockhash;
blockhash='52d7beaf4c7f392bef2744167c7f4db4bb4113b2635496edcf2d1c94128696aa';
curl $url \
-X POST \
--data '{
"method": "invalidateblock",
"params": [ "'$blockhash'" ]
}'
bcoin-cli rpc invalidateblock $blockhash
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
const result = await client.execute('invalidateblock', [ blockhash ]);
console.log(result);
})();
Invalidates the block in the chain. It will rewind network to blockhash and invalidate it.
It won't accept that block as valid. Invalidation will work while running, restarting node will remove invalid block from list.
Params
N. | Name | Default | Description |
---|---|---|---|
1 | blockhash | Required | Block's hash |
reconsiderblock
let blockhash;
blockhash='1896e628f8011b77ea80f4582c29c21b3376183683f587ee863050376add3891'
curl $url \
-X POST \
--data '{
"method": "reconsiderblock",
"params": [ "'$blockhash'" ]
}'
bcoin-cli rpc reconsiderblock $blockhash
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
const result = await client.execute('reconsiderblock', [ blockhash ]);
console.log(result);
})().catch((err) => {
console.error(err.stack);
});
This rpc command will remove block from invalid block set.
Params
N. | Name | Default | Description |
---|---|---|---|
1 | blockhash | Required | Block's hash |
RPC Calls - Block
getblockchaininfo
curl $url \
-X POST \
--data '{ "method": "getblockchaininfo" }'
bcoin-cli rpc getblockchaininfo
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
const result = await client.execute('getblockchaininfo');
console.log(result);
})();
The above command returns JSON "result" like this:
{
"chain": "regtest",
"blocks": 98,
"headers": 98,
"bestblockhash": "498d003ecfc60ee829cdc3640dc305583057d88e2c38a7d57dbe0f92aa2bb512",
"difficulty": 4.6565423739069247e-10,
"mediantime": 1527028558,
"verificationprogress": 0.9997162305340502,
"chainwork": "00000000000000000000000000000000000000000000000000000000000000c6",
"pruned": false,
"softforks": [
{
"id": "bip34",
"version": 2,
"reject": {
"status": false
}
},
{
"id": "bip66",
"version": 3,
"reject": {
"status": false
}
},
{
"id": "bip65",
"version": 4,
"reject": {
"status": false
}
}
],
"bip9_softforks": {
"csv": {
"status": "defined",
"bit": 0,
"startTime": 0,
"timeout": 4294967295
},
"segwit": {
"status": "defined",
"bit": 1,
"startTime": 0,
"timeout": 4294967295
},
"segsignal": {
"status": "defined",
"bit": 4,
"startTime": 4294967295,
"timeout": 4294967295
},
"testdummy": {
"status": "defined",
"bit": 28,
"startTime": 0,
"timeout": 4294967295
}
},
"pruneheight": null
}
Returns blockchain information.
Params
N. | Name | Default | Description |
---|---|---|---|
None. |
getbestblockhash
curl $url \
-X POST \
--data '{ "method": "getbestblockhash" }'
bcoin-cli rpc getbestblockhash
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
const result = await client.execute('getbestblockhash');
console.log(result);
})();
The above command returns JSON "result" like this:
"498d003ecfc60ee829cdc3640dc305583057d88e2c38a7d57dbe0f92aa2bb512"
Returns Block Hash of the tip.
Params
N. | Name | Default | Description |
---|---|---|---|
None. |
getblockcount
curl $url \
-X POST \
--data '{ "method": "getblockcount" }'
bcoin-cli rpc getblockcount
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
const result = await client.execute('getblockcount');
console.log(result);
})();
The above command returns JSON "result" like this:
98
Returns block count.
Params
N. | Name | Default | Description |
---|---|---|---|
None. |
getblock
let blockhash, details, verbose;
blockhash='498d003ecfc60ee829cdc3640dc305583057d88e2c38a7d57dbe0f92aa2bb512';
verbose=1;
details=0;
curl $url \
-X POST \
--data '{
"method": "getblock",
"params": [ "'$blockhash'", '$verbose', '$details' ]
}'
bcoin-cli rpc getblock $blockhash $verbose $details
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
const result = await client.execute('getblock', [ blockhash, verbose, details ]);
console.log(result);
})();
The above command returns JSON "result" like this:
{
"hash": "498d003ecfc60ee829cdc3640dc305583057d88e2c38a7d57dbe0f92aa2bb512",
"confirmations": 1,
"strippedsize": 197,
"size": 197,
"weight": 788,
"height": 98,
"version": 536870912,
"versionHex": "20000000",
"merkleroot": "674527b1b1b8604677a0b9e3f7a62fd733af9eba254d9f98748d3d0afdf35602",
"coinbase": "01620e6d696e65642062792062636f696e046d2df7a0080000000000000000",
"tx": [
"674527b1b1b8604677a0b9e3f7a62fd733af9eba254d9f98748d3d0afdf35602"
],
"time": 1527028559,
"mediantime": 1527028558,
"bits": 545259519,
"difficulty": 4.6565423739069247e-10,
"chainwork": "00000000000000000000000000000000000000000000000000000000000000c6",
"previousblockhash": "267bec5755cb8362828351a1bedb0de8c8ab37a58627070a79b7aa48d09c7276",
"nextblockhash": null
}
Returns information about block.
Params
N. | Name | Default | Description |
---|---|---|---|
1 | blockhash | Required | Hash of the block |
2 | verbose | true | If set to false, it will return hex of the block |
3 | details | false | If set to true, it will return transaction details too. |
getblockbyheight
let blockhash, details, verbose;
blockheight=50;
verbose=1;
details=0;
curl $url \
-X POST \
--data '{
"method": "getblockbyheight",
"params": [ '$blockheight', '$verbose', '$details' ]
}'
bcoin-cli rpc getblockbyheight $blockheight $verbose $details
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
const result = await client.execute('getblockbyheight', [ blockheight, verbose, details ]);
console.log(result);
})();
The above command returns JSON "result" like this:
{
"hash": "51726259de9560e1924f3cb554ad16e889b6170eb4d01d01f5a4ca8a81d1e318",
"confirmations": 49,
"strippedsize": 197,
"size": 197,
"weight": 788,
"height": 50,
"version": 536870912,
"versionHex": "20000000",
"merkleroot": "8e2d404a039a7a3e1768b161aa23546aab0444b73905bdd3d68b3d6f1769e8c0",
"coinbase": "01320e6d696e65642062792062636f696e04a829b925080000000000000000",
"tx": [
"8e2d404a039a7a3e1768b161aa23546aab0444b73905bdd3d68b3d6f1769e8c0"
],
"time": 1527028551,
"mediantime": 1527028550,
"bits": 545259519,
"difficulty": 4.6565423739069247e-10,
"chainwork": "0000000000000000000000000000000000000000000000000000000000000066",
"previousblockhash": "69eef02e5b7e2558f96a7e9ecb47dbbc4dd9fb1aa46cc22f36d8e7ee1edde33d",
"nextblockhash": "7f734e621cc3e08834063b9482aa89e0bcaf29e7812b83494f3891c7955958fb"
}
Returns information about block by height.
Params
N. | Name | Default | Description |
---|---|---|---|
1 | blockheight | Required | height of the block in the blockchain. |
2 | verbose | true | If set to false, it will return hex of the block. |
3 | details | false | If set to true, it will return transaction details too. |
getblockhash
let blockheight;
blockheight=50;
curl $url \
-X POST \
--data '{
"method": "getblockhash",
"params": [ '$blockheight' ]
}'
bcoin-cli rpc getblockhash $blockheight
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
const result = await client.execute('getblockhash', [ blockheight ]);
console.log(result);
})();
The above command returns JSON "result" like this:
"51726259de9560e1924f3cb554ad16e889b6170eb4d01d01f5a4ca8a81d1e318"
Returns block's hash given its height.
Params
N. | Name | Default | Description |
---|---|---|---|
1 | blockheight | Required | height of the block in the blockchain. |
getblockheader
let blockhash, verbose;
blockhash='51726259de9560e1924f3cb554ad16e889b6170eb4d01d01f5a4ca8a81d1e318';
verbose=1;
curl $url \
-X POST \
--data '{
"method": "getblockheader",
"params": [ "'$blockhash'", '$verbose' ]
}'
bcoin-cli rpc getblockheader $blockhash $verbose
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
const result = await client.execute('getblockheader', [ blockhash, verbose ]);
console.log(result);
})();
The above command returns JSON "result" like this:
{
"hash": "51726259de9560e1924f3cb554ad16e889b6170eb4d01d01f5a4ca8a81d1e318",
"confirmations": 49,
"height": 50,
"version": 536870912,
"versionHex": "20000000",
"merkleroot": "8e2d404a039a7a3e1768b161aa23546aab0444b73905bdd3d68b3d6f1769e8c0",
"time": 1527028551,
"mediantime": 1527028550,
"bits": 545259519,
"difficulty": 4.6565423739069247e-10,
"chainwork": "0000000000000000000000000000000000000000000000000000000000000066",
"previousblockhash": "69eef02e5b7e2558f96a7e9ecb47dbbc4dd9fb1aa46cc22f36d8e7ee1edde33d",
"nextblockhash": "7f734e621cc3e08834063b9482aa89e0bcaf29e7812b83494f3891c7955958fb"
}
Returns a block's header given its hash.
Params
N. | Name | Default | Description |
---|---|---|---|
1 | blockheight | Required | height of the block in the blockchain. |
2 | verbose | true | If set to false, it will return hex of the block. |
getchaintips
curl $url \
-X POST \
--data '{
"method": "getchaintips"
}'
bcoin-cli rpc getchaintips
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
const result = await client.execute('getchaintips');
console.log(result);
})();
Returns chaintips.
The above command returns JSON "result" like this:
[
{
"height": 98,
"hash": "498d003ecfc60ee829cdc3640dc305583057d88e2c38a7d57dbe0f92aa2bb512",
"branchlen": 0,
"status": "active"
}
...
]
Params
N. | Name | Default | Description |
---|---|---|---|
None. |
getdifficulty
curl $url \
-X POST \
--data '{
"method": "getdifficulty"
}'
bcoin-cli rpc getdifficulty
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
const result = await client.execute('getdifficulty');
console.log(result);
})();
The above command returns JSON "result" like this:
1048576
Params
N. | Name | Default | Description |
---|---|---|---|
None. |
RPC Calls - Mempool
getmempoolinfo
curl $url \
-X POST \
--data '{
"method": "getmempoolinfo"
}'
bcoin-cli rpc getmempoolinfo
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
const result = await client.execute('getmempoolinfo');
console.log(result);
})();
The above command returns JSON "result" like this:
{
"size": 5,
"bytes": 14120,
"usage": 14120,
"maxmempool": 100000000,
"mempoolminfee": 0.00001
}
Returns informations about mempool.
Params
N. | Name | Default | Description |
---|---|---|---|
None. |
getmempoolancestors
let txhash, verbose;
txhash='0e690d6655767c8b388e7403d13dc9ebe49b68e3bd46248c840544f9da87d1e8';
verbose=1;
curl $url \
-X POST \
--data '{
"method": "getmempoolancestors",
"params": [ "'$txhash'", '$verbose' ]
}'
bcoin-cli rpc getmempoolancestors $txhash $verbose
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
const result = await client.execute('getmempoolancestors', [ txhash, verbose ]);
console.log(result);
})();
The above command returns JSON "result" like this:
verbose=1
[
{
"size": 226,
"fee": 0.0000454,
"modifiedfee": 0,
"time": 1527103521,
"height": 100,
"startingpriority": 0,
"currentpriority": 0,
"descendantcount": 1,
"descendantsize": 451,
"descendantfees": 9080,
"ancestorcount": 2,
"ancestorsize": 0,
"ancestorfees": 0,
"depends": [
"7922c798ea02c3957393bb7c373ba89e0a337d049564aeb64a9fd2b8d4998795"
]
},
{
"size": 225,
"fee": 0.0000454,
"modifiedfee": 0,
"time": 1527103519,
"height": 100,
"startingpriority": 0,
"currentpriority": 0,
"descendantcount": 2,
"descendantsize": 676,
"descendantfees": 13620,
"ancestorcount": 1,
"ancestorsize": 0,
"ancestorfees": 0,
"depends": [
"d54e576d30f9014ffb06a31b9e36f2f5bb360e8c54980188ee4b09a979e092c2"
]
},
...
]
verbose=0
[
"56ab7663c80cb6ffc9f8a4b493d77b2e6f52ae8ff64eefa8899c2065922665c8"
]
returns all in-mempool ancestors for a transaction in the mempool.
Params
N. | Name | Default | Description |
---|---|---|---|
1 | txhash | Required | Transaction Hash |
2 | verbose | false | False returns only tx hashs, true - returns dependency tx info |
getmempooldescendants
let txhash, verbose;
txhash='7922c798ea02c3957393bb7c373ba89e0a337d049564aeb64a9fd2b8d4998795';
verbose=1;
curl $url \
-X POST \
--data '{
"method": "getmempooldescendants",
"params": [ "'$txhash'", '$verbose' ]
}'
bcoin-cli rpc getmempooldescendants $txhash $verbose
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
const result = await client.execute('getmempooldescendants', [ txhash, verbose ]);
console.log(result);
})();
The above command returns JSON "result" like this:
verbose=1
[
{
"size": 226,
"fee": 0.0000454,
"modifiedfee": 0,
"time": 1527103521,
"height": 100,
"startingpriority": 0,
"currentpriority": 0,
"descendantcount": 1,
"descendantsize": 451,
"descendantfees": 9080,
"ancestorcount": 2,
"ancestorsize": 0,
"ancestorfees": 0,
"depends": [
"7922c798ea02c3957393bb7c373ba89e0a337d049564aeb64a9fd2b8d4998795"
]
},
{
"size": 225,
"fee": 0.0000454,
"modifiedfee": 0,
"time": 1527103523,
"height": 100,
"startingpriority": 0,
"currentpriority": 0,
"descendantcount": 0,
"descendantsize": 225,
"descendantfees": 4540,
"ancestorcount": 3,
"ancestorsize": 0,
"ancestorfees": 0,
"depends": [
"e66c029a755d326f14cc32f485ea43e705ef59ed4a8061e8f47e681fbdefefea"
]
}
]
verbose=0
[
"939a3b8485b53a718d89e7e4412473b3762fa1d9bbd555fc8b01e73be0ab1881"
]
returns all in-mempool descendants for a transaction in the mempool.
Params
N. | Name | Default | Description |
---|---|---|---|
1 | txhash | Required | Transaction hash |
2 | verbose | false | False returns only tx hashs, true - returns dependency tx info |
getmempoolentry
let txhash;
txhash='0e690d6655767c8b388e7403d13dc9ebe49b68e3bd46248c840544f9da87d1e8';
curl $url \
-X POST \
--data '{
"method": "getmempoolentry",
"params": [ "'$txhash'" ]
}'
bcoin-cli rpc getmempoolentry $txhash
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
const result = await client.execute('getmempoolentry', [ txhash ]);
console.log(result);
})();
The above command returns JSON "result" like this:
{
"size": 225,
"fee": 0.0000454,
"modifiedfee": 0,
"time": 1527103523,
"height": 100,
"startingpriority": 0,
"currentpriority": 0,
"descendantcount": 0,
"descendantsize": 225,
"descendantfees": 4540,
"ancestorcount": 3,
"ancestorsize": 0,
"ancestorfees": 0,
"depends": [
"e66c029a755d326f14cc32f485ea43e705ef59ed4a8061e8f47e681fbdefefea"
]
}
returns mempool transaction info by its hash.
Params
N. | Name | Default | Description |
---|---|---|---|
1 | txhash | Required | Transaction Hash |
getrawmempool
let verbose;
verbose=1;
curl $url \
-X POST \
--data '{
"method": "getrawmempool",
"params": [ '$verbose' ]
}'
bcoin-cli rpc getrawmempool $verbose
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
const result = await client.execute('getrawmempool', [ verbose ]);
console.log(result);
})();
The above command returns JSON "result" like this:
{
"d54e576d30f9014ffb06a31b9e36f2f5bb360e8c54980188ee4b09a979e092c2": {
"size": 225,
"fee": 0.0000454,
"modifiedfee": 0,
"time": 1527103516,
"height": 100,
"startingpriority": 2200000000,
"currentpriority": 2200000000,
"descendantcount": 3,
"descendantsize": 901,
"descendantfees": 18160,
"ancestorcount": 0,
"ancestorsize": 0,
"ancestorfees": 0,
"depends": []
},
"7922c798ea02c3957393bb7c373ba89e0a337d049564aeb64a9fd2b8d4998795": {
"size": 225,
"fee": 0.0000454,
"modifiedfee": 0,
"time": 1527103519,
"height": 100,
"startingpriority": 0,
"currentpriority": 0,
"descendantcount": 2,
"descendantsize": 676,
"descendantfees": 13620,
"ancestorcount": 1,
"ancestorsize": 0,
"ancestorfees": 0,
"depends": [
"d54e576d30f9014ffb06a31b9e36f2f5bb360e8c54980188ee4b09a979e092c2"
]
},
...
}
Returns mempool detailed information (on verbose). Or mempool tx list.
Params
N. | Name | Default | Description |
---|---|---|---|
1 | verbose | false | False returns only tx hashs, true - returns full tx info |
prioritisetransaction
let txhash, priorityDelta, feeDelta;
txhash='0e690d6655767c8b388e7403d13dc9ebe49b68e3bd46248c840544f9da87d1e8';
priorityDelta=1000;
feeDelta=1000;
curl $url \
-X POST \
--data '{
"method": "prioritisetransaction",
"params": [ "'$txhash'", '$priorityDelta', '$feeDelta' ]
}'
bcoin-cli rpc prioritisetransaction $txhash $priorityDelta $feeDelta
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
const result = await client.execute('prioritisetransaction', [ txhash, priorityDelta, feeDelta ]);
console.log(result);
})();
The above command returns JSON "result" like this:
true
Prioritises the transaction.
Note: changing fee or priority will only trick local miner (using this mempool) into accepting Transaction(s) into the block. (even if Priority/Fee doen't qualify)
N. | Name | Default | Description |
---|---|---|---|
1 | txhash | Required | Transaction hash |
2 | priority delta | Required | Virtual priority to add/subtract to the entry |
3 | fee delta | Required | Virtual fee to add/subtract to the entry |
estimatefee
let nblocks;
nblocks=10;
curl $url \
-X POST \
--data '{
"method": "estimatefee",
"params": [ '$nblocks' ]
}'
bcoin-cli rpc estimatefee $nblocks
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
const result = await client.execute('estimatefee', [ nblocks ]);
console.log(result);
})();
The above command returns JSON "result" like this:
0.001
Estimates fee to be paid for transaction.
Params
N. | Name | Default | Description |
---|---|---|---|
1 | nblocks | 1 | Number of blocks to check for estimation. |
estimatepriority
let nblocks;
nblocks=10;
curl $url \
-X POST \
--data '{
"method": "estimatepriority",
"params": [ '$nblocks' ]
}'
bcoin-cli rpc estimatepriority $nblocks
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
const result = await client.execute('estimatepriority', [ nblocks ]);
console.log(result);
})();
The above command returns JSON "result" like this:
718158904.3501
estimates the priority (coin age) that a transaction needs in order to be included within a certain number of blocks as a free high-priority transaction.
Params
N. | Name | Default | Description |
---|---|---|---|
1 | nblocks | 1 | Number of blocks to check for estimation. |
estimatesmartfee
let nblocks;
nblocks=10;
curl $url \
-X POST \
--data '{
"method": "estimatesmartfee",
"params": [ '$nblocks' ]
}'
bcoin-cli rpc estimatesmartfee $nblocks
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
const result = await client.execute('estimatesmartfee', [ nblocks ]);
console.log(result);
})();
The above command returns JSON "result" like this:
{
"fee": 0.001,
"blocks": 10
}
Estimates smart fee to be paid for transaction.
Params
N. | Name | Default | Description |
---|---|---|---|
1 | nblocks | 1 | Number of blocks to check for estimation. |
estimatesmartpriority
let nblocks;
nblocks=10;
curl $url \
-X POST \
--data '{
"method": "estimatesmartpriority",
"params": [ '$nblocks' ]
}'
bcoin-cli rpc estimatesmartpriority $nblocks
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
const result = await client.execute('estimatesmartpriority', [ nblocks ]);
console.log(result);
})();
The above command returns JSON "result" like this:
{
"priority": 718158904.3501,
"blocks": 10
}
estimates smart priority (coin age) that a transaction needs in order to be included within a certain number of blocks as a free high-priority transaction.
Params
N. | Name | Default | Description |
---|---|---|---|
1 | nblocks | 1 | Number of blocks to check for estimation. |
RPC Calls - Transactions
gettxout
let txhash, index, includemempool;
txhash='1ddd325274274f8a2a62e96c3f3fd5f7ecbca4a3ba24c039692e3068edd904a7';
index=0;
includemempool=1;
curl $url \
-X POST \
--data '{
"method": "gettxout",
"params": [ "'$txhash'", '$index', '$includemempool' ]
}'
bcoin-cli rpc gettxout $txhash $index $includemempool
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
const result = await client.execute('gettxout', [ txhash, index, includemempool ]);
console.log(result);
})();
The above command returns JSON "result" like this:
{
"bestblock": "6070a949eb9dcc36c416fe52a499d4cf2c7ad699ddeb2e358a9063a452c72523",
"confirmations": 4,
"value": 0.00024823,
"scriptPubKey": {
"asm": "OP_DUP OP_HASH160 94fe559c42b11736d0cab28d550b8972ccfbef3d OP_EQUALVERIFY OP_CHECKSIG",
"hex": "76a91494fe559c42b11736d0cab28d550b8972ccfbef3d88ac",
"type": "PUBKEYHASH",
"reqSigs": 1,
"addresses": [
"mu6kyujE3JeyPZYHwdBdBVrv6V5ReWwz6a"
]
},
"version": 1,
"coinbase": false
}
Get outpoint of the transaction.
Params
N. | Name | Default | Description |
---|---|---|---|
1 | txid | Required | Transaction hash |
2 | index | Required | Index of the Outpoint tx. |
3 | includemempool | true | Whether to include mempool transactions. |
gettxoutsetinfo
curl $url \
-X POST \
--data '{
"method": "gettxoutsetinfo",
"params": []
}'
bcoin-cli rpc gettxoutsetinfo
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
const result = await client.execute('gettxoutsetinfo');
console.log(result);
})();
The above command returns JSON "result" like this:
{
"height": 100,
"bestblock": "0e11d85b2081b84e131ba6692371737e6bb2aa7bc6d16e92954ffb1f9ad762e5",
"transactions": 101,
"txouts": 100,
"bytes_serialized": 0,
"hash_serialized": 0,
"total_amount": 5000
}
Returns information about UTXO's from Chain.
Params
N. | Name | Default | Description |
---|---|---|---|
None. |
getrawtransaction
let txhash, verbose;
txhash='0e690d6655767c8b388e7403d13dc9ebe49b68e3bd46248c840544f9da87d1e8';
verbose=0;
curl $url \
-X POST \
--data '{
"method": "getrawtransaction",
"params": [ "'$txhash'", '$verbose' ]
}'
bcoin-cli rpc getrawtransaction $txhash $verbose
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
const result = await client.execute('getrawtransaction', [ txhash, verbose ]);
console.log(result);
})();
The above command returns JSON "result" like this:
"0100000001eaefefbd1f687ef4e861804aed59ef05e743ea85f432cc146f325d759a026ce6010000006a4730440220718954e28983c875858b5a0094df4607ce2e7c6e9ffea47f3876792b01755c1202205e2adc7c32ff64aaef6d26045f96181e8741e560b6f3a8ef2f4ffd2892add656012103142355370728640592109c3d2bf5592020a6b9226303c8bc98ab2ebcadf057abffffffff02005a6202000000001976a914fe7e0711287688b33b9a5c239336c4700db34e6388ac10ca0f24010000001976a914af92ad98c7f77559f96430dfef2a6805b87b24f888ac00000000"
Returns raw transaction
Params
N. | Name | Default | Description |
---|---|---|---|
1 | txhash | Required | Transaction hash |
2 | verbose | false | Returns json formatted if true |
decoderawtransaction
let rawtx;
rawtx='0100000001eaefefbd1f687ef4e861804aed59ef05e743ea85f432cc146f325d759a026ce6010000006a4730440220718954e28983c875858b5a0094df4607ce2e7c6e9ffea47f3876792b01755c1202205e2adc7c32ff64aaef6d26045f96181e8741e560b6f3a8ef2f4ffd2892add656012103142355370728640592109c3d2bf5592020a6b9226303c8bc98ab2ebcadf057abffffffff02005a6202000000001976a914fe7e0711287688b33b9a5c239336c4700db34e6388ac10ca0f24010000001976a914af92ad98c7f77559f96430dfef2a6805b87b24f888ac00000000';
curl $url \
-X POST \
--data '{
"method": "decoderawtransaction",
"params": [ "'$rawtx'" ]
}'
bcoin-cli rpc decoderawtransaction $rawtx
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
const result = await client.execute('decoderawtransaction', [ rawtx ]);
console.log(result);
})();
The above command returns JSON "result" like this:
{
"txid": "0e690d6655767c8b388e7403d13dc9ebe49b68e3bd46248c840544f9da87d1e8",
"hash": "0e690d6655767c8b388e7403d13dc9ebe49b68e3bd46248c840544f9da87d1e8",
"size": 225,
"vsize": 225,
"version": 1,
"locktime": 0,
"vin": [
{
"txid": "e66c029a755d326f14cc32f485ea43e705ef59ed4a8061e8f47e681fbdefefea",
"scriptSig": {
"asm": "30440220718954e28983c875858b5a0094df4607ce2e7c6e9ffea47f3876792b01755c1202205e2adc7c32ff64aaef6d26045f96181e8741e560b6f3a8ef2f4ffd2892add65601 03142355370728640592109c3d2bf5592020a6b9226303c8bc98ab2ebcadf057ab",
"hex": "4730440220718954e28983c875858b5a0094df4607ce2e7c6e9ffea47f3876792b01755c1202205e2adc7c32ff64aaef6d26045f96181e8741e560b6f3a8ef2f4ffd2892add656012103142355370728640592109c3d2bf5592020a6b9226303c8bc98ab2ebcadf057ab"
},
"sequence": 4294967295,
"vout": 1
}
],
"vout": [
{
"value": 0.4,
"n": 0,
"scriptPubKey": {
"asm": "OP_DUP OP_HASH160 fe7e0711287688b33b9a5c239336c4700db34e63 OP_EQUALVERIFY OP_CHECKSIG",
"hex": "76a914fe7e0711287688b33b9a5c239336c4700db34e6388ac",
"type": "PUBKEYHASH",
"reqSigs": 1,
"addresses": [
"n4iauL838sLmADwTwfRkeejc4jCs8UJsTE"
]
}
},
{
"value": 48.9998184,
"n": 1,
"scriptPubKey": {
"asm": "OP_DUP OP_HASH160 af92ad98c7f77559f96430dfef2a6805b87b24f8 OP_EQUALVERIFY OP_CHECKSIG",
"hex": "76a914af92ad98c7f77559f96430dfef2a6805b87b24f888ac",
"type": "PUBKEYHASH",
"reqSigs": 1,
"addresses": [
"mwXJFzrRk86NoH7uKytkSq2rbCkV9tgAgp"
]
}
}
],
"blockhash": null,
"confirmations": 0,
"time": 0,
"blocktime": 0
}
Decodes raw tx and provide chain info.
Params
N. | Name | Default | Description |
---|---|---|---|
1 | rawtx | Required | Raw transaction hex |
decodescript
let script;
script='76a914af92ad98c7f77559f96430dfef2a6805b87b24f888ac';
curl $url \
-X POST \
--data '{
"method": "decodescript",
"params": [ "'$script'" ]
}'
bcoin-cli rpc decodescript $script
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
const result = await client.execute('decodescript', [ script ]);
console.log(result);
})();
The above command returns JSON "result" like this:
{
"asm": "OP_DUP OP_HASH160 af92ad98c7f77559f96430dfef2a6805b87b24f8 OP_EQUALVERIFY OP_CHECKSIG",
"type": "PUBKEYHASH",
"reqSigs": 1,
"addresses": [
"mwXJFzrRk86NoH7uKytkSq2rbCkV9tgAgp"
],
"p2sh": "2N8Hd7HBwFoqq3hHvSLQ1XWEKLgkhVjxisY"
}
Decodes script
Params
N. | Name | Default | Description |
---|---|---|---|
1 | script | Required | Script hex |
sendrawtransaction
let rawtx;
rawtx='0100000001eaefefbd1f687ef4e861804aed59ef05e743ea85f432cc146f325d759a026ce6010000006a4730440220718954e28983c875858b5a0094df4607ce2e7c6e9ffea47f3876792b01755c1202205e2adc7c32ff64aaef6d26045f96181e8741e560b6f3a8ef2f4ffd2892add656012103142355370728640592109c3d2bf5592020a6b9226303c8bc98ab2ebcadf057abffffffff02005a6202000000001976a914fe7e0711287688b33b9a5c239336c4700db34e6388ac10ca0f24010000001976a914af92ad98c7f77559f96430dfef2a6805b87b24f888ac00000000';
curl $url \
-X POST \
--data '{
"method": "sendrawtransaction",
"params": [ "'$rawtx'" ]
}'
bcoin-cli rpc sendrawtransaction $rawtx
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
const result = await client.execute('sendrawtransaction', [ rawtx ]);
console.log(result);
})();
"0e690d6655767c8b388e7403d13dc9ebe49b68e3bd46248c840544f9da87d1e8"
Sends raw transaction without verification
Params
N. | Name | Default | Description |
---|---|---|---|
1 | rawtx | Required | Raw transaction hex |
createrawtransaction
let txhash, txindex, amount, address, data;
txhash='0e690d6655767c8b388e7403d13dc9ebe49b68e3bd46248c840544f9da87d1e8';
txindex=1;
amount=48.99900000;
address='mhX1xHbKGzw3r8FoN5bUkmRixHPEDNywxh';
data='';
curl $url \
-X POST \
--data '{
"method": "createrawtransaction",
"params": [
[{ "txid": "'$txhash'", "vout": '$txindex' }],
{ "'$address'": '$amount', "data": "'$data'" }
]
}'
bcoin-cli rpc createrawtransaction \
'[{ "txid": "'$txhash'", "vout": '$txindex' }]' \
'{ "'$address'": '$amount', "data": "'$data'" }'
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
const sendTo = {
data: data
};
sendTo[address] = amount;
const result = await client.execute('createrawtransaction', [ [{ txid: txhash, vout: txindex }], sendTo]);
console.log(result);
})();
The above command returns JSON "result" like this:
"0100000001e8d187daf94405848c2446bde3689be4ebc93dd103748e388b7c7655660d690e0100000000ffffffff02608a0e24010000001976a914c1325e8fb60bd71d23532c39b4c9e743a2cc764988ac0000000000000000026a0000000000"
Creates raw, unsigned transaction without any formal verification.
Params
N. | Name | Default | Description |
---|---|---|---|
1 | outpoints | Required | Outpoint list |
1.1 | txid | Transaction Hash | |
1.2 | vout | Transaction Outpoint Index | |
1.3 | sequence | Sequence number for input | |
2 | sendto | Required | List of addresses with amounts that we are sending to. |
2.1 | address | 0 | address: amount key pairs (string: float) |
2.2 | data | nullData | Data output (added as OP_RETURN ) |
3 | locktime | earliest time a transaction can be added |
signrawtransaction
let rawtx, txhash, txindex, scriptPubKey, amount, privkey;
rawtx='0100000001e8d187daf94405848c2446bde3689be4ebc93dd103748e388b7c7655660d690e0100000000ffffffff02608a0e24010000001976a914c1325e8fb60bd71d23532c39b4c9e743a2cc764988ac0000000000000000026a0000000000';
txhash='0e690d6655767c8b388e7403d13dc9ebe49b68e3bd46248c840544f9da87d1e8';
txindex=1;
scriptPubKey='76a914af92ad98c7f77559f96430dfef2a6805b87b24f888ac';
amount=48.99900000;
privkey='cNmBeL4kpjLtNZcvjSezftq4ks6ajzZRi1z2AGpuBGy6XjxzytiQ';
curl $url \
-X POST \
--data '{
"method": "signrawtransaction",
"params": [
"'$rawtx'",
[{
"txid": "'$txhash'",
"vout": '$txindex',
"scriptPubKey": "'$scriptPubKey'",
"amount": '$amount'
}],
[ "'$privkey'" ]
]
}'
bcoin-cli rpc signrawtransaction $rawtx \
'[{ "txid": "'$txhash'", "vout": '$txindex', "scriptPubKey": "'$scriptPubKey'", "amount": '$amount' }]' \
'[ "'$privkey'" ]'
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
const result = await client.execute('signrawtransaction', [ rawtx,
[{
txid: txhash,
vout: txindex,
scriptPubKey: scriptPubKey,
amount: amount
}],
[ privkey ]
]);
console.log(result);
})();
The above command returns JSON "result" like this:
{
"hex": "0100000001e8d187daf94405848c2446bde3689be4ebc93dd103748e388b7c7655660d690e010000006a47304402205088870d469e5a878c54186e971cdc59d4e0c74f1c88709f584590ba76a9b97002202b4810a122fc4977e5a77c80dc68d4ffa73d22dbf385e46241dda6bddfd7993901210284a937f256393b3ba686556e90bd000706600bdbee4169abd092f392689307d2ffffffff02608a0e24010000001976a914c1325e8fb60bd71d23532c39b4c9e743a2cc764988ac0000000000000000026a0000000000",
"complete": true
}
Signs raw transaction
Params
N. | Name | Default | Description |
---|---|---|---|
1 | rawtx | Required | raw tx |
2 | inputs | Required | Coins you're going to spend |
2.1 | txid | Transaction Hash | |
2.2 | vout | Transaction Outpoint Index | |
2.3 | scriptPubKey | script with pubkey you are going to sign | |
2.4 | redeemScript | redeemScript if tx is P2SH | |
2.5 | amount | value of output in BTC | |
3 | privkeylist | List of private keys | |
4 | sighashtype | Type of signature hash |
gettxoutproof
let txid0, txid1;
txid0='0e690d6655767c8b388e7403d13dc9ebe49b68e3bd46248c840544f9da87d1e8';
txid1='e66c029a755d326f14cc32f485ea43e705ef59ed4a8061e8f47e681fbdefefea';
curl $url \
-X POST \
--data '{
"method": "gettxoutproof",
"params": [ ["'$txid0'", "'$txid1'"] ]
}'
bcoin-cli rpc gettxoutproof '[ "'$txid0'", "'$txid1'" ]'
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
const result = await client.execute('gettxoutproof', [ [ txid0, txid1 ] ]);
console.log(result);
})();
The above command returns JSON "result" like this:
"00000020e562d79a1ffb4f95926ed1c67baab26b7e73712369a61b134eb881205bd8110ef08c63626ea13ca11fddad4f2c0a2b67354efdcd50f769b73330af205dcdd054cbd3055bffff7f20010000000500000004ae4be9cd199b09f605119820680eb23462746e98fbc2b0c635643f00b34c3cd8958799d4b8d29f4ab6ae6495047d330a9ea83b377cbb937395c302ea98c72279eaefefbd1f687ef4e861804aed59ef05e743ea85f432cc146f325d759a026ce6e8d187daf94405848c2446bde3689be4ebc93dd103748e388b7c7655660d690e02eb01"
Checks if transactions are within block. Returns proof of transaction inclusion (raw MerkleBlock).
Params
N. | Name | Default | Description |
---|---|---|---|
1 | txidlist | Required | array of transaction hashes |
2 | blockhash | Based on TX | Block hash |
verifytxoutproof
let proof;
proof='00000020e562d79a1ffb4f95926ed1c67baab26b7e73712369a61b134eb881205bd8110ef08c63626ea13ca11fddad4f2c0a2b67354efdcd50f769b73330af205dcdd054cbd3055bffff7f20010000000500000004ae4be9cd199b09f605119820680eb23462746e98fbc2b0c635643f00b34c3cd8958799d4b8d29f4ab6ae6495047d330a9ea83b377cbb937395c302ea98c72279eaefefbd1f687ef4e861804aed59ef05e743ea85f432cc146f325d759a026ce6e8d187daf94405848c2446bde3689be4ebc93dd103748e388b7c7655660d690e02eb01';
curl $url \
-X POST \
--data '{
"method": "verifytxoutproof",
"params": [ "'$proof'" ]
}'
bcoin-cli rpc verifytxoutproof $proof
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
const result = await client.execute('verifytxoutproof', [ proof ]);
console.log(result);
})();
The above command returns JSON "result" like this:
[
"e66c029a755d326f14cc32f485ea43e705ef59ed4a8061e8f47e681fbdefefea",
"0e690d6655767c8b388e7403d13dc9ebe49b68e3bd46248c840544f9da87d1e8"
]
Checks the proof for transaction inclusion. Returns transaction hash if valid.
Params
N. | Name | Default | Description |
---|---|---|---|
1 | proof | Required | Proof of transaction inclusion (raw MerkleBlock). |
RPC Calls - Mining
Note: many mining-related RPC calls require bcoin
to be started with the flag --coinbase-address
designating a comma-separated list of payout addresses, randomly selected during block creation
getnetworkhashps
let blocks, height;
blocks=120;
height=1000000;
curl $url \
-X POST \
--data '{
"method": "getnetworkhashps",
"params": [ '$blocks', '$height' ]
}'
bcoin-cli rpc getnetworkhashps $blocks $height
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
const result = await client.execute('getnetworkhashps', [ blocks, height ]);
console.log(result);
})();
The above command returns JSON "result" like this:
453742051556.55084
Returns the estimated current or historical network hashes per second, based on last blocks
.
Params
N. | Name | Default | Description |
---|---|---|---|
1 | blocks | 120 | Number of blocks to lookup. |
2 | height | 1 | Starting height for calculations. |
getmininginfo
curl $url \
-X POST \
--data '{
"method": "getmininginfo",
"params": []
}'
bcoin-cli rpc getmininginfo
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
const result = await client.execute('getmininginfo', []);
console.log(result);
})();
The above command returns JSON "result" like this:
{
"blocks": 101,
"currentblocksize": 0,
"currentblockweight": 0,
"currentblocktx": 0,
"difficulty": 0,
"errors": "",
"genproclimit": 0,
"networkhashps": 8.766601909687916e-7,
"pooledtx": 0,
"testnet": true,
"chain": "regtest",
"generate": false
}
Returns mining info.
Note: currentblocksize, currentblockweight, currentblocktx, difficulty are returned when there's active work.
generate - is true when bcoin
itself is mining.
Params
N. | Name | Default | Description |
---|---|---|---|
None. |
getwork
curl $url \
-X POST \
--data '{
"method": "getwork",
"params": []
}'
bcoin-cli rpc getwork
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
const result = await client.execute('getwork');
console.log(result);
})();
The above command returns JSON "result" like this:
{
"data": "200000001072adb70d69fc2b5a6601eeaaa54e31b7c57417028b429a0b98aa374413799c12c94351d52da980c8fa67eaddf6053dee141b14f4e6a3e10bb7db21c0d533b05b05ec88207fffff00000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000",
"target": "0000000000000000000000000000000000000000000000000000000000ffff7f",
"height": 102
}
Returns hashing work to be solved by miner. Or submits solved block.
Params
N. | Name | Default | Description |
---|---|---|---|
1 | data | Data to be submitted to the network. |
getworklp
# Because there is a request timeout set on CLI http requests.
# without manually adjusting the timeout (or receiving a new transaction on the current
# network) this call will timeout before the request is complete.
curl $url \
-X POST \
--data '{
"method": "getworklp",
"params": []
}'
# Because there is a request timeout set on CLI http requests.
# without manually adjusting the timeout (or receiving a new transaction on the current
# network) this call will timeout before the request is complete.
bcoin-cli rpc getworklp
// Because there is a request timeout set on CLI http requests.
// without manually adjusting the timeout (or receiving a new transaction on the current
// network) this call will timeout before the request is complete.
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
const result = await client.execute('getworklp');
console.log(result);
})();
The above command returns JSON "result" like this:
{
"data": "200000001072adb70d69fc2b5a6601eeaaa54e31b7c57417028b429a0b98aa374413799c09e651f7a930c198755993bf7348fd807836d1560b6baded56857def309a03855b05ecf1207fffff00000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000",
"target": "0000000000000000000000000000000000000000000000000000000000ffff7f",
"height": 102
}
Long polling for new work.
Returns new work, whenever new TX is received in the mempool or new block has been discovered. So miner can restart mining on new data.
Params
N. | Name | Default | Description |
---|---|---|---|
None. |
getblocktemplate
curl $url \
-X POST \
--data '{
"method": "getblocktemplate",
"params": []
}'
bcoin-cli rpc getblocktemplate
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
const result = await client.execute('getblocktemplate');
console.log(result);
})();
The above command returns JSON "result" like this:
{
"capabilities": [
"proposal"
],
"mutable": [
"time",
"transactions",
"prevblock"
],
"version": 536870912,
"rules": [],
"vbavailable": {},
"vbrequired": 0,
"height": 102,
"previousblockhash": "4413799c0b98aa37028b429ab7c57417aaa54e315a6601ee0d69fc2b1072adb7",
"target": "7fffff0000000000000000000000000000000000000000000000000000000000",
"bits": "207fffff",
"noncerange": "00000000ffffffff",
"curtime": 1527115118,
"mintime": 1527103506,
"maxtime": 1527122318,
"expires": 1527122318,
"sigoplimit": 20000,
"sizelimit": 1000000,
"longpollid": "4413799c0b98aa37028b429ab7c57417aaa54e315a6601ee0d69fc2b1072adb700000003",
"submitold": false,
"coinbaseaux": {
"flags": "6d696e65642062792062636f696e"
},
"coinbasevalue": 5000016600,
"transactions": [
{
"data": "01000000017efbcc72a5733c7b9bcb1b763a81480425425bc10a4157e9553f0fd32eda710b000000006a47304402206a04f6c4fa9be51206e3fb9a48c5960198d7b27ce1b7c1915a4535e63ffdc60b022050796a1e0c09f60384379c2a477bedbce548cbaaa0e42183b737115b4ea77c5d0121020987e993a946a058d0969bd296b08783229fd1a0a779d8bfb376ebe30a164e89ffffffff02005a6202000000001976a914fe7e0711287688b33b9a5c239336c4700db34e6388ac4486a327010000001976a914b1a4d7b11dad88f767d0ad894e11b53d766400a888ac00000000",
"txid": "7444ea74eaee01ed7c7871f355bb5cb244a4ef2c05ae16ad49b4b06cbf34f539",
"hash": "7444ea74eaee01ed7c7871f355bb5cb244a4ef2c05ae16ad49b4b06cbf34f539",
"depends": [],
"fee": 4540,
"sigops": 2,
"weight": 900
},
{
"data": "0100000002e8d187daf94405848c2446bde3689be4ebc93dd103748e388b7c7655660d690e000000006b483045022100eeae86adccb31514ca25d3ddf265b21de05230fd6c93db7fbd185c133647fe640220392c3b5ebd50f4f0538c686b88e1d7051a81c2e5dff8c96f2a5c61154fa3c43a0121032cbf9d9b3beb61004d158ae897257fab6ce46efbad6b1e51b4a64e74732c3b4dffffffffeaefefbd1f687ef4e861804aed59ef05e743ea85f432cc146f325d759a026ce6000000006a47304402203e3ca4312bee4c465e6d5fcaee7aae1301d043444fe7a8f20b7df9f555ca1b4f022060104fc66cdb68af8cc674e94bb1900328cda94a8f6580d12ef0ad9810f24a290121032cbf9d9b3beb61004d158ae897257fab6ce46efbad6b1e51b4a64e74732c3b4dffffffff0220a6c901000000001976a914253d160f8a14c9586c9204553b50b279c71d2c8888ac005a6202000000001976a914fe7e0711287688b33b9a5c239336c4700db34e6388ac00000000",
"txid": "c0f7dc9540629f6e1623cb25edba1d07cab4dd441b71cd247e629a6d817ed1ad",
"hash": "c0f7dc9540629f6e1623cb25edba1d07cab4dd441b71cd247e629a6d817ed1ad",
"depends": [],
"fee": 7520,
"sigops": 2,
"weight": 1492
},
{
"data": "0100000001e8d187daf94405848c2446bde3689be4ebc93dd103748e388b7c7655660d690e010000006b483045022100977567f80741451fe1407fbe453e75d371cc38a0de1411efc7df5c8c3c35d8ec02207a5899976628c19a22dae0058f60f86f43b379991bbf93383b17932310e497b001210284a937f256393b3ba686556e90bd000706600bdbee4169abd092f392689307d2ffffffff02005a6202000000001976a914fe7e0711287688b33b9a5c239336c4700db34e6388ac545ead21010000001976a914520b23898b775a4a5dc19d07a88ca4a4a87b92bf88ac00000000",
"txid": "fa36691ec5f18a9dc56b1dfce3dff293352ebde8bc1b77489cba4921bc5b0c69",
"hash": "fa36691ec5f18a9dc56b1dfce3dff293352ebde8bc1b77489cba4921bc5b0c69",
"depends": [],
"fee": 4540,
"sigops": 2,
"weight": 904
}
]
}
returns block template or proposal for use with mining.
Also validates proposal if mode
is specified as proposal
.
Note: This is described in BIP22 - Fundamentals, BIP23 - Pooled Mining, BIP145 - Updates for Segregated Witness
Params
N. | Name | Default | Description |
---|---|---|---|
1 | jsonrequestobject | {} | JSONRequestObject. |
submitblock
let blockdata;
blockdata='000000203f6397a1442eb6a9901998c4a4b432f8573c7a490b2d5e6d6f2ad0d0fca25e2c56940d79c8f81f3eb5e998bcf79dbf8c7d3b13b01adaac526cf9df8ee385ec0c1ac0055bffff7f20000000000101000000010000000000000000000000000000000000000000000000000000000000000000ffffffff1f01640e6d696e65642062792062636f696e046c62c046080000000000000000ffffffff0100f2052a010000001976a91473815900ee35f3815b3407af2eeb1b611cf533d788ac00000000';
curl $url \
-X POST \
--data '{
"method": "submitblock",
"params": [ "'$blockdata'" ]
}'
bcoin-cli rpc submitblock $blockdata
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
const result = await client.execute('submitblock', [ blockdata ]);
console.log(result);
})();
Adds block to chain.
Params
N. | Name | Default | Description |
---|---|---|---|
1 | blockdata | Required. | Mined block data (hex) |
verifyblock
let blockdata;
blockdata='000000203f6397a1442eb6a9901998c4a4b432f8573c7a490b2d5e6d6f2ad0d0fca25e2c56940d79c8f81f3eb5e998bcf79dbf8c7d3b13b01adaac526cf9df8ee385ec0c1ac0055bffff7f20000000000101000000010000000000000000000000000000000000000000000000000000000000000000ffffffff1f01640e6d696e65642062792062636f696e046c62c046080000000000000000ffffffff0100f2052a010000001976a91473815900ee35f3815b3407af2eeb1b611cf533d788ac00000000';
curl $url \
-X POST \
--data '{
"method": "verifyblock",
"params": [ "'$blockdata'" ]
}'
bcoin-cli rpc verifyblock $blockdata
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
// Block data is old, so it should return error
const result = await client.execute('verifyblock', [ blockdata ]);
console.log(result);
})();
Verifies the block data.
Params
N. | Name | Default | Description |
---|---|---|---|
1 | blockdata | Required. | Mined block data (hex) |
setgenerate
let mining, proclimit;
mining=1;
proclimit=1;
curl $url \
-X POST \
--data '{
"method": "setgenerate",
"params": [ '$mining', '$proclimit' ]
}'
bcoin-cli rpc setgenerate $mining $proclimit
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
const result = await client.execute('setgenerate', [ mining, proclimit ]);
console.log(result);
})();
The above command returns JSON "result" like this:
true
Will start the mining on CPU.
Params
N. | Name | Default | Description |
---|---|---|---|
1 | mining | 0 | true will start mining, false will stop. |
2 | proclimit | 0 |
getgenerate
curl $url \
-X POST \
--data '{
"method": "getgenerate",
"params": []
}'
bcoin-cli rpc getgenerate
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
const result = await client.execute('getgenerate');
console.log(result);
})();
The above command returns JSON "result" like this:
true
Returns status of mining on Node.
Params
N. | Name | Default | Description |
---|
None.
generate
let numblocks;
numblocks=2;
curl $url \
-X POST \
--data '{
"method": "generate",
"params": [ '$numblocks' ]
}'
bcoin-cli rpc generate $numblocks
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
// Timeout error
const result = await client.execute('generate', [ numblocks ]);
console.log(result);
})();
The above command returns JSON "result" like this:
[
"11c5504f63aebe71b3e6f46a31f83dd24e65e392a11e905f6acdb7346c8b18c0",
"64455db5aa23d6277027aea1851d85da8ee07958ed7caee2ca630b065f4faaa8"
]
Mines numblocks
number of blocks. Will return once all blocks are mined. CLI command may
timeout before that happens.
Params
N. | Name | Default | Description |
---|---|---|---|
1 | numblocks | 1 | Number of blocks to mine. |
2 | maxtries |
generatetoaddress
let numblocks, address;
numblocks=2;
address='mhX1xHbKGzw3r8FoN5bUkmRixHPEDNywxh';
# Will return once all blocks are mined.
curl $url \
-X POST \
--data '{
"method": "generatetoaddress",
"params": [ '$numblocks', "'$address'" ]
}'
bcoin-cli rpc generatetoaddress $numblocks $address
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
// Timeout error
const result = await client.execute('generatetoaddress', [ numblocks, address ]);
console.log(result);
})();
The above command returns JSON "result" like this:
[
"65e54939c20f61e54173596eb72a7b00b96baac0c58d2cb30d1fad64d1b51dbb",
"3959ee3f58bb1ac05af9bebb51ebf7872bcd4231fa41c384bcfef468541b5166"
]
Mines blocknumber
blocks, with address
as coinbase.
Params
N. | Name | Default | Description |
---|---|---|---|
1 | numblocks | 1 | Number of blocks to mine. |
2 | address | Coinbase address for new blocks. |
RPC Calls - Network
getconnectioncount
curl $url \
-X POST \
--data '{
"method": "getconnectioncount",
"params": []
}'
bcoin-cli rpc getconnectioncount
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
const result = await client.execute('getconnectioncount');
console.log(result);
})();
The above command returns JSON "result" like this:
8
Returns connection count.
Params
N. | Name | Default | Description |
---|---|---|---|
None. |
ping
curl $url \
-X POST \
--data '{
"method": "ping",
"params": []
}'
bcoin-cli rpc ping
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
const result = await client.execute('ping');
console.log(result);
})();
The above command returns JSON "result" like this:
null
Will send ping request to every connected peer.
Params
N. | Name | Default | Description |
---|---|---|---|
None. |
getpeerinfo
curl $url \
-X POST \
--data '{
"method": "getpeerinfo",
"params": []
}'
bcoin-cli rpc getpeerinfo
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
const result = await client.execute('getpeerinfo');
console.log(result);
})();
The above command returns JSON "result" like this:
[
{
"id": 17,
"addr": "67.210.228.203:8333",
"addrlocal": "100.200.50.10:52342",
"services": "0000000d",
"relaytxes": true,
"lastsend": 1571762943,
"lastrecv": 1571762941,
"bytessent": 299812,
"bytesrecv": 1149318,
"conntime": 2534,
"timeoffset": 0,
"pingtime": 0.054,
"minping": 0.051,
"version": 70015,
"subver": "/Satoshi:0.14.2/",
"inbound": false,
"startingheight": 600551,
"besthash": "0000000000000000000425601a59d69922cdce6bad287950004d8308428b0748",
"bestheight": 600558,
"banscore": 0,
"inflight": [],
"whitelisted": false
},
...
]
Returns information about all connected peers.
Params
N. | Name | Default | Description |
---|---|---|---|
None. |
addnode
let nodeAddr, cmd;
nodeAddr='127.0.0.1:48444';
cmd='add'
curl $url \
-X POST \
--data '{
"method": "addnode",
"params": [ "'$nodeAddr'", "'$cmd'" ]
}'
bcoin-cli rpc addnode $nodeAddr $cmd
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
const result = await client.execute('addnode', [ nodeAddr, cmd ]);
console.log(result);
})();
The above command returns JSON "result" like this:
null
Adds or removes peers in Host List.
Params
N. | Name | Default | Description |
---|---|---|---|
1 | addr | Required | IP Address of the Node. |
2 | cmd | Required | Command |
Commands
Command | Description |
---|---|
add | Adds node to Host List and connects to it |
onetry | Tries to connect to the given node |
remove | Removes node from host list |
disconnectnode
let nodeAddr;
nodeAddr='127.0.0.1:48444';
curl $url \
-X POST \
--data '{
"method": "disconnectnode",
"params": [ "'$nodeAddr'" ]
}'
bcoin-cli rpc disconnectnode $nodeAddr
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
const result = await client.execute('disconnectnode', [ nodeAddr ]);
console.log(result);
})();
The above command returns JSON "result" like this:
null
Disconnects node.
Params
N. | Name | Default | Description |
---|---|---|---|
1 | addr | Required | IP Address of the Node. |
getaddednodeinfo
let nodeAddr;
nodeAddr='127.0.0.1:48444';
curl $url \
-X POST \
--data '{
"method": "getaddednodeinfo",
"params": [ "'$nodeAddr'" ]
}'
bcoin-cli rpc getaddednodeinfo $nodeAddr
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
const result = await client.execute('getaddednodeinfo', [ nodeAddr ]);
console.log(result);
})();
The above command returns JSON "result" like this:
[
{
"addednode": "127.0.0.1:48444",
"connected": true,
"addresses": [
{
"address": "127.0.0.1:48444",
"connected": "outbound"
}
]
}
]
Returns node information from host list.
Params
N. | Name | Default | Description |
---|---|---|---|
1 | addr | Required | IP Address of the Node. |
getnettotals
curl $url \
-X POST \
--data '{
"method": "getnettotals",
"params": []
}'
bcoin-cli rpc getnettotals
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
const result = await client.execute('getnettotals');
console.log(result);
})();
The above command returns JSON "result" like this:
{
"totalbytesrecv": 42175,
"totalbytessent": 42175,
"timemillis": 1527116369308
}
Returns information about used network resources.
Params
N. | Name | Default | Description |
---|---|---|---|
None. |
getnetworkinfo
curl $url \
-X POST \
--data '{
"method": "getnetworkinfo",
"params": []
}'
bcoin-cli rpc getnetworkinfo
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
const result = await client.execute('getnetworkinfo');
console.log(result);
})();
The above command returns JSON "result" like this:
"version": "2.0.0-dev",
"subversion": "/bcoin:2.0.0-dev/",
"protocolversion": 70015,
"localservices": "00000009",
"localservicenames": [
"NETWORK",
"WITNESS"
],
"localrelay": true,
"timeoffset": 0,
"networkactive": true,
"connections": 8,
"networks": [],
"relayfee": 0.00001,
"incrementalfee": 0,
"localaddresses": [
{
"address": "200.100.50.10",
"port": 8333,
"score": 3
}
],
"warnings": ""
}
Returns local node's network information
Params
N. | Name | Default | Description |
---|---|---|---|
None. |
setban
let nodeAddr, cmd;
nodeAddr='127.0.0.1:48444';
cmd='add'
curl $url \
-X POST \
--data '{
"method": "setban",
"params": [ "'$nodeAddr'", "'$cmd'" ]
}'
bcoin-cli rpc setban $nodeAddr $cmd
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
const result = await client.execute('setban', [ nodeAddr, cmd ]);
console.log(result);
})();
The above command returns JSON "result" like this:
null
Adds or removes nodes from banlist.
Params
N. | Name | Default | Description |
---|---|---|---|
1 | addr | Required | IP Address of the Node. |
2 | cmd | Required | Command |
Commands
Command | Description |
---|---|
add | Adds node to ban list, removes from host list, disconnects. |
remove | Removes node from ban list |
listbanned
curl $url \
-X POST \
--data '{
"method": "listbanned",
"params": []
}'
bcoin-cli rpc listbanned
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
const result = await client.execute('listbanned');
console.log(result);
})();
The above command returns JSON "result" like this:
[
{
"address": "127.0.0.1",
"banned_until": 1527202858,
"ban_created": 1527116458,
"ban_reason": ""
}
]
Lists all banned peers.
Params
N. | Name | Default | Description |
---|---|---|---|
None. |
clearbanned
curl $url \
-X POST \
--data '{
"method": "clearbanned",
"params": []
}'
bcoin-cli rpc clearbanned
const {NodeClient, Network} = require('bcoin');
const network = Network.get('regtest');
const clientOptions = {
network: network.type,
port: network.rpcPort,
apiKey: 'api-key'
}
const client = new NodeClient(clientOptions);
(async () => {
const result = await client.execute('clearbanned');
console.log(result);
})();
The above command returns JSON "result" like this:
null
Removes all banned peers.
Params
N. | Name | Default | Description |
---|---|---|---|
None. |
Wallet
The Wallet Client
npm i -g bclient
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
const id = 'primary'; // or whatever your wallet name is
const wallet = walletClient.wallet(id);
The best way to interact with the wallet API is with bwallet-cli in the bclient
package. Installing globally with
npm i -g bclient
gives you access to the CLI. You can also install locally
to your project.
Note that when using it in your own program, you will need to explicitly
pass in a port option. The easiest way to do this is with bcoin.Network
.
You can create a client for a specific wallet (and be compatible with the old
API) with the wallet
method on WalletClient
class.
The wallet HTTP server listens on it's own port, separate from the node's server.
By default the wallet server listens on these localhost
ports:
Network | API Port |
---|---|
main | 8334 |
testnet | 18334 |
regtest | 48334 |
simnet | 18558 |
Configuration
Persistent configuration can be added to wallet.conf
in your prefix
directory.
This could be the same directory as bcoin.conf
for the node server, but could also
be in a network-specific directory.
Example Configuration:
network: regtest
wallet-auth: true
api-key: api-key
http-host: 0.0.0.0
Wallet Authentication
The following samples return a wallet object using a wallet token
let token, id;
id='primary'
token='17715756779e4a5f7c9b26c48d90a09d276752625430b41b5fcf33cf41aa7615'
curl $walleturl/$id?token=$token
bwallet-cli get --token=$token
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
const wallet = walletClient.wallet(id, token);
(async () => {
const result = await wallet.getInfo();
console.log(result);
})();
There are three levels of authentication for the bcoin wallet API server:
1. API Key
The API key is set either in wallet.conf
or with the argument --api-key=
at launch.
When set, the API key is required (using HTTP Basic Authorization)
to access ALL endpoints, otherwise a 401 Unauthorized
error is returned.
See the section on node API server authentication for tips on creating a strong key.
2. Wallet tokens
Every individual wallet has its own security token, which is a 32 byte hash calculated from the wallet master key:
SHA256(m/44' Private Key | tokenDepth)
A wallet is always created with a corresponding token. Even watch-only wallets will have a master private key,
used just for this purpose. The token is returned when a wallet is created, or from the wallet info
API endpoint (which is restricted to admin
access, see next subsection). When wallet-auth
is set to true
,
the token must be sent in the query string or JSON body for any requests regarding that wallet.
Requests with incorrect tokens are rejected with a 403 Forbidden
error.
3. Wallet admin token
The admin token is set by the user in wallet.conf
, with the launch argument bcoin --wallet-admin-token=
or, if running bwallet
as a separate server, just bwallet --admin-token=
.
It is required to be a 32 byte hex string. Like the individual wallet tokens, it is only required when
wallet-auth: true
, and must be included in the query string or JSON body. Requests sent with an
admin token automatically overrides individual wallet tokens, and can therefore access all wallets.
The admin token also enables access to extra API endpoints outlined in Wallet Admin Commands.
The WalletDB and Object
let id;
id="primary"
curl http://x:api-key@127.0.0.1:48334/wallet # will list regtest (default port 48334) wallets
# examples in these docs will use an environment variable:
walleturl=http://x:api-key@127.0.0.1:48334/wallet/
curl $walleturl/$id
# Like the node client, you can configure it by passing arguments:
bwallet-cli --network=regtest --id=$id get
# ...or you can use environment variables. The default `id` is `primary`:
export BCOIN_API_KEY=yoursecret
export BCOIN_NETWORK=regtest
bwallet-cli get
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
const wallet = walletClient.wallet(id);
(async () => {
const result = await wallet.getInfo();
console.log(result);
})();
The wallet object will look something like this:
{
"network": "regtest",
"wid": 0,
"id": "primary",
"watchOnly": false,
"accountDepth": 1,
"token": "17715756779e4a5f7c9b26c48d90a09d276752625430b41b5fcf33cf41aa7615",
"tokenDepth": 0,
"master": {
"encrypted": false
},
"balance": {
"tx": 5473,
"coin": 5472,
"unconfirmed": 1504999981750,
"confirmed": 1494999998350
}
}
bcoin maintains a wallet database which contains every wallet. Wallets are not usable without also using a wallet database. For testing, the wallet database can be in-memory, but it must be there. Wallets are uniquely identified by an id and the walletdb is created with a default id of primary
. (See Create a Wallet below for more details.)
Wallets in bcoin use bip44. They also originally supported bip45 for multisig, but support was removed to reduce code complexity, and also because bip45 doesn't seem to add any benefit in practice.
The wallet database can contain many different wallets, with many different accounts, with many different addresses for each account. bcoin should theoretically be able to scale to hundreds of thousands of wallets/accounts/addresses.
Each account can be of a different type. You could have a pubkeyhash account, as well as a multisig account, a witness pubkeyhash account, etc.
Note that accounts should not be accessed directly from the public API. They do not have locks which can lead to race conditions during writes.
wallet object vs wallet client object
bclient returns a WalletClient object that can perform admin functions without specifying a wallet, and may be useful when managing multiple wallets. WalletClient can also return a wallet object specified by an id
. This object performs functions (and may be authorized by a token) specific to that wallet only.
Create A Wallet
let id, passphrase, witness, watchOnly, accountKey;
id='newWallet'
passphrase='secret456'
witness=false
watchOnly=true
accountKey='tpubDDF921KoqbemP3yPiBMBzvkDY5pe4KpirJtXtSaTdRkZ3LyqorrHy1mv1XLNqrmTQQXztdTQiZxDtPxGZ9Lmiqtv8wJYJs5o52J54djLpqC'
curl $walleturl/$id \
-X PUT \
--data '{"witness":'$witness', "passphrase":"'$passphrase'", "watchOnly": '$watchOnly', "accountKey":"'$accountKey'"}'
# watch-only defaults to true if --account-key flag is set
bwallet-cli mkwallet $id --witness=$witness --passphrase=$passphrase --watch-only=$watchOnly --account-key=$accountKey
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
const options = {
passphrase: passphrase,
witness: witness,
watchOnly: watchOnly,
accountKey: accountKey
};
(async() => {
const result = await walletClient.createWallet(id, options);
console.log(result);
})();
Sample response:
{
"network": "regtest",
"wid": 11,
"id": "newWallet",
"watchOnly": true,
"accountDepth": 1,
"token": "489d43e398dad34e69653e5edb5cb39b6d55be3364753c07d084d4b3d0292af7",
"tokenDepth": 0,
"master": {
"encrypted": true,
"until": 1571763677,
"iv": "4e24f2a5908e20da0b8ba3e88dcda272",
"algorithm": "pbkdf2",
"n": 50000,
"r": 0,
"p": 0
},
"balance": {
"tx": 0,
"coin": 0,
"unconfirmed": 0,
"confirmed": 0
}
}
Create a new wallet with a specified ID.
HTTP Request
PUT /wallet/:id
Parameters:
Name | Type | Default | Description |
---|---|---|---|
id | String | Wallet ID (used for storage) | |
master | HDPrivateKey | Master HD key. If not present, it will be generated | |
witness | Boolean | true |
Whether to use witness programs |
watchOnly | Boolean | false |
(watch-only for CLI) |
accountKey | String | The extended public key for the primary account in the new wallet. This value is ignored if watchOnly is false ( account-key for CLI) |
|
type | String | Type of wallet (pubkeyhash (default), multisig) | |
m | Number | 1 |
m value for multisig (m-of-n ) |
n | Number | 1 |
n value for multisig (m-of-n ) |
mnemonic | String | A mnemonic phrase to use to instantiate an hd private key. One will be generated if none provided | |
passphrase | String | A strong passphrase used to encrypt the wallet | |
accountDepth* | Number | 0 |
The index of the next BIP44 account index |
compressed* | Boolean | true |
Whether to use compressed public keys |
(*) options are only available in Javascript usage, not CLI or curl
Reset Authentication Token
let id;
id='primary'
passphrase='secret123'
bwallet-cli retoken --id=$id --passphrase=$passphrase
curl $walleturl/$id/retoken \
-X POST \
--data '{"passphrase":"'$passphrase'"}'
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
const wallet = walletClient.wallet(id);
(async () => {
const result = await wallet.retoken(passphrase);
console.log(result);
})();
Sample response:
{
"token": "2d04e217877f15ba920d02c24c6c18f4d39df92f3ae851bec37f0ade063244b2"
}
Derive a new wallet token, required for access of this particular wallet.
HTTP Request
POST /wallet/:id/retoken
Get Wallet Info
let id;
id='primary'
curl $walleturl/$id
bwallet-cli get --id=$id
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
const wallet = walletClient.wallet(id);
(async () => {
const result = await wallet.getInfo();
console.log(result);
})();
Sample output
{
"network": "regtest",
"wid": 0,
"id": "primary",
"watchOnly": false,
"accountDepth": 1,
"token": "4d9e2a62f67929340b8c600bef0c965370f29cc64afcdeb7aea9cb52906c1d27",
"tokenDepth": 13,
"master": {
"encrypted": true,
"until": 0,
"iv": "e33424f46674d4010fb0715bb69abc98",
"algorithm": "pbkdf2",
"n": 50000,
"r": 0,
"p": 0
},
"balance": {
"tx": 5473,
"coin": 5472,
"unconfirmed": 1504999981750,
"confirmed": 1494999998350
}
}
Get wallet info by ID. If no id is passed in the CLI it assumes an id of primary
.
HTTP Request
GET /wallet/:id
Parameters | Description |
---|---|
id string |
named id of the wallet whose info you would like to retrieve |
Get Master HD Key
let id;
id='primary'
curl $walleturl/$id/master
bwallet-cli master --id=$id
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
const wallet = walletClient.wallet(id);
(async () => {
const result = await wallet.getMaster();
console.log(result);
})();
Sample responses:
BEFORE passphrase is set:
{
"encrypted": false,
"key": {
"xprivkey": "tprv8ZgxMBicQKsPfNKy1Wf9EV1cTmz1Cmm6MVrvYdgcR6Hf8sEDUAzhnnoiVbw5jejp4EZWXynQEJhB62oSfANpHRAJqfiZarh1gVMowcJZ2Mn"
},
"mnemonic": {
"bits": 128,
"language": "english",
"entropy": "e35833c318d677945ec21efff032bb64",
"phrase": "today screen valid coyote guess sketch kitchen duck zoo light put siege"
}
}
AFTER passphrase is set:
{
"encrypted": true,
"until": 1527121890,
"iv": "e33424f46674d4010fb0715bb69abc98",
"ciphertext": "c2bd62d659bc92212de5d9e939d9dc735bd0212d888b1b04a71d319e82e5ddb18008e383130fd0409113264d1cbc0db42d997ccf99510b168c80e2f39f2983382457f031d5aa5ec7a2d61f4fc92c62117e4eed59afa4a17d7cb0aae3ec5fa0d4",
"algorithm": "pbkdf2",
"n": 50000,
"r": 0,
"p": 0
}
Get wallet master HD key. This is normally censored in the wallet info route. The provided API key must have admin access.
HTTP Request
GET /wallet/:id/master
Parameters | Description |
---|---|
id string |
named id of the wallet whose info you would like to retrieve |
Change Passphrase
let id, oldPass, newPass;
id='newWallet'
oldPass='secret456'
newPass='789secret'
> No cli command available
curl $walleturl/$id/passphrase \
-X POST \
--data '{"old":"'$oldPass'", "passphrase":"'$newPass'"}'
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
const wallet = walletClient.wallet(id);
(async () => {
const result = await wallet.setPassphrase(newPass, oldPass);
console.log(result);
})();
Sample Response:
{"success": true}
Change wallet passphrase. Encrypt if unencrypted.
HTTP Request
POST /wallet/:id/passphrase
Body Parameters
Paramters | Description |
---|---|
old string |
Old passphrase. Pass in empty string if none |
new string |
New passphrase |
Send a transaction
id="primary"
passphrase="secret123"
rate=0.00001000
value=0.00020000
address="mo2L7KZgmH2QNs9QCBAFwQPqBJNSXNhQWV"
bwallet-cli send --id=$id --value=$value --address=$address ---passphrase=$passphrase
id="primary"
passphrase="secret123"
rate=1000
value=20000
address="mo2L7KZgmH2QNs9QCBAFwQPqBJNSXNhQWV"
curl $walleturl/$id/send \
-X POST \
--data '{
"passphrase":"'$passphrase'",
"rate":'$rate',
"outputs":[
{"address":"'$address'", "value":'$value'}
]
}'
let id, passphrase, rate, value, address;
id="primary"
passphrase="secret123"
rate=1000
value=20000
address="mo2L7KZgmH2QNs9QCBAFwQPqBJNSXNhQWV"
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
const wallet = walletClient.wallet(id);
const options = {
passphrase: passphrase,
rate: rate,
outputs: [{ value: value, address: address }]
};
(async () => {
const result = await wallet.send(options);
console.log(result);
})();
Sample response:
{
"hash": "4d44a0285e4e5ae782fc9dee32d2a7b60ec63009a731d72e51374910582f517c",
"height": -1,
"block": null,
"time": 0,
"mtime": 1571764348,
"date": "1970-01-01T00:00:00Z",
"mdate": "2019-10-22T17:12:28Z",
"size": 225,
"virtualSize": 225,
"fee": 4540,
"rate": 20177,
"confirmations": 0,
"inputs": [
{
"value": 2500000000,
"address": "mhX1xHbKGzw3r8FoN5bUkmRixHPEDNywxh",
"path": {
"name": "default",
"account": 0,
"change": false,
"derivation": "m/0'/0/1"
}
}
],
"outputs": [
{
"value": 20000,
"address": "mo2L7KZgmH2QNs9QCBAFwQPqBJNSXNhQWV",
"path": {
"name": "default",
"account": 0,
"change": true,
"derivation": "m/0'/1/0"
}
},
{
"value": 2499975460,
"address": "mhpSYq8bnM5XJVbpafdLNUtLZefr2d6xSq",
"path": {
"name": "default",
"account": 0,
"change": true,
"derivation": "m/0'/1/1"
}
}
],
"tx": "010000000195c60f9cdf95961f696a83bac71adcab286b4a269bb5bdae71ca95d634fab681000000006a473044022068d00d638a3b4d4d54c76167fff1bad023f34375d3bb05a7cb0c051ac63133ed0220182eba4cd68d27c43c071d6690a60c8b13f4c775fec145a736f6f58781fa2d5a01210336c99e45e00b73c863497a989fe6feb08439ca2d7cf98f55bc261ed70ed28a7bffffffff02204e0000000000001976a91452572750e3cf71b97a58dd084f34c3b7027ec75288ac24990295000000001976a914193ee8a7e5d7d5c299785dea90802bc1906a893788ac00000000"
}
Create, sign, and send a transaction.
HTTP Request
POST /wallet/:id/send
Post Parameters
Parameter | Description |
---|---|
outputs array |
An array of outputs to send for the transaction |
account string |
account to use for transaction |
passphrase string |
passphrase to unlock the account |
smart bool |
whether or not to choose smart coins, will also used unconfirmed transactions |
blocks int |
number of blocks to use for fee estimation. |
rate int |
the rate for transaction fees. Denominated in satoshis per kb |
sort bool |
Sort outputs and inputs according BIP69 |
maxFee int |
maximum fee you're willing to pay |
subtractFee bool |
whether to subtract fee from outputs (evenly) |
subtractIndex int |
subtract only from specified output index |
selection enum - all , random , age , value |
How to select coins |
depth int |
number of confirmation for coins to spend |
value int (or float) |
Value to send in satoshis (or whole BTC, see warning above) |
address string |
destination address for transaction |
Create a Transaction
id="multisig-watch"
rate=0.00001000
value=0.05000000
address="mg54SV2ZubNQ5urTbd42mUsQ54byPvSg5j"
sign=false
bwallet-cli mktx --id=$id --rate=$rate --value=$value --address=$address ---passphrase=$passphrase --sign=$sign
id="multisig1"
rate=1000
value=5000000
address="mg54SV2ZubNQ5urTbd42mUsQ54byPvSg5"
sign=false
curl $walleturl/$id/create \
-X POST \
--data '{
"rate":'$rate',
"outputs":[
{"address":"'$address'", "value":'$value'}
],
"sign": '$false'
}'
let id, rate, value, address, sign;
id="multisig-watch"
rate=1000
value=5000000
address="mg54SV2ZubNQ5urTbd42mUsQ54byPvSg5"
sign=false
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
const wallet = walletClient.wallet(id);
const options = {
rate: rate,
outputs: [{ value: value, address: address }],
sign: sign
};
(async () => {
const result = await wallet.createTX(options);
console.log(result);
})();
Sample response:
{
"hash": "3f61cbbe01ca9eb7eb0fb8c37f15e92d2fee8c28ea54fef5b7bc89eee219074b",
"witnessHash": "3f61cbbe01ca9eb7eb0fb8c37f15e92d2fee8c28ea54fef5b7bc89eee219074b",
"fee": 3840,
"rate": 30000,
"mtime": 1571766790,
"version": 1,
"inputs": [
{
"prevout": {
"hash": "4e6c7db14b22e39ca800b0eb83d698619849ac3245408cf03ae5dc752e2d884c",
"index": 0
},
"script": "",
"witness": "00",
"sequence": 4294967295,
"coin": {
"version": 1,
"height": 746,
"value": 312500000,
"script": "00201e669358ab0b70bbdf63ac7abc442ee1b1f6f0fe24b1d67b2e3527ffac664c39",
"address": "bcrt1qrenfxk9tpdcthhmr43atc3pwuxcldu87yjcav7ewx5nlltrxfsustr8wj5",
"coinbase": true
}
}
],
"outputs": [
{
"value": 5000000,
"script": "76a914061270cea3bdd77a5442657d177f4490642e7a2288ac",
"address": "mg54SV2ZubNQ5urTbd42mUsQ54byPvSg5j"
},
{
"value": 307496160,
"script": "0020485f95ef73a1f444cbbfdb7ff1f43c7e34c069d25a823026d3513cfa64cfd677",
"address": "bcrt1qfp0etmmn586yfjalmdllrapu0c6vq6wjt2prqfkn2y705ex06ems39f93c"
}
],
"locktime": 0,
"hex": "01000000014c882d2e75dce53af08c404532ac49986198d683ebb000a89ce3224bb17d6c4e0000000000ffffffff02404b4c00000000001976a914061270cea3bdd77a5442657d177f4490642e7a2288ace004541200000000220020485f95ef73a1f444cbbfdb7ff1f43c7e34c069d25a823026d3513cfa64cfd67700000000"
}
Create and template a transaction (useful for multisig). Does not broadcast or add to wallet.
HTTP Request
POST /wallet/:id/create
Post Paramters
Paramter | Description |
---|---|
outputs array |
An array of outputs to send for the transaction |
passphrase string |
passphrase to unlock the account |
smart bool |
whether or not to choose smart coins, will also used unconfirmed transactions |
rate int |
the rate for transaction fees. Denominated in satoshis per kb |
maxFee int |
maximum fee you're willing to pay |
subtractFee bool |
whether to subtract fee from outputs (evenly) |
subtractIndex int |
subtract only from specified output index |
selection enum - all , random , age , value |
How to select coins |
depth int |
number of confirmation for coins to spend |
value int (or float) |
Value to send in satoshis (or whole BTC, see warning above) |
address string |
destination address for transaction |
sign bool |
whether to sign the TX (must be false for watch-only wallets) |
Sign Transaction
let id, tx, passphrase;
id="multisig1"
passphrase="multisecret123"
tx="01000000014c882d2e75dce53af08c404532ac49986198d683ebb000a89ce3224bb17d6c4e0000000000ffffffff02404b4c00000000001976a914061270cea3bdd77a5442657d177f4490642e7a2288ace004541200000000220020485f95ef73a1f444cbbfdb7ff1f43c7e34c069d25a823026d3513cfa64cfd67700000000"
bwallet-cli sign --id=$id --passphrase=$passphrase --tx=$tx
curl $walleturl/$id/sign \
-X POST \
--data '{"tx": "'$tx'", "passphrase":"'$passphrase'"}'
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
const wallet = walletClient.wallet(id);
const options = { tx: tx, passphrase: passphrase };
(async () => {
const result = await wallet.sign(options);
console.log(result);
})();
Sample Output
{
"hash": "3f61cbbe01ca9eb7eb0fb8c37f15e92d2fee8c28ea54fef5b7bc89eee219074b",
"witnessHash": "68e9d7a28a571746eb7561ebc107479da26eb1cb2246ad5f05769149f6ec84db",
"fee": 3840,
"rate": 21942,
"mtime": 1571767276,
"version": 1,
"inputs": [
{
"prevout": {
"hash": "4e6c7db14b22e39ca800b0eb83d698619849ac3245408cf03ae5dc752e2d884c",
"index": 0
},
"script": "",
"witness": "050000483045022100a8ba55fb5bdf6a69fc820d44c4430d55ae0356f7dd5cdcf5bb27e8cb24535fb802204a6a23dedc1acff4725e99b51bce9f2692aa08d6063842be51d5728e8f95f76f0100695221027b88633d65cb48667012bb64039afda0b50c51abb2fe11aca975b324b8f0f44c2102f9ae8660d9dc5f3d62a5c347e8cd431ecc9404c17ecbb57ab89aa54b6df68a422103001a9a61d4989e229cfa5bb9acf0fb03fa5f3f1c9785fc1de2d76a8f363c457953ae",
"sequence": 4294967295,
"coin": {
"version": 1,
"height": 746,
"value": 312500000,
"script": "00201e669358ab0b70bbdf63ac7abc442ee1b1f6f0fe24b1d67b2e3527ffac664c39",
"address": "bcrt1qrenfxk9tpdcthhmr43atc3pwuxcldu87yjcav7ewx5nlltrxfsustr8wj5",
"coinbase": true
}
}
],
"outputs": [
{
"value": 5000000,
"script": "76a914061270cea3bdd77a5442657d177f4490642e7a2288ac",
"address": "mg54SV2ZubNQ5urTbd42mUsQ54byPvSg5j"
},
{
"value": 307496160,
"script": "0020485f95ef73a1f444cbbfdb7ff1f43c7e34c069d25a823026d3513cfa64cfd677",
"address": "bcrt1qfp0etmmn586yfjalmdllrapu0c6vq6wjt2prqfkn2y705ex06ems39f93c"
}
],
"locktime": 0,
"hex": "010000000001014c882d2e75dce53af08c404532ac49986198d683ebb000a89ce3224bb17d6c4e0000000000ffffffff02404b4c00000000001976a914061270cea3bdd77a5442657d177f4490642e7a2288ace004541200000000220020485f95ef73a1f444cbbfdb7ff1f43c7e34c069d25a823026d3513cfa64cfd677050000483045022100a8ba55fb5bdf6a69fc820d44c4430d55ae0356f7dd5cdcf5bb27e8cb24535fb802204a6a23dedc1acff4725e99b51bce9f2692aa08d6063842be51d5728e8f95f76f0100695221027b88633d65cb48667012bb64039afda0b50c51abb2fe11aca975b324b8f0f44c2102f9ae8660d9dc5f3d62a5c347e8cd431ecc9404c17ecbb57ab89aa54b6df68a422103001a9a61d4989e229cfa5bb9acf0fb03fa5f3f1c9785fc1de2d76a8f363c457953ae00000000"
}
Sign a templated transaction (useful for multisig).
HTTP Request
POST /wallet/:id/sign
Post Paramters
Parameter | Description |
---|---|
tx string |
the hex of the transaction you would like to sign |
passphrase string |
passphrase to unlock the wallet |
Zap Transactions
id="primary"
account="default"
age=259200 # 72 hours
bwallet-cli zap --id=$id --account=$account --age=$age
id="primary"
account="default"
age=259200 # 72 hours
curl $walleturl/$id/zap \
-X POST \
--data '{
"account": "'$account'",
"age": '$age'
}'
let id, age, account;
id="primary"
account="default"
age=259200 // 72 hours
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
const wallet = walletClient.wallet(id);
(async () => {
const result = await wallet.zap(account, age);
console.log(result);
})();
Sample Response
Zapped!
{
"success": true
}
{
"success": true
}
Remove all pending transactions older than a specified age.
HTTP Request
POST /wallet/:id/zap?age=3600
Post Parameters
Parameters | Description |
---|---|
account string or number |
account to zap from |
age number |
age threshold to zap up to (unix time) |
Unlock Wallet
let id, pass, timeout
id='primary'
pass='secret123'
timeout=60
bwallet-cli unlock --id=$id $pass $timeout
curl $walleturl/$id/unlock \
-X POST \
--data '{"passphrase":"'$pass'", "timeout": '$timeout'}'
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
const wallet = walletClient.wallet(id);
(async () => {
const result = await wallet.unlock(pass, timeout);
console.log(result);
})();
Sample Response
{"success": true}
{"success": true}
Unlocked.
Derive the AES key from passphrase and hold it in memory for a specified number of seconds. Note: During this time, account creation and signing of transactions will not require a passphrase.
HTTP Request
POST /wallet/:id/unlock
Body Parameters
Parameter | Description |
---|---|
passphrase string |
Password used to encrypt the wallet being unlocked |
timeout number |
time to re-lock the wallet in seconds. (default=60) |
Lock Wallet
let id;
id='primary'
bwallet-cli lock --id=$id
curl $walleturl/$id/lock \
-X POST
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
const wallet = walletClient.wallet(id);
(async () => {
const result = await wallet.lock(id);
console.log(result);
})();
Sample Response
{"success": true}
{"success": true}
Locked.
If unlock was called, zero the derived AES key and revert to normal behavior.
HTTP Request
POST /wallet/:id/lock
Import Public/Private Key
let id, account, key;
id='primary'
watchid='watchonly1'
account='default'
pubkey='03b28be4fd749be06233452542e9d602f97a9b9c292aed4e4669c3fcc499e366de'
privkey='cNRiqwzRfcUfokNV8nSnDKb3NsKPhfRV2z5kBN11GKFb3GXkk1Hj'
bwallet-cli --id=$id --account=$account import $privkey
bwallet-cli --id=$watchid --account=$account import $pubkey
curl $walleturl/$id/import \
-X POST \
--data '{"account":"'$account'", "privateKey":"'$privkey'"}'
curl $walleturl/$watchid/import \
-X POST \
--data '{"account":"'$account'", "publicKey":"'$pubkey'"}'
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
const wallet = walletClient.wallet(id);
const watchwallet = walletClient.wallet(watchid);
(async () => {
const result = await watchwallet.importPublic(account, pubkey);
console.log(result);
})();
(async () => {
const result = await wallet.importPrivate(account, privkey);
console.log(result);
})();
Sample Responses
Imported private key.
Imported public key.
Import a standard WIF key.
An import can be either a private key or a public key for watch-only. (Watch Only wallets will throw an error if trying to import a private key)
A rescan will be required to see any transaction history associated with the key.
HTTP Request
POST /wallet/:id/import
Body Paramters
Paramter | Description |
---|---|
id string |
id of target wallet to import key into |
privateKey string |
Base58Check encoded private key |
publicKey string |
Hex encoded public key |
Will return following error if incorrectly formatted:
Bad key for import
Import Address
let id, account, address;
id='watchonly1'
account='default'
address='msKYwEVXcKBxatPMfFLdVwYug6bz4YS87J'
bwallet-cli watch --id=$id --account=$account $address
curl $walleturl/$id/import \
-X POST \
--data '{"account":"'$account'", "address":"'$address'"}'
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
const wallet = walletClient.wallet(id);
(async () => {
const result = await wallet.importAddress(account, address);
console.log(result);
})();
Sample Response
{
"success": true
}
Import a Base58Check encoded address. Addresses (like public keys) can only be imported into watch-only wallets
The HTTP endpoint is the same as for key imports.
HTTP Request
POST /wallet/:id/import
Body Paramters
Paramter | Description |
---|---|
id string |
id of target wallet to import key into |
address string |
Base58Check encoded address |
Get Blocks with Wallet Txs
let id;
id="primary"
curl $walleturl/$id/block
bwallet-cli blocks --id=$id
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
const wallet = walletClient.wallet(id);
(async () => {
const result = await wallet.getBlocks();
console.log(result);
})();
Sample Response
[ 1179720, 1179721, 1180146, 1180147, 1180148, 1180149 ]
List all block heights which contain any wallet transactions. Returns an array of block heights
HTTP Request
GET /wallet/:id/block
Parameters | Description |
---|---|
id string |
id of wallet to query blocks with its transactions in it |
Get Wallet Block by Height
let id, height;
id="primary"
height=50
bwallet-cli --id=$id block $height
curl $walleturl/$id/block/$height
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
const wallet = walletClient.wallet(id);
(async () => {
const result = await wallet.getBlock(height);
console.log(result);
})();
Sample response:
{
"hash": "5a630279111118885f4489471ddf6f7a318b3510e5e17aa73412088d19b8ba78",
"height": 50,
"time": 1527181141,
"hashes": [
"4255c0784ae89cfe7ccf878be3a408d8c1f6c665d5df331e27962b4defe3beb8"
]
}
Get block info by height.
HTTP Request
GET /wallet/:id/block/:height
Parameters | Description |
---|---|
id string |
id of wallet which has tx in the block being queried |
height int |
height of block being queried |
Add xpubkey (Multisig)
let id, key, account;
id="multisig3"
account="default"
key="tpubDDkzvYzn2iJLqucWgnULe1x3DR5PCaZvWzpg13ZA395sFmbvKNG3XrPp3KpnbFrdE3R3c93w5ZVfU2XWBzde5LLCBR1YRy8XwMibN7sG39o"
bwallet-cli --id=$id --account=$account shared add $key
curl $walleturl/$id/shared-key \
-X PUT \
--data '{"accountKey": "'$key'", "account": "'$account'"}'
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
const wallet = walletClient.wallet(id);
(async () => {
const result = await wallet.addSharedKey(account, key);
console.log(result);
})();
Sample Response
{
"success": true,
"addedKey": true
}
Add a shared xpubkey to wallet. Must be a multisig wallet.
Response will return addedKey: true
true if key was added on this request. Returns
false
if key already added, but will still return success: true
with status 200
.
HTTP Request
PUT /wallet/:id/shared-key
Body Parameters
Paramter | Description |
---|---|
accountKey string |
xpubkey to add to the multisig wallet |
account string |
multisig account to add the xpubkey to (default='default') |
Remove xpubkey (Multisig)
let id, key;
id="multisig3"
account="default"
key="tpubDDkzvYzn2iJLqucWgnULe1x3DR5PCaZvWzpg13ZA395sFmbvKNG3XrPp3KpnbFrdE3R3c93w5ZVfU2XWBzde5LLCBR1YRy8XwMibN7sG39o"
bwallet-cli --id=$id --account=$account shared remove $key
curl $walleturl/$id/shared-key \
-X DELETE \
--data '{"accountKey": "'$key'", "account": "'$account'"}'
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
const wallet = walletClient.wallet(id);
(async () => {
const result = await wallet.removeSharedKey(account, key);
console.log(result);
})();
Sample Response
{
"success": true,
"removedKey": true
}
Remove shared xpubkey from wallet if present.
Response will return removedKey: true
true if key was removed on this request. Returns
false
if key was already removed, but will still return success: true
with status 200
.
HTTP Request
DEL /wallet/:id/shared-key
Body Parameters
Paramter | Description |
---|---|
accountKey string |
xpubkey to add to the multisig wallet |
account string |
multisig account to remove the key from (default='default') |
Get Public Key By Address
let id, address;
id="primary"
address="msKYwEVXcKBxatPMfFLdVwYug6bz4YS87J"
bwallet-cli --id=$id key $address
curl $walleturl/$id/key/$address
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
const wallet = walletClient.wallet(id);
(async () => {
const result = await wallet.getKey(address);
console.log(result);
})();
Sample Response
{
"name": "default",
"account": 0,
"branch": 0,
"index": 2,
"witness": false,
"nested": false,
"publicKey": "03b28be4fd749be06233452542e9d602f97a9b9c292aed4e4669c3fcc499e366de",
"script": null,
"program": null,
"type": "pubkeyhash",
"address": "msKYwEVXcKBxatPMfFLdVwYug6bz4YS87J"
}
Get wallet key by address. Returns wallet information with address and public key
HTTP Request
GET /wallet/:id/key/:address
Parameters | Description |
---|---|
id string |
id of wallet that holds the address being queried |
address string |
Base58 encoded address to get corresponding public key for |
Get Private Key By Address
let id, address;
id='primary'
passphrase='secret123'
address='msKYwEVXcKBxatPMfFLdVwYug6bz4YS87J'
bwallet-cli --id=$id --passphrase=$passphrase dump $address
curl $walleturl/$id/wif/$address?passphrase=$passphrase
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
const wallet = walletClient.wallet(id);
(async () => {
const result = await wallet.getWIF(address, passphrase);
console.log(result);
})();
Sample Response
{
"privateKey": "cNRiqwzRfcUfokNV8nSnDKb3NsKPhfRV2z5kBN11GKFb3GXkk1Hj"
}
Get wallet private key (WIF format) by address. Returns just the private key
HTTP Request
GET /wallet/:id/wif/:address
Parameters | Description |
---|---|
id string |
id of wallet that holds the address being queried |
address string |
Base58 encoded address to get corresponding public key for |
Generate Receiving Address
let id, account;
id="primary"
account="default"
bwallet-cli --id=$id --account=$account address
curl $walleturl/$id/address -X POST --data '{"account":"'$account'"}'
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
const wallet = walletClient.wallet(id);
(async () => {
const result = await wallet.createAddress(account);
console.log(result);
})();
Sample response:
{
"name": "default",
"account": 0,
"branch": 0,
"index": 3,
"witness": false,
"nested": false,
"publicKey": "03af169e5a186bbd7b380cb4553c72af243e18f243785b1597f192bbedd4a94fc3",
"script": null,
"program": null,
"type": "pubkeyhash",
"address": "n2eoT9D8txT5ZymDvCFPA8PHs2CmTV6oJT"
}
Derive new receiving address for account.
HTTP Request
POST /wallet/:id/address
Post Paramters
Parameter | Description |
---|---|
account string |
BIP44 account to generate address from |
Generate Change Address
let id, account;
id="primary"
account="default"
bwallet-cli --id=$id --account=$account change
curl $walleturl/$id/change -X POST --data '{"account":"'$account'"}'
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
const wallet = walletClient.wallet(id);
(async () => {
const result = await wallet.createChange(account);
console.log(result);
})();
Sample response:
{
"name": "default",
"account": 0,
"branch": 1,
"index": 3,
"witness": false,
"nested": false,
"publicKey": "03853852949194b426608b55074c54bbb78791a80c1eeece1e83343fb8babe6129",
"script": null,
"program": null,
"type": "pubkeyhash",
"address": "mppKe3yeSqnwX6pSVFqCT1AVGYPbnncKGh"
}
Derive new change address for account.
HTTP Request
POST /wallet/:id/change
Post Paramters
Parameter | Description |
---|---|
account string |
BIP44 account to generate address from |
Derive Nested Address
let id, account;
id="witness1"
account='default'
bwallet-cli --id=$id nested --account=$account
curl $walleturl/$id/nested -X POST --data '{"account": "'$account'"}'
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
const wallet = walletClient.wallet(id);
(async () => {
const result = await wallet.createNested(account);
console.log(result);
})();
Sample response
{
"name": "default",
"account": 0,
"branch": 2,
"index": 1,
"witness": true,
"nested": true,
"publicKey": "02d4ac18c8422e1ed65b007bfaef9f6b5b5c2e7070d56806f2928f24e3c92ba04d",
"script": null,
"program": "00142248d004cd1afca5fec1d8a92e3ef8de026b395d",
"type": "scripthash",
"address": "2NFQrQQSTWWCG3A9du6UNbDeDw1K3BQqQdu"
}
Derive new nested p2sh receiving address for account. Note that this can't be done on a non-witness account otherwise you will receive the following error:
[error] (node) Cannot derive nested on non-witness account.
HTTP Request
POST /wallet/:id/nested
Post Paramters
Paramter | Description |
---|---|
account string |
account to derive the nested address for (default='default') |
Get Balance
let id, account;
id='primary'
account='default'
bwallet-cli --id=$id balance --account=$account
curl $walleturl/$id/balance?account=$account
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
const wallet = walletClient.wallet(id);
(async () => {
const result = await wallet.getBalance(account);
console.log(result);
})();
Sample response:
{
"account": 0,
"tx": 307,
"coin": 287,
"unconfirmed": 1122500000000,
"confirmed": 1122500000000
}
Get wallet or account balance. If no account option is passed, the call defaults to wallet balance (with account index of -1
unconfimred
and confirmed
are expressed in satoshis.
HTTP Request
GET /wallet/:id/balance?account=:account
Request Paramters
Paramters | Description |
---|---|
id string |
wallet id to get balance of |
account string |
account name (optional, defaults to entire wallet balance) |
List all Coins
let id;
id="primary"
curl $walleturl/$id/coin
bwallet-cli --id=$id coins
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
const wallet = walletClient.wallet(id);
(async () => {
const result = await wallet.getCoins();
console.log(result);
})();
Sample Response
[
{
"version": 1,
"height": 533,
"value": 54145,
"script": "0014b36ce46975f794a457ace76acf60e9e729afa9f6",
"address": "bcrt1qkdkwg6t47722g4avua4v7c8fuu56l20khg99xp",
"coinbase": false,
"hash": "4d970cefa68cc09a4d591b106d551f2ab7ec5588fad34135e8bf0549acf1071f",
"index": 1
},
{
"version": 1,
"height": 533,
"value": 34296708683,
"script": "001478c6269acab13571f03ec97e6ef81c06a87d8b91",
"address": "bcrt1q0rrzdxk2ky6hrup7e9lxa7quq658mzu3yatkz4",
"coinbase": false,
"hash": "af4fc1e2490a01f028e837a9a4cc2deef7760ca7c7373e53e2bf0f4f71a7b808",
"index": 1
},
...
]
List all wallet coins available.
HTTP Request
GET /wallet/:id/coin
Lock Coin/Outpoints
let id, hash, index;
id="primary"
hash="52ada542512ea95be425087ee4b891842d81eb6f9a4e0350f14d0285b5fd40c1"
index="0"
# Not Supported in CLI
curl $walleturl/$id/locked/$hash/$index -X PUT
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
const wallet = walletClient.wallet(id);
(async () => {
const result = await wallet.lockCoin(hash, index);
console.log(result);
})();
Sample response:
{
"success": true
}
Lock outpoints. Also see lockunspent and listlockunspent.
HTTP Request
PUT /wallet/:id/locked/:hash/:index
Request Parameters
Paramters | Description |
---|---|
id string |
id of wallet that contains the outpoint |
hash string |
hash of transaction that created the outpoint |
index string or int |
index of the output in the transaction being referenced |
Body Paramters
Parameter | Description |
---|---|
passphrase string |
passphrase of wallet being referenced |
Unlock Outpoint
let id, passphrase, hash, index;
id="primary"
hash="52ada542512ea95be425087ee4b891842d81eb6f9a4e0350f14d0285b5fd40c1"
index="0"
# Not Supported in CLI
curl $walleturl/$id/locked/$hash/$index -X DELETE
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
const wallet = walletClient.wallet(id);
(async () => {
const result = await wallet.unlockCoin(hash, index);
console.log(result);
})();
Sample response:
{
"success": true
}
Unlock outpoints. Also see lockunspent and listlockunspent.
HTTP Request
DEL /wallet/:id/locked/:hash/:index
Request Parameters
Paramters | Description |
---|---|
id string |
id of wallet that contains the outpoint |
hash string |
hash of transaction that created the outpoint |
index string or int |
index of the output in the transaction being referenced |
Body Paramters
Parameter | Description |
---|---|
passphrase string |
passphrase of wallet being referenced |
Get Locked Outpoints
let id;
id="primary"
# Not supported in CLI
curl $walleturl/$id/locked
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
const wallet = walletClient.wallet(id);
(async () => {
const result = await wallet.getLocked();
console.log(result);
})();
Sample response:
[
{
"hash": "52ada542512ea95be425087ee4b891842d81eb6f9a4e0350f14d0285b5fd40c1",
"index": 0
}
]
Get all locked outpoints. Also see lockunspent and listlockunspent.
HTTP Request
GET /wallet/:id/locked
Request Parameters
Paramters | Description |
---|---|
id string |
id of wallet to check for outpoints |
Get Wallet Coin
let id, hash, index;
id="primary"
hash="d07a4211a3633bedd737b850378872191c27fc6126dc8131c3b45f62611a7f36"
index="1"
# command is wallet agnostic, same as in vanilla coin command
bcoin-cli coin $hash $index
curl $walleturl/$id/coin/$hash/$index
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
const wallet = walletClient.wallet(id);
(async () => {
const result = await wallet.getCoin(hash, index);
console.log(result);
})();
Sample response:
{
"version": 1,
"height": 533,
"value": 34296788338,
"script": "001442079abdd9a01b9ccc5c6822413c06ce4e0c53d0",
"address": "bcrt1qggre40we5qdeenzudq3yz0qxee8qc57s2fqygy",
"coinbase": false,
"hash": "d07a4211a3633bedd737b850378872191c27fc6126dc8131c3b45f62611a7f36",
"index": 1
}
Get wallet coin
HTTP Request
GET /wallet/:id/coin/:hash/:index
Request Parameters
Paramters | Description |
---|---|
id string |
id of wallet that contains the outpoint |
hash string |
hash of transaction that created the outpoint |
index string or int |
index of the output in the transaction being referenced |
Wallet Admin Commands
curl http://x:api-key@127.0.0.1:48334 # will access admin functions for regtest (port 48334) wallets
# examples in these docs will use an environment variable:
walletadminurl=http://x:api-key@127.0.0.1:48334/
curl $walletadminurl/<METHOD>
Admin commands are simply commands no specific to any particular wallet, and may impact all wallets on the system.
Additional security is available by specifying admin-token
in your configuration
if wallet-auth
is also enabled. If admin-token
is specified, add ?token=
to all admin requests.
This is highly recommended, especially on production instances.
Wallet Rescan
let height;
height=50
curl $walletadminurl/rescan \
-X POST \
--data '{"height": '$height'}'
bwallet-cli rescan $height
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
(async () => {
const result = await walletClient.rescan(height);
console.log(result);
})();
Response Body:
{"success": true}
Initiates a blockchain rescan for the walletdb. Wallets will be rolled back to the specified height (transactions above this height will be unconfirmed). For SPV nodes, a wallet
reascan will be ineffective since there are no blocks stored on disk. Therefore a
chain reset
must be called instead.
Example HTTP Request
POST /rescan?height=50
Wallet Resend
curl $walletadminurl/resend \
-X POST
bwallet-cli resend
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
(async () => {
result = await walletClient.resend();
console.log(result);
})();
Response Body:
{"success": true}
Rebroadcast all pending transactions in all wallets.
HTTP Request
POST /resend
Wallet Backup
let path;
path='/home/user/walletdb-backup.ldb'
curl $walletadminurl/backup?path=$path \
-X POST
bwallet-cli backup $path
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
(async () => {
const result = await walletClient.backup(path);
console.log(result);
})();
Response Body:
{"success": true}
Safely backup the wallet database to specified path (creates a clone of the database).
HTTP Request
POST /backup?path=/home/user/walletdb-backup.ldb
List all Wallets
curl $walletadminurl/wallet
bwallet-cli wallets
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
(async () => {
const result = await walletClient.getWallets();
console.log(result);
})();
Sample Response Body:
[
"primary",
"newWallet",
"multisig1",
"multisig2",
"watchonly1",
"multisig3",
"witness1"
]
List all wallet IDs. Returns an array of strings.
HTTP Request
GET /wallet
Wallet Transactions
Get Wallet TX Details
let id, hash
id="primary"
hash="c7dcd8f8923f8cd0d44d0d980ddd4da80f67290ef872aab0f7be5858210712f7"
bwallet-cli --id=$id tx $hash
curl $walleturl/$id/tx/$hash
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
const wallet = walletClient.wallet(id);
(async () => {
const result = await wallet.getTX(hash);
console.log(result);
})();
Sample Response
{
"hash": "292fbf4fb037a5354465e0a183d664b99477248f1dd14f47493a2a66a66f40b4",
"height": -1,
"block": null,
"time": 0,
"mtime": 1571774862,
"date": "1970-01-01T00:00:00Z",
"mdate": "2019-10-22T20:07:42Z",
"size": 226,
"virtualSize": 226,
"fee": 4540,
"rate": 20088,
"confirmations": 0,
"inputs": [
{
"value": 2500000000,
"address": "mhX1xHbKGzw3r8FoN5bUkmRixHPEDNywxh",
"path": {
"name": "default",
"account": 0,
"change": false,
"derivation": "m/0'/0/1"
}
}
],
"outputs": [
{
"value": 10000000,
"address": "mxbdj9hHDLK2TXD3Cztiy8BLiEuKPcsM5x",
"path": {
"name": "default",
"account": 0,
"change": false,
"derivation": "m/0'/0/5"
}
},
{
"value": 2489995460,
"address": "mjQqy8E7WJLaybxHcpiaWQMppjizi6nG3Y",
"path": {
"name": "default",
"account": 0,
"change": true,
"derivation": "m/0'/1/6"
}
}
],
"tx": "0100000001a02535c04f1791c7cee4a299d55179d998c23c41c039778ce10d7d3150695b10000000006b483045022100c7ce594aadde910687a6a86ee48a865221066d47b8a2323d10683076d399938e022048844ec1ad29c3733d13ac191a3bc89a1f07abc0f240ae631e5d146acc11f6e901210336c99e45e00b73c863497a989fe6feb08439ca2d7cf98f55bc261ed70ed28a7bffffffff0280969800000000001976a914bb5cb80bfffca7ba777ff3a8f7c33098faf9769188acc4506a94000000001976a9142ab8b9f49d7c3559b4228aa69b1e8cba0a7558d088ac00000000"
}
Get wallet transaction details.
HTTP Request
GET /wallet/:id/tx/:hash
Request Parameters
Parameter | Description |
---|---|
id string |
id of wallet that handled the transaction |
hash string |
hash of the transaction you're trying to retrieve |
Delete Transaction
let id, hash, passphrase;
id="primary"
hash="a97a9993389ae321b263dffb68ba1312ad0655da83aeca75b2372d5abc70544a"
# Not available in CLI
curl $walleturl/$id/tx/$hash \
-X DELETE
// Not available in javascript wallet client.
Abandon single pending transaction. Confirmed transactions will throw an error.
"TX not eligible"
HTTP Request
DEL /wallet/:id/tx/:hash
Paramters | Description |
---|---|
id string |
id of wallet where the transaction is that you want to remove |
hash string |
hash of transaction you would like to remove. |
Get Wallet TX History
let id;
id='primary'
bwallet-cli --id=$id history
curl $walleturl/$id/tx/history
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
const wallet = walletClient.wallet(id);
const account = 'default';
(async () => {
const result = await wallet.getHistory(account);
console.log(result);
})();
Sample Response
[
{
"hash": "292fbf4fb037a5354465e0a183d664b99477248f1dd14f47493a2a66a66f40b4",
"height": -1,
"block": null,
"time": 0,
"mtime": 1571774862,
"date": "1970-01-01T00:00:00Z",
"mdate": "2019-10-22T20:07:42Z",
"size": 226,
"virtualSize": 226,
"fee": 4540,
"rate": 20088,
"confirmations": 0,
"inputs": [
{
"value": 2500000000,
"address": "mhX1xHbKGzw3r8FoN5bUkmRixHPEDNywxh",
"path": {
"name": "default",
"account": 0,
"change": false,
"derivation": "m/0'/0/1"
}
}
],
"outputs": [
{
"value": 10000000,
"address": "mxbdj9hHDLK2TXD3Cztiy8BLiEuKPcsM5x",
"path": {
"name": "default",
"account": 0,
"change": false,
"derivation": "m/0'/0/5"
}
},
{
"value": 2489995460,
"address": "mjQqy8E7WJLaybxHcpiaWQMppjizi6nG3Y",
"path": {
"name": "default",
"account": 0,
"change": true,
"derivation": "m/0'/1/6"
}
}
],
"tx": "0100000001a02535c04f1791c7cee4a299d55179d998c23c41c039778ce10d7d3150695b10000000006b483045022100c7ce594aadde910687a6a86ee48a865221066d47b8a2323d10683076d399938e022048844ec1ad29c3733d13ac191a3bc89a1f07abc0f240ae631e5d146acc11f6e901210336c99e45e00b73c863497a989fe6feb08439ca2d7cf98f55bc261ed70ed28a7bffffffff0280969800000000001976a914bb5cb80bfffca7ba777ff3a8f7c33098faf9769188acc4506a94000000001976a9142ab8b9f49d7c3559b4228aa69b1e8cba0a7558d088ac00000000"
},
...
]
Get wallet TX history. Returns array of tx details.
HTTP Request
GET /wallet/:id/tx/history
Request Parameters
Paramter | Description |
---|---|
id string |
id of wallet to get history of |
Get Pending Transactions
let id;
id='primary'
bwallet-cli --id=$id pending
curl $walleturl/$id/tx/unconfirmed
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
const wallet = walletClient.wallet(id);
(async () => {
const result = await wallet.getPending();
console.log(result);
})();
Get pending wallet transactions. Returns array of tx details.
HTTP Request
GET /wallet/:id/tx/unconfirmed
Request Parameters
Paramter | Description |
---|---|
id string |
id of wallet to get pending/unconfirmed txs |
Get Range of Transactions
let id, account, start, end;
id="primary"
account="default"
start="1527184612"
end="1527186612"
# range not available in CLI
curl $walleturl/$id/tx/range?start=$start'&'end=$end
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
const wallet = walletClient.wallet(id);
(async () => {
const result = await wallet.getRange(account, {start: start, end: end});
console.log(result);
})();
Sample Response
[
{
"hash": "292fbf4fb037a5354465e0a183d664b99477248f1dd14f47493a2a66a66f40b4",
"height": -1,
"block": null,
"time": 0,
"mtime": 1571774862,
"date": "1970-01-01T00:00:00Z",
"mdate": "2019-10-22T20:07:42Z",
"size": 226,
"virtualSize": 226,
"fee": 4540,
"rate": 20088,
"confirmations": 0,
"inputs": [
{
"value": 2500000000,
"address": "mhX1xHbKGzw3r8FoN5bUkmRixHPEDNywxh",
"path": {
"name": "default",
"account": 0,
"change": false,
"derivation": "m/0'/0/1"
}
}
],
"outputs": [
{
"value": 10000000,
"address": "mxbdj9hHDLK2TXD3Cztiy8BLiEuKPcsM5x",
"path": {
"name": "default",
"account": 0,
"change": false,
"derivation": "m/0'/0/5"
}
},
{
"value": 2489995460,
"address": "mjQqy8E7WJLaybxHcpiaWQMppjizi6nG3Y",
"path": {
"name": "default",
"account": 0,
"change": true,
"derivation": "m/0'/1/6"
}
}
],
"tx": "0100000001a02535c04f1791c7cee4a299d55179d998c23c41c039778ce10d7d3150695b10000000006b483045022100c7ce594aadde910687a6a86ee48a865221066d47b8a2323d10683076d399938e022048844ec1ad29c3733d13ac191a3bc89a1f07abc0f240ae631e5d146acc11f6e901210336c99e45e00b73c863497a989fe6feb08439ca2d7cf98f55bc261ed70ed28a7bffffffff0280969800000000001976a914bb5cb80bfffca7ba777ff3a8f7c33098faf9769188acc4506a94000000001976a9142ab8b9f49d7c3559b4228aa69b1e8cba0a7558d088ac00000000"
},
...
]
Get range of wallet transactions by timestamp. Returns array of tx details.
HTTP Request
GET /wallet/:id/tx/range
Body Parameters
Paramter | Description |
---|---|
account string |
account to get the tx history from |
start int |
start time to get range from |
end int |
end time to get range from |
Wallet Accounts
Account Object
An account object looks like this:
{
"name": "default",
"initialized": true,
"witness": true,
"watchOnly": false,
"type": "pubkeyhash",
"m": 1,
"n": 1,
"accountIndex": 0,
"receiveDepth": 152,
"changeDepth": 89,
"nestedDepth": 2,
"lookahead": 10,
"receiveAddress": "bcrt1qp3kym2sv7k23ndpqrv4hhcpzcm392l97hq932m",
"changeAddress": "bcrt1qkezyz65tq8k5gfyhs5v6jgzeplwsq84cscmczf",
"nestedAddress": "2NFQrQQSTWWCG3A9du6UNbDeDw1K3BQqQdu",
"accountKey": "tpubDDkzvYzn2iJLqucWgnULe1x3DR5PCaZvWzpg13ZA395sFmbvKNG3XrPp3KpnbFrdE3R3c93w5ZVfU2XWBzde5LLCBR1YRy8XwMibN7sG39o",
"keys": [],
"balance": {
"tx": 157,
"coin": 80,
"unconfirmed": 102893658385,
"confirmed": 102893658385
}
}
Represents a BIP44 Account belonging to a Wallet. Note that this object does not enforce locks. Any method that does a write is internal API only and will lead to race conditions if used elsewhere.
From the BIP44 Specification:
This level splits the key space into independent user identities, so the wallet never mixes the coins across different accounts. Users can use these accounts to organize the funds in the same fashion as bank accounts; for donation purposes (where all addresses are considered public), for saving purposes, for common expenses etc. Accounts are numbered from index 0 in sequentially increasing manner. This number is used as child index in BIP32 derivation. Hardened derivation is used at this level.
Get Wallet Account List
id='primary'
curl $walleturl/$id/account
bwallet-cli account --id=$id list
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
const wallet = walletClient.wallet(id);
(async () => {
const result = await wallet.getAccounts();
console.log(result);
})();
Sample response:
[
"default"
]
List all account names (array indices map directly to bip44 account indices) associated with a specific wallet id.
HTTP Request
GET /wallet/:id/account
Parameters | Description |
---|---|
id string |
id of wallet you would like to retrieve the account list for |
Get Account Information
let id, account;
id='primary'
account='default'
curl $walleturl/$id/account/$account
bwallet-cli --id=$id account get $account
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
const wallet = walletClient.wallet(id);
(async () => {
const result = await wallet.getAccount(account);
console.log(result);
})();
Sample response:
{
"name": "default",
"initialized": true,
"witness": true,
"watchOnly": false,
"type": "pubkeyhash",
"m": 1,
"n": 1,
"accountIndex": 0,
"receiveDepth": 152,
"changeDepth": 89,
"nestedDepth": 2,
"lookahead": 10,
"receiveAddress": "bcrt1qp3kym2sv7k23ndpqrv4hhcpzcm392l97hq932m",
"changeAddress": "bcrt1qkezyz65tq8k5gfyhs5v6jgzeplwsq84cscmczf",
"nestedAddress": "2NFQrQQSTWWCG3A9du6UNbDeDw1K3BQqQdu",
"accountKey": "tpubDDkzvYzn2iJLqucWgnULe1x3DR5PCaZvWzpg13ZA395sFmbvKNG3XrPp3KpnbFrdE3R3c93w5ZVfU2XWBzde5LLCBR1YRy8XwMibN7sG39o",
"keys": [],
"balance": {
"tx": 157,
"coin": 80,
"unconfirmed": 102893658385,
"confirmed": 102893658385
}
}
Get account info.
HTTP Request
GET /wallet/:id/account/:account
Parameters | Description |
---|---|
id string |
id of wallet you would like to query |
account string |
id of account you would to retrieve information for |
Create new wallet account
let id, passphrase, name, type;
id='primary'
passphrase='secret123'
name='menace'
type='multisig'
bwallet-cli --id=$id account create --name=$name --type=$type --passphrase=$passphrase
curl $walleturl/$id/account/$name \
-X PUT \
--data '{"type": "'$type'", "passphrase": "'$passphrase'"}'
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
const wallet = walletClient.wallet(id);
const options = {name: name, type: type, passphrase: passphrase}
(async () => {
const result = await wallet.createAccount(name, options);
console.log(result);
})();
Sample response:
{
"name": "null",
"initialized": true,
"witness": false,
"watchOnly": false,
"type": "pubkeyhash",
"m": 1,
"n": 1,
"accountIndex": 3,
"receiveDepth": 1,
"changeDepth": 1,
"nestedDepth": 0,
"lookahead": 10,
"receiveAddress": "msciA3DK8mAAzj8u7MN53D8dYwXgHTwM59",
"changeAddress": "mkJNMxC1j4BWUmexzBbyM2T4uvnAGCFCV6",
"nestedAddress": null,
"accountKey": "tpubDC8ATY6G4mgAhJE9xRUEW2JNv6T5c1Vni7gKn1oUuwRzBh858H3Vx2baB8BG5Mh8UnLknZiT7nwnX8MHKKhKrUTduJXYdnskp43EJpSWdYB",
"keys": [],
"balance": {
"tx": 0,
"coin": 0,
"unconfirmed": 0,
"confirmed": 0
}
}
Create account with specified account name.
HTTP Request
PUT /wallet/:id/account/:name
Options object
Parameter | Description |
---|---|
name string |
name to give the account. Option can be account or name |
witness bool |
whether or not to act as segregated witness wallet account |
accountKey string |
the extended public key for the account. This is ignored for non watch only wallets. Watch only accounts can't accept private keys for import (or sign transactions) |
type string |
what type of wallet to make it ('multisig', 'pubkeyhash') |
m int |
for multisig accounts, what to make m in m-of-n |
n int |
for multisig accounts, what to make the n in m-of-n |
RPC Calls - Wallet
# examples in these docs will use a DIFFERENT environment variable
# than the built-in bcoin wallet API calls above:
walletrpcurl=http://x:api-key@127.0.0.1:48334/
curl $walletrpcurl \
-X POST \
--data '{ "method": "<method>", "params": [...] "id": "some-id" }'
bwallet-cli rpc <method> <params>
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
(async () => {
const result = await walletClient.execute('<method>', [ <params> ]);
console.log(result);
})();
Like the bcoin node RPC calls, the wallet RPC calls mimic Bitcoin Core's RPC.
Refer to the sections on the wallet client and the wallet db object for host, port, and authentication information.
RPC Calls are accepted at:
POST /
wallet RPC POST Parameters
Parameter | Description |
---|---|
method | Name of the RPC call |
params | Parameters accepted by method |
id | int Will be returned with the response (cURL only) |
selectwallet
let id;
id='primary'
curl $walletrpcurl \
-X POST \
--data '{
"method": "selectwallet",
"params": [ "'$id'" ]
}'
bwallet-cli rpc selectwallet $id
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
(async () => {
const result = await walletClient.execute('selectwallet', [id]);
console.log(result);
})();
The above command returns JSON "result" like this:
null
Switch target wallet for all future RPC calls.
Params
N. | Name | Default | Description |
---|---|---|---|
1 | id | Required | id of selected wallet |
getwalletinfo
curl $walletrpcurl \
-X POST \
--data '{ "method": "getwalletinfo" }'
bwallet-cli rpc getwalletinfo
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
(async () => {
const result = await walletClient.execute('getwalletinfo');
console.log(result);
})();
The above command returns JSON "result" like this:
{
"result": {
"walletid": "primary",
"walletversion": 6,
"balance": 50,
"unconfirmed_balance": 50,
"txcount": 1,
"keypoololdest": 0,
"keypoolsize": 0,
"unlocked_until": 0,
"paytxfee": 0
},
"error": null,
"id": null
}
Get basic wallet details.
Params
N. | Name | Default | Description |
---|---|---|---|
None. |
fundrawtransaction
let tx;
let options={"changeAddress": "mfi6TVtSYsNk4ADkXbFT9d6f95kmDMXgKp", "feeRate": 0.00001000};
tx='0100000000024e61bc00000000001976a914fbdd46898a6d70a682cbd34420ccf0b6bb64493788acf67e4929010000001976a9141b002b6fc0f457bf8d092722510fce9f37f0423b88ac00000000'
options='{"changeAddress": "mfi6TVtSYsNk4ADkXbFT9d6f95kmDMXgKp", "feeRate": 0.00001000}'
curl $walletrpcurl \
-X POST \
--data '{
"method": "fundrawtransaction",
"params": [ "'$tx'", '"$options"']
}'
options='{"changeAddress": "mfi6TVtSYsNk4ADkXbFT9d6f95kmDMXgKp", "feeRate": 0.00001000}'
bwallet-cli rpc fundrawtransaction $tx "$options"
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
(async () => {
const result = await walletClient.execute('fundrawtransaction', [tx, options]);
console.log(result);
})();
The above command returns JSON "result" like this:
Add inputs to a transaction until it has enough in value to meet its out value.
Params
N. | Name | Default | Description |
---|---|---|---|
1 | hexstring | Required | raw transaction |
2 | options | Optional | Object containing options |
Options
Option | Description |
---|---|
feeRate | Sets fee rate for transaction in BTC/kb |
changeAddress | Bitcoin address for change output of transaction |
resendwallettransactions
curl $walletrpcurl \
-X POST \
--data '{ "method": "resendwallettransactions" }'
bwallet-cli rpc resendwallettransactions
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
(async () => {
const result = await walletClient.execute('resendwallettransactions');
console.log(result);
})();
The above command returns JSON "result" like this:
[
"147c2527e2bb7ddfa855cc4b933ab288e05aa7816c487db69db344971f1b0951",
"c3c92d6686442755d70d2ea44401437d9fab51bc7a504b041d6d6b950ba45e85",
"77f09f2f307aaa62c8d36a9b8efeac368381c84ebd195e8aabc8ba3023ade390",
"2c0fa5740c494e8c86637c1fad645511d0379d3b6f18f84c1e8f7b6a040a399c",
"ef38a6b68afe74f637c1e1bc605f7dc810ef50c6f475a0a978bac9546cac25d8",
"1146d21bb5c46f1de745d9def68dafe97bbf917fe0f32cef31937731865f10e9"
]
Re-broadcasts all unconfirmed transactions to the network.
Params
N. | Name | Default | Description |
---|---|---|---|
None. |
abandontransaction
let tx;
tx='a0a65cd0508450e8acae76f35ae622e7b1e7980e95f50026b98b2c6e025dae6c'
curl $walletrpcurl \
-X POST \
--data '{
"method": "abandontransaction",
"params": [ "'$tx'" ]
}'
bwallet-cli rpc abandontransaction $tx
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
(async () => {
const result = await walletClient.execute('abandontransaction', [tx]);
console.log(result);
})();
The above command returns JSON "result" like this:
null
Remove transaction from the database. This allows "stuck" coins to be respent.
Params
N. | Name | Default | Description |
---|---|---|---|
1 | txid | Required | Transaction ID to remove |
addmultisigaddress
Not implemented -- Impossible to implement in bcoin (no address book).
addwitnessaddress
Not implemented -- Deprecated in Bitcoin Core 0.16.0
backupwallet
let path;
path='/home/user/WalletBackup'
curl $walletrpcurl \
-X POST \
--data '{
"method": "backupwallet",
"params": [ "'$path'" ]
}'
bwallet-cli rpc backupwallet $path
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
(async () => {
const result = await walletClient.execute('backupwallet', [path]);
console.log(result);
})();
The above command returns JSON "result" like this:
null
Back up wallet database and files to directory created at specified path.
Params
N. | Name | Default | Description |
---|---|---|---|
1 | path | Required | Path and name of destination directory for backup |
dumpprivkey
let address;
address='msKYwEVXcKBxatPMfFLdVwYug6bz4YS87J'
curl $walletrpcurl \
-X POST \
--data '{
"method": "dumpprivkey",
"params": [ "'$address'" ]
}'
bwallet-cli rpc dumpprivkey $address
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
(async () => {
const result = await walletClient.execute('dumpprivkey', [address]);
console.log(result);
})();
The above command returns JSON "result" like this:
cNRiqwzRfcUfokNV8nSnDKb3NsKPhfRV2z5kBN11GKFb3GXkk1Hj
Get the private key (WIF format) corresponding to specified address. Also see importprivkey
Params
N. | Name | Default | Description |
---|---|---|---|
1 | address | Required | Reveal the private key for this Bitcoin address |
dumpwallet
let path;
path='/home/user-1/secretfiles/dump1.txt'
curl $walletrpcurl \
-X POST \
--data '{
"method": "dumpwallet",
"params": [ "'$path'" ]
}'
bwallet-cli rpc dumpwallet $path
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
(async () => {
const result = await walletClient.execute('dumpwallet', [path]);
console.log(result);
})();
The above command returns JSON "result" like this:
null
The contents of the wallet dump file are formatted like this:
# Wallet Dump created by Bcoin 2.0.0-dev
# * Created on 2019-10-22T18:29:15Z
# * Best block at time of backup was 845 (72365e9f4b4ed638bb1600116a67e3fa59b6ad6be2a449b675db607a984da4f8).
# * File: /home/user-1/secretfiles/dump1.txt
cNUUoZYmUGoJyodrNaohzfu6LmKy7pBk6yqubJcTeL5WPWw97DQ1 2019-10-22T18:29:15Z label= addr=mg54SV2ZubNQ5urTbd42mUsQ54byPvSg5j
cNH7YBw6haTB3yWkAndoPhwXRLNibXjWAYpqRQdvqPKLeW7JAj6h 2019-10-22T18:29:15Z change=1 addr=mgj4oGTbvCHxvx4EESYJKPkXWamxh2R6ef
cNmBeL4kpjLtNZcvjSezftq4ks6ajzZRi1z2AGpuBGy6XjxzytiQ 2019-10-22T18:29:15Z label= addr=mhX1xHbKGzw3r8FoN5bUkmRixHPEDNywxh
cUEfRrvPpKCy87QReCmPmd74Hz68kgZEHAErkuvEDFqwJKcCLsMn 2019-10-22T18:29:15Z label= addr=mhcx3M1AitoiwDQS3sz42CQLpVCEVkJLfq
cP4N8mxe81DhZfrgTz2GoV3croXD2o6Hern4DTB6Gr5jUwoLkT8h 2019-10-22T18:29:15Z change=1 addr=mhpSYq8bnM5XJVbpafdLNUtLZefr2d6xSq
...
# End of dump
Creates a new human-readable file at specified path with all wallet private keys in Wallet Import Format (base58).
Params
N. | Name | Default | Description |
---|---|---|---|
1 | path | Required | Path and name of destination file for dump |
encryptwallet
let passphrase;
passphrase='bikeshed'
curl $walletrpcurl \
-X POST \
--data '{
"method": "encryptwallet",
"params": [ "'$passphrase'" ]
}'
bwallet-cli rpc encryptwallet $passphrase
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
(async () => {
const result = await walletClient.execute('encryptwallet', [passphrase]);
console.log(result);
})();
The above command returns JSON "result" like this:
wallet encrypted; we do not need to stop!
Encrypts wallet with provided passphrase. This action can only be done once on an unencrypted wallet. See walletpassphrasechange or change passphrase if wallet has already been encrypted.
Params
N. | Name | Default | Description |
---|---|---|---|
1 | passphrase | Required | Strong passphrase with which to encrypt wallet |
getaccountaddress
let account;
account='default'
curl $walletrpcurl \
-X POST \
--data '{
"method": "getaccountaddress",
"params": [ "'$account'" ]
}'
bwallet-cli rpc getaccountaddress $account
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
(async () => {
const result = await walletClient.execute('getaccountaddress', [account]);
console.log(result);
})();
The above command returns JSON "result" like this:
bcrt1qp3kym2sv7k23ndpqrv4hhcpzcm392l97hq932m
Get the current receiving address for specified account.
Params
N. | Name | Default | Description |
---|---|---|---|
1 | account | Required | Account to retrieve address from |
getaccount
let address;
address='bcrt1qp3kym2sv7k23ndpqrv4hhcpzcm392l97hq932m'
curl $walletrpcurl \
-X POST \
--data '{
"method": "getaccount",
"params": [ "'$address'" ]
}'
bwallet-cli rpc getaccount $address
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
(async () => {
const result = await walletClient.execute('getaccount', [address]);
console.log(result);
})();
The above command returns JSON "result" like this:
default
Get the account associated with a specified address.
Params
N. | Name | Default | Description |
---|---|---|---|
1 | address | Required | Address to search for |
getaddressesbyaccount
let account;
account='default'
curl $walletrpcurl \
-X POST \
--data '{
"method": "getaddressesbyaccount",
"params": [ "'$account'" ]
}'
bwallet-cli rpc getaddressesbyaccount $account
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
(async () => {
const result = await walletClient.execute('getaddressesbyaccount', [account]);
console.log(result);
})();
The above command returns JSON "result" like this:
[
"mg54SV2ZubNQ5urTbd42mUsQ54byPvSg5j",
"mgj4oGTbvCHxvx4EESYJKPkXWamxh2R6ef",
"mhX1xHbKGzw3r8FoN5bUkmRixHPEDNywxh",
"mhcx3M1AitoiwDQS3sz42CQLpVCEVkJLfq",
"mhpSYq8bnM5XJVbpafdLNUtLZefr2d6xSq",
...
"mjQqy8E7WJLaybxHcpiaWQMppjizi6nG3Y"
]
Get all addresses for a specified account.
Params
N. | Name | Default | Description |
---|---|---|---|
1 | account | Required | Account name |
getbalance
curl $walletrpcurl \
-X POST \
--data '{ "method": "getbalance" }'
bwallet-cli rpc getbalance
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
(async () => {
const result = await walletClient.execute('getbalance');
console.log(result);
})();
The above command returns JSON "result" like this:
50.01205819
Get total balance for entire wallet or a single, specified account.
Params
N. | Name | Default | Description |
---|---|---|---|
1 | account | Optional | Account name |
getnewaddress
let account;
account='default'
curl $walletrpcurl \
-X POST \
--data '{
"method": "getnewaddress",
"params": [ "'$account'" ]
}'
bwallet-cli rpc getnewaddress $account
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
(async () => {
const result = await walletClient.execute('getnewaddress', [account]);
console.log(result);
})();
The above command returns JSON "result" like this:
msSaQkCXyrEefbSH9TCSWNjnacTwGGc55d
Get the next receiving address from specified account, or default
account.
Params
N. | Name | Default | Description |
---|---|---|---|
1 | account | Optional | Account name |
getrawchangeaddress
curl $walletrpcurl \
-X POST \
--data '{ "method": "getrawchangeaddress" }'
bwallet-cli rpc getrawchangeaddress
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
(async () => {
const result = await walletClient.execute('getrawchangeaddress');
console.log(result);
})();
The above command returns JSON "result" like this:
moKaYJdRT19YUWSsfhnTQpo68wkVvzkk8y
Get the next change address from specified account.
Params
N. | Name | Default | Description |
---|---|---|---|
None. |
getreceivedbyaccount
let account, minconf;
account='default'
minconf=6
curl $walletrpcurl \
-X POST \
--data '{
"method": "getreceivedbyaccount",
"params": [ "'$account'", '$minconf' ]
}'
bwallet-cli rpc getreceivedbyaccount $account $minconf
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
(async () => {
const result = await walletClient.execute('getreceivedbyaccount', [account, minconf]);
console.log(result);
})();
The above command returns JSON "result" like this:
50.00001234
Get total amount received by specified account.
Optionally only count transactions with minconf
number of confirmations.
Params
N. | Name | Default | Description |
---|---|---|---|
1 | account | Required | Account name |
2 | minconf | Optional | Only include transactions with this many confirmations |
getreceivedbyaddress
let address, minconf;
address='bcrt1quvydwldtduzjpdz8nm79d30g49nt6u5nurw0dt'
minconf=6
curl $walletrpcurl \
-X POST \
--data '{
"method": "getreceivedbyaddress",
"params": [ "'$address'", '$minconf' ]
}'
bwallet-cli rpc getreceivedbyaddress $address $minconf
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
(async () => {
const result = await walletClient.execute('getreceivedbyaddress', [address, minconf]);
console.log(result);
})();
The above command returns JSON "result" like this:
50.00001234
Get total amount received by specified address.
Optionally only count transactions with minconf
number of confirmations.
Params
N. | Name | Default | Description |
---|---|---|---|
1 | address | Required | Address to request balance of |
2 | minconf | Optional | Only include transactions with this many confirmations |
gettransaction
let address, minconf;
txid='36cbb7ad0cc98ca86640a04c485f164dd741c20339af34516d359ecba2892c21'
curl $walletrpcurl \
-X POST \
--data '{
"method": "gettransaction",
"params": [ "'$txid'" ]
}'
bwallet-cli rpc gettransaction $txid
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
(async () => {
const result = await walletClient.execute('gettransaction', [txid]);
console.log(result);
})();
The above command returns JSON "result" like this:
{
"amount": 0.00072058,
"blockhash": "1134065cc665e4f6df36202307ea1c9ad31287c45a7b9a5196e446885a76fc1c",
"blocktime": 1571760038,
"txid": "bc8336f7bb88e9613d5d1e81bef73837d8ec1c2bd47b9e19c3c4bf1eeb7e03b8",
"walletconflicts": [],
"time": 1571759979,
"timereceived": 1571759979,
"bip125-replaceable": "no",
"details": [
{
"account": "default",
"address": "bcrt1qvjewtg83j8w7halz0h2axlwcn6c2ver4u75avy",
"category": "receive",
"amount": 0.00072058,
"label": "default",
"vout": 1
}
],
"hex": "010000000001013384747e0e0d5f7a8dfff4220c5bc25479a4abf674abe9ac5e5b77da7b2973050400000000ffffffff038f8f0000000000001976a9149a006584ab0383ef07ad289395118ed9fba0e45688ac7a1901000000000016001464b2e5a0f191ddebf7e27dd5d37dd89eb0a66475d97249fc0700000016001449f1b89f0b09bbf77f33035ed3d4c30bd90eade90248304502210098989192ba64b6d1008e6137bbffffcfc7c8b7d4d05fb4a03b6906f9ce1e6ed302204bf8c7915ed4b35b6120901fc7459b2dcfe62567f7d6649d451a2136ba15f6700121029bf6c7b020b6e106b8492c6a3d396a265566c6294f553d10557a274d572a0e9e00000000"
}
Get details about a transaction in the wallet.
Params
N. | Name | Default | Description |
---|---|---|---|
1 | txid | Required | ID of transaction to fetch |
2 | watchonly | Optional | (bool) Whether to include watch-only addresses in balance details |
getunconfirmedbalance
curl $walletrpcurl \
-X POST \
--data '{ "method": "getunconfirmedbalance" }'
bwallet-cli rpc getunconfirmedbalance
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
(async () => {
const result = await walletClient.execute('getunconfirmedbalance');
console.log(result);
})();
The above command returns JSON "result" like this:
50
Get the unconfirmed balance from the wallet.
Params
N. | Name | Default | Description |
---|---|---|---|
None. |
importprivkey
let key, label, rescan;
key='cNH7YBw6haTB3yWkAndoPhwXRLNibXjWAYpqRQdvqPKLeW7JAj6h'
label='this_is_ignored'
rescan=false
curl $walletrpcurl \
-X POST \
--data '{
"method": "importprivkey",
"params": [ "'$key'", "'$label'", '$rescan' ]
}'
bwallet-cli rpc importprivkey $key $label $rescan
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
(async () => {
const result = await walletClient.execute('importprivkey', [key, label, rescan]);
console.log(result);
})();
The above command returns JSON "result" like this:
null
Import a private key into wallet. Also see dumpprivkey.
Params
N. | Name | Default | Description |
---|---|---|---|
1 | key | Required | Private key to import (WIF format) |
2 | label | Optional | Ignored but required if additional parameters are passed |
3 | rescan | Optional | (bool) Whether to rescan wallet after importing |
importwallet
let file, rescan;
file='/home/user/WalletDump'
rescan=false
curl $walletrpcurl \
-X POST \
--data '{
"method": "importwallet",
"params": [ "'$file'", '$rescan' ]
}'
bwallet-cli rpc importwallet $file $rescan
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
(async () => {
const result = await walletClient.execute('importwallet', [file, rescan]);
console.log(result);
})();
The above command returns JSON "result" like this:
null
Import all keys from a wallet backup file. Also see dumpwallet.
Params
N. | Name | Default | Description |
---|---|---|---|
1 | file | Required | Path to wallet file |
2 | rescan | Optional | (bool) Whether to rescan wallet after importing |
importaddress
let address;
address='mg54SV2ZubNQ5urTbd42mUsQ54byPvSg5j'
curl $walletrpcurl \
-X POST \
--data '{
"method": "importaddress",
"params": [ "'$address'" ]
}'
bwallet-cli rpc importaddress $address
# P2SH example, imports script as address 2N57YNxkxUcUR9tXHsdEsvybTaAdsdc4fx
bwallet-cli rpc importaddress 76a9145e50fb5b7475ebe2f7276ed3f29662e5321d1d7288ac "this_is_ignored" true true
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
(async () => {
const result = await walletClient.execute('importaddress', [address]);
console.log(result);
})();
The above command returns JSON "result" like this:
null
Import address to a watch-only wallet. May also import a Bitcoin script (in hex) as pay-to-script-hash (P2SH) address.
Params
N. | Name | Default | Description |
---|---|---|---|
1 | address | Required | Address to watch in wallet |
2 | label | Optional | Ignored but required if additional parameters are passed |
3 | rescan | Optional | (bool) Whether to rescan wallet after importing |
4 | p2sh | Optional | (bool) Whether to generate P2SH address from given script |
importprunedfunds
let rawtx, txoutproof;
rawtx='01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff1e510e6d696e65642062792062636f696e048e0e9256080000000000000000ffffffff0100f2052a010000001976a9145e50fb5b7475ebe2f7276ed3f29662e5321d1d7288ac00000000'
txoutproof='0000002006226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f212c89a2cb9e356d5134af3903c241d74d165f484ca04066a88cc90cadb7cb36e749355bffff7f20040000000100000001212c89a2cb9e356d5134af3903c241d74d165f484ca04066a88cc90cadb7cb360101'
curl $walletrpcurl \
-X POST \
--data '{
"method": "importprunedfunds",
"params": [ "'$rawtx'", "'$txoutproof'" ]
}'
bwallet-cli rpc importprunedfunds $rawtx $txoutproof
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
(async () => {
const result = await walletClient.execute('importprunedfunds', [rawtx, txoutproof]);
console.log(result);
})();
The above command returns JSON "result" like this:
null
Imports funds (without rescan) into pruned wallets. Corresponding address or script must previously be included in wallet. Does NOT check if imported coins are already spent, rescan may be required after the point in time in which the specified transaciton was included in the blockchain. See gettxoutproof and removeprunedfunds.
Params
N. | Name | Default | Description |
---|---|---|---|
1 | rawtx | Required | Raw transaction in hex that funds an address already in the wallet |
2 | txoutproof | Required | Hex output from gettxoutproof containing the tx |
importpubkey
let pubkey;
pubkey='02548e0a23b90505f1b4017f52cf2beeaa399fce7ff2961e29570c6afdfa9bfc5b'
curl $walletrpcurl \
-X POST \
--data '{
"method": "importpubkey",
"params": [ "'$pubkey'" ]
}'
bwallet-cli rpc importpubkey $pubkey
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
(async () => {
const result = await walletClient.execute('importpubkey', [pubkey]);
console.log(result);
})();
The above command returns JSON "result" like this:
null
Import public key to a watch-only wallet.
Params
N. | Name | Default | Description |
---|---|---|---|
1 | pubkey | Required | Hex-encoded public key |
2 | label | Optional | Ignored but required if additional parameters are passed |
3 | rescan | Optional | (bool) Whether to rescan wallet after importing |
keypoolrefill
let newsize;
newsize=100
curl $walletrpcurl \
-X POST \
--data '{
"method": "keypoolrefill",
"params": [ '$newsize' ]
}'
bwallet-cli rpc keypoolrefill $newsize
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
(async () => {
const result = await walletClient.execute('keypoolrefill', [newsize]);
console.log(result);
})();
The above command returns JSON "result" like this:
null
Params
N. | Name | Default | Description |
---|---|---|---|
1 | newsize | Required | The new keypool size |
listaccounts
let minconf, watchonly;
minconf=6
watchonly=false
curl $walletrpcurl \
-X POST \
--data '{
"method": "listaccounts",
"params": [ '$minconf', '$watchonly' ]
}'
bwallet-cli rpc listaccounts $minconf $watchonly
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
(async () => {
const result = await walletClient.execute('listaccounts', [minconf, watchonly]);
console.log(result);
})();
The above command returns JSON "result" like this:
{
"default": 46.87650028,
"savings": 9.37345432
}
Get list of account names and balances.
Params
N. | Name | Default | Description |
---|---|---|---|
1 | minconf | Optional | Minimum confirmations for transaction to be included in balance |
2 | watchonly | Optional | (bool) Include watch-only addresses |
listaddressgroupings
Not implemented.
lockunspent
let unlock, outputs;
outputs=[{ "txid": "3962a06342fc62a733700d74c075a5d24c4f44f7108f6d9a318b66e92e3bdc72", "vout": 1 }];
unlock=false
outputs='[{ "txid": "3962a06342fc62a733700d74c075a5d24c4f44f7108f6d9a318b66e92e3bdc72", "vout": 1 }]'
curl $walletrpcurl \
-X POST \
--data '{
"method": "lockunspent",
"params": [ '$unlock', '"$outputs"' ]
}'
outputs='[{ "txid": "3962a06342fc62a733700d74c075a5d24c4f44f7108f6d9a318b66e92e3bdc72", "vout": 1 }]'
bwallet-cli rpc lockunspent $unlock "$outputs"
# unlock all coins
bwallet-cli rpc lockunspent true
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
(async () => {
const result = await walletClient.execute('lockunspent', [unlock, outputs]);
console.log(result);
})();
The above command returns JSON "result" like this:
true
Lock or unlock specified transaction outputs. If no outputs are specified,
ALL coins will be unlocked (unlock
only).
Params
N. | Name | Default | Description |
---|---|---|---|
1 | unlock | Required | (bool) true = unlock coins, false = lock coins |
2 | outputs | Optional | Array of outputs to lock or unlock |
listlockunspent
curl $walletrpcurl \
-X POST \
--data '{ "method": "listlockunspent" }'
bwallet-cli rpc listlockunspent
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
(async () => {
const result = await walletClient.execute('listlockunspent');
console.log(result);
})();
The above command returns JSON "result" like this:
[
{
"txid": "3962a06342fc62a733700d74c075a5d24c4f44f7108f6d9a318b66e92e3bdc72",
"vout": 1
}
]
Get list of currently locked (unspendable) outputs. See lockunspent and lock-coin-outpoints.
Params
N. | Name | Default | Description |
---|---|---|---|
None. |
listreceivedbyaccount
let minconf, includeEmpty, watchOnly;
minconf=1
includeEmpty=true
watchOnly=true
curl $walletrpcurl \
-X POST \
--data '{
"method": "listreceivedbyaccount",
"params": [ '$minconf', '$includeEmpty', '$watchOnly' ]
}'
bwallet-cli rpc listreceivedbyaccount $minconf $includeEmpty $watchOnly
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
(async () => {
const result = await walletClient.execute('listreceivedbyaccount', [minconf, includeEmpty, watchOnly]);
console.log(result);
})();
The above command returns JSON "result" like this:
[
{
"involvesWatchonly": false,
"account": "hot",
"amount": 6.2500454,
"confirmations": 0,
"label": ""
},
{
"involvesWatchonly": false,
"account": "default",
"amount": 96.87650028,
"confirmations": 0,
"label": ""
},
{
"involvesWatchonly": false,
"account": "savings",
"amount": 9.37345432,
"confirmations": 0,
"label": ""
}
]
Get balances for all accounts in wallet.
Params
N. | Name | Default | Description |
---|---|---|---|
1 | minconf | Optional | Minimum confirmations required to count a transaction |
2 | includeEmpty | Optional | (bool) Whether to include accounts with zero balance |
3 | watchOnly | Optional | (bool) Whether to include watch-only addresses |
listreceivedbyaddress
let minconf, includeEmpty, watchOnly;
minconf=1
includeEmpty=false
watchOnly=false
curl $walletrpcurl \
-X POST \
--data '{
"method": "listreceivedbyaddress",
"params": [ '$minconf', '$includeEmpty', '$watchOnly' ]
}'
bwallet-cli rpc listreceivedbyaddress $minconf $includeEmpty $watchOnly
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
(async () => {
const result = await walletClient.execute('listreceivedbyaddress', [minconf, includeEmpty, watchOnly]);
console.log(result);
})();
The above command returns JSON "result" like this:
[
{
"involvesWatchonly": true,
"address": "bcrt1ql8ll4v0u83uf3ghafr9f6c5slhnn7dfrxm499g",
"account": "default",
"amount": 0.00030033,
"confirmations": 313,
"label": ""
},
{
"involvesWatchonly": true,
"address": "bcrt1qlfeauahf7jdpruxm6f2vax2yu3xsdkkw2z7n9g",
"account": "default",
"amount": 0.00015496,
"confirmations": 321,
"label": ""
},
{
"involvesWatchonly": true,
"address": "bcrt1qlaawtlmdcfjdegghxvdh5pqphk5fjhlevsup7s",
"account": "default",
"amount": 342.97828963,
"confirmations": 348,
"label": ""
},
...
{
"involvesWatchonly": true,
"address": "bcrt1ql797szp8tvdday5r3zpeepc8fjfk4qs09uaq7t",
"account": "default",
"amount": 0.00091418,
"confirmations": 337,
"label": ""
}
]
Get balances for all addresses in wallet.
Params
N. | Name | Default | Description |
---|---|---|---|
1 | minconf | Optional | Minimum confirmations required to count a transaction |
2 | includeEmpty | Optional | (bool) Whether to include addresses with zero balance |
3 | watchOnly | Optional | (bool) Whether to include watch-only addresses |
listsinceblock
let block, minconf, watchOnly;
block='26b5e76dcdfc51b94e8e09ca1cf55b453e6c542b7abb863df0a306c6f00ebc8e'
minconf=1
watchOnly=false
curl $walletrpcurl \
-X POST \
--data '{
"method": "listsinceblock",
"params": [ "'$block'", '$minconf', '$watchOnly' ]
}'
bwallet-cli rpc listsinceblock $block $minconf $watchOnly
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
(async () => {
const result = await walletClient.execute('listsinceblock', [block, minconf, watchOnly]);
console.log(result);
})();
The above command returns JSON "result" like this:
{
"transactions": [
{
"account": "default",
"address": "bcrt1q730jd9qryjjd7wqyc3aw72mu8u3804m3qxz3qe",
"category": "receive",
"amount": 0.00036954,
"label": "default",
"vout": 0,
"confirmations": 314,
"blockhash": "142abcc5469da7684c84404f93b247b7948dc36933cd438360f611d05f3c62b8",
"blockindex": -1,
"blocktime": 1571760040,
"blockheight": 532,
"txid": "5f5f496a6095f729755e22eec19484c0e2ea4b144ab266be722e0fe7e5a2ea98",
"walletconflicts": [],
"time": 1571759982,
"timereceived": 1571759982,
"bip125-replaceable": "no"
},
{
"account": "default",
"address": "bcrt1qy86kqv3cxfqkemu4e7f6kzxzk2cyt6j6vsxptz",
"category": "receive",
"amount": 0.00050209,
"label": "default",
"vout": 2,
"confirmations": 316,
"blockhash": "34d0385c667319c5225c7f82e025681bae2fb5df28809cc7cf432b491125c83c",
"blockindex": -1,
"blocktime": 1571760040,
"blockheight": 530,
"txid": "9b7899e0800389aa293578ea14d03f9c7d0249faaced52c2120c20cde8f0479b",
"walletconflicts": [],
"time": 1571759982,
"timereceived": 1571759982,
"bip125-replaceable": "no"
},
{
"account": "default",
"address": "bcrt1q8nnvw4h09u6avx4tn8gkrx4t9ayd56v86q7ceg",
"category": "receive",
"amount": 0.00037547,
"label": "default",
"vout": 0,
"confirmations": 316,
"blockhash": "34d0385c667319c5225c7f82e025681bae2fb5df28809cc7cf432b491125c83c",
"blockindex": -1,
"blocktime": 1571760040,
"blockheight": 530,
"txid": "77a39583060aa3ff2a705d401fea0c07e77e95d66cc10b744dc95098cad1bee1",
"walletconflicts": [],
"time": 1571759981,
"timereceived": 1571759981,
"bip125-replaceable": "no"
}
],
"lastblock": "20b062aa8ff8a1611b86016c8ba4f0cec0a6c55b69f1f0431190018bd23d5aec"
}
Get all transactions in blocks since a block specified by hash, or all transactions if no block is specifiied.
Params
N. | Name | Default | Description |
---|---|---|---|
1 | block | Optional | Hash of earliest block to start listing from |
2 | minconf | Optional | Minimum confirmations required to count a transaction |
3 | watchOnly | Optional | (bool) Whether to include watch-only addresses |
listtransactions
let account, count, from, watchOnly;
account='hot'
curl $walletrpcurl \
-X POST \
--data '{
"method": "listtransactions",
"params": [ "'$account'" ]
}'
bwallet-cli rpc listtransactions $account
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
(async () => {
const result = await walletClient.execute('listtransactions', [account]);
console.log(result);
})();
The above command returns JSON "result" like this:
[
{
"account": "default",
"address": "bcrt1qpqgnssrdfkfv9pkdj23c7k9w02x8n9ezv4nm3z",
"category": "receive",
"amount": 0.00013937,
"label": "default",
"vout": 1,
"confirmations": 406,
"blockhash": "2ad44c048bc555d18f06d31065856ab3ea24c9a749d579f036aef102bddeabf9",
"blockindex": -1,
"blocktime": 1571760025,
"blockheight": 440,
"txid": "675d4f09e1da5e9d8268de41ecdbb77795d738333caf6a7c86775211c19b6550",
"walletconflicts": [],
"time": 1571759957,
"timereceived": 1571759957,
"bip125-replaceable": "no"
},
{
"account": "",
"address": "bcrt1qh7jclanaex66gpkr5x4duyd45nltxvpppcqnw6",
"category": "send",
"amount": -0.00125648,
"vout": 1,
"confirmations": 404,
"blockhash": "53441b98c5286ef75e9aa431b2dd44adbef840b04a3b6c07ca79ff6a5e599373",
"blockindex": -1,
"blocktime": 1571760025,
"blockheight": 442,
"txid": "725ca556002481e4445110fa4c67fb31d4fdf436e4939bf3c8fa7ff93b1b6c89",
"walletconflicts": [],
"time": 1571759957,
"timereceived": 1571759957,
"bip125-replaceable": "no"
},
{
"account": "default",
"address": "bcrt1qpc0fu2fl3hdhf0kaheta67gzdfmfe90ga27pr6",
"category": "receive",
"amount": 0.00044896,
"label": "default",
"vout": 1,
"confirmations": 407,
"blockhash": "39e8e1d9f19389a3b92c5e024e5d7070fe48f4ca7bd0d045b119c09a155cebbf",
"blockindex": -1,
"blocktime": 1571760024,
"blockheight": 439,
"txid": "e346029655b10a9cd4df74d87d4001b1fd11ee7a6f53ab556cadb27ce160be14",
"walletconflicts": [],
"time": 1571759957,
"timereceived": 1571759957,
"bip125-replaceable": "no"
}
]
Get all recent transactions for specified account up to a limit, starting from a specified index.
Params
N. | Name | Default | Description |
---|---|---|---|
1 | account | Optional | Account name |
2 | count | Optional | Max number of transactions to return |
3 | from | Optional | Number of oldest transactions to skip |
4 | watchOnly | Optional | Whether to include watch-only addresses |
listunspent
let minconf, maxconf, addrs;
addrs=["bcrt1qggre40we5qdeenzudq3yz0qxee8qc57s2fqygy"];
minconf=0
maxconf=20
addrs='["bcrt1qggre40we5qdeenzudq3yz0qxee8qc57s2fqygy"]'
curl $walletrpcurl \
-X POST \
--data '{
"method": "listunspent",
"params": [ '$minconf', '$maxconf', '"$addrs"' ]
}'
addrs='["bcrt1qggre40we5qdeenzudq3yz0qxee8qc57s2fqygy"]'
bwallet-cli rpc listunspent $minconf $maxconf $addrs
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
(async () => {
const result = await walletClient.execute('listunspent', [minconf, maxconf, addrs]);
console.log(result);
})();
The above command returns JSON "result" like this:
[
{
"txid": "d07a4211a3633bedd737b850378872191c27fc6126dc8131c3b45f62611a7f36",
"vout": 1,
"address": "bcrt1qggre40we5qdeenzudq3yz0qxee8qc57s2fqygy",
"account": "default",
"scriptPubKey": "001442079abdd9a01b9ccc5c6822413c06ce4e0c53d0",
"amount": 342.96788338,
"confirmations": 313,
"spendable": true,
"solvable": true
}
]
Get unsepnt transaction outputs from all addreses, or a specific set of addresses.
Params
N. | Name | Default | Description |
---|---|---|---|
1 | minconf | Optional | Minimum confirmations required to return tx |
2 | maxconf | Optional | Maximum confirmations required to return tx |
3 | addrs | Optional | Array of addresses to filter |
move
Not implemented -- Deprecated in Bitcoin Core
sendfrom
let fromaccount, tobitcoinaddress, amount;
fromaccount='hot'
tobitcoinaddress='bcrt1qggre40we5qdeenzudq3yz0qxee8qc57s2fqygy'
amount=0.0195
curl $walletrpcurl \
-X POST \
--data '{
"method": "sendfrom",
"params": [ "'$fromaccount'", "'$tobitcoinaddress'", '$amount' ]
}'
bwallet-cli rpc sendfrom $fromaccount $tobitcoinaddress $amount
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
(async () => {
const result = await walletClient.execute('sendfrom', [fromaccount, tobitcoinaddress, amount]);
console.log(result);
})();
The above command returns JSON "result" like this:
94f8a6dbaea9b5863d03d3b606c24e2e588d9e82564972148d54058660308e6a
Send Bitcoin from an account to an address.
Params
N. | Name | Default | Description |
---|---|---|---|
1 | fromaccount | Required | Wallet account to spend outputs from |
2 | tobitcoinaddress | Required | Bitcoin address to send funds to |
3 | amount | Required | Amount (in BTC) to send |
4 | minconf | Optional | Minimum confirmations for output to be spent from |
5 | comment | Optional | not implemented in bcoin |
6 | comment_to | Optional | not implemented in bcoin |
sendmany
let fromaccount, outputs, minconf, label, subtractFee;
outputs={"msSaQkCXyrEefbSH9TCSWNjnacTwGGc55d": 0.123, "moKaYJdRT19YUWSsfhnTQpo68wkVvzkk8y": 0.321}
fromaccount='hot'
minconf=1
label="this_is_ignored"
subtractfee=false
outputs='{"msSaQkCXyrEefbSH9TCSWNjnacTwGGc55d": 0.123, "moKaYJdRT19YUWSsfhnTQpo68wkVvzkk8y": 0.321}'
curl $walletrpcurl \
-X POST \
--data '{
"method": "sendmany",
"params": [ "'$fromaccount'", '"$outputs"', '$minconf', "'$label'", '$subtractfee' ]
}'
outputs='{"msSaQkCXyrEefbSH9TCSWNjnacTwGGc55d": 0.123, "moKaYJdRT19YUWSsfhnTQpo68wkVvzkk8y": 0.321}'
bwallet-cli rpc sendmany $fromaccount "$outputs" $minconf $label $subtractfee
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
(async () => {
const result = await walletClient.execute('sendmany', [fromaccount, outputs, minconf, label, subtractfee]);
console.log(result);
})();
The above command returns JSON "result" like this:
121d1e44f8125f02433e96c7b672a34af00be9906895f0ee51aaf504f4d76b78
Send different amounts of Bitcoin from an account to multiple addresses.
Params
N. | Name | Default | Description |
---|---|---|---|
1 | fromaccount | Required | Wallet account to spend outputs from |
2 | outputs | Required | Array of Bitcoin addresses and amounts to send |
3 | minconf | Optional | Minimum confirmations for output to be spent from |
5 | label | Optional | Ignored but required if additional parameters are passed |
6 | subtractfee | Optional | (bool) Subtract the transaction fee equally from the output amounts |
sendtoaddress
let address, amount, comment, comment_to, subtractFee;
address='moKaYJdRT19YUWSsfhnTQpo68wkVvzkk8y'
amount=1.01010101
comment="this_is_ignored"
comment_to="this_is_ignored"
subtractfee=true
curl $walletrpcurl \
-X POST \
--data '{
"method": "sendtoaddress",
"params": [ "'$address'", '$amount', "'$comment'", "'$comment_to'", '$subtractfee' ]
}'
bwallet-cli rpc sendtoaddress $address $amount $comment $commnt_to $subtractfee
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
(async () => {
const result = await walletClient.execute('sendtoaddress', [address, amount, comment, comment_to, subtractfee]);
console.log(result);
})();
The above command returns JSON "result" like this:
552006b288266ab26fa30d9048b758a469a4101fd8235eff2384141ca5cf604d
Send Bitcoin to an address.
Params
N. | Name | Default | Description |
---|---|---|---|
1 | address | Required | Bitcoin address to send funds to |
2 | amount | Required | Amount (in BTC) to send |
4 | comment | Optional | Ignored but required if additional parameters are passed |
5 | comment_to | Optional | Ignored but required if additional parameters are passed |
6 | subtractfee | Optional | (bool) Subtract the transaction fee equally from the output amount |
setaccount
Not implemented
settxfee
let rate;
rate=0.00001
curl $walletrpcurl \
-X POST \
--data '{
"method": "settxfee",
"params": [ '$rate' ]
}'
bwallet-cli rpc settxfee $rate
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
(async () => {
const result = await walletClient.execute('settxfee', [rate]);
console.log(result);
})();
The above command returns JSON "result" like this:
true
Set the fee rate for all new transactions until the fee is
changed again, or set to 0
(will return to automatic fee).
Params
N. | Name | Default | Description |
---|---|---|---|
1 | rate | Required | Fee rate in BTC/kB |
signmessage
let address, message;
address='moKaYJdRT19YUWSsfhnTQpo68wkVvzkk8y'
message='Satoshi'
curl $walletrpcurl \
-X POST \
--data '{
"method": "signmessage",
"params": [ "'$address'", "'$message'" ]
}'
bwallet-cli rpc signmessage $address $message
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
(async () => {
const result = await walletClient.execute('signmessage', [address, message]);
console.log(result);
})();
The above command returns JSON "result" like this:
MEUCIQC5Zzr+JoenWHy7m9XxpbDVVeg3DvKvJVQNyYPvLOuB2gIgP/BT3dRItxarNbE8ajEoTI66q3eB4lo+/SLsp7bbP70=
Sign an arbitrary message with the private key corresponding to a specified Bitcoin address in the wallet.
Params
N. | Name | Default | Description |
---|---|---|---|
1 | address | Required | Wallet address to use for signing |
2 | message | Required | The message to sign |
walletlock
curl $walletrpcurl \
-X POST \
--data '{ "method": "walletlock" }'
bwallet-cli rpc walletlock
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
(async () => {
const result = await walletClient.execute('walletlock');
console.log(result);
})();
The above command returns JSON "result" like this:
null
Locks the wallet by removing the decryption key from memory. See walletpassphrase.
Params
N. | Name | Default | Description |
---|---|---|---|
None. |
walletpassphrasechange
let old, passphrase;
old='OneTwoThreeFour'
passphrase='CorrectHorseBatteryStaple'
curl $walletrpcurl \
-X POST \
--data '{
"method": "walletpassphrasechange",
"params": [ "'$old'", "'$passphrase'" ]
}'
bwallet-cli rpc walletpassphrasechange $old $passphrase
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
(async () => {
const result = await walletClient.execute('walletpassphrasechange', [old, passphrase]);
console.log(result);
})();
The above command returns JSON "result" like this:
null
Change the wallet encryption pasphrase
Params
N. | Name | Default | Description |
---|---|---|---|
1 | old | Required | The current wallet passphrase |
2 | passphrase | Required | New passphrase |
walletpassphrase
let passphrase, timeout;
passphrase='CorrectHorseBatteryStaple'
timeout=600
curl $walletrpcurl \
-X POST \
--data '{
"method": "walletpassphrase",
"params": [ "'$passphrase'", '$timeout' ]
}'
bwallet-cli rpc walletpassphrase $passphrase $timeout
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
(async () => {
const result = await walletClient.execute('walletpassphrase', [passphrase, timeout]);
console.log(result);
})();
The above command returns JSON "result" like this:
null
Store wallet decryption key in memory, unlocking the wallet keys.
Params
N. | Name | Default | Description |
---|---|---|---|
1 | passphrase | Required | The current wallet passphrase |
2 | timeout | Required | Amount of time in seconds decryption key will stay in memory |
removeprunedfunds
let txid;
txid='6478cafe0c91e5ed4c55ade3b1726209caa0d290c8a3a84cc345caad60073ad5'
curl $walletrpcurl \
-X POST \
--data '{
"method": "removeprunedfunds",
"params": [ "'$txid'" ]
}'
bwallet-cli rpc removeprunedfunds $txid
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
(async () => {
const result = await walletClient.execute('removeprunedfunds', [txid]);
console.log(result);
})();
The above command returns JSON "result" like this:
null
Deletes the specified transaction from the wallet database. See importprunedfunds.
Params
N. | Name | Default | Description |
---|---|---|---|
1 | txid | Required | txid of the transaction to remove |
wallet getmemoryinfo
curl $walletrpcurl \
-X POST \
--data '{ "method": "getmemoryinfo" }'
bwallet-cli rpc getmemoryinfo
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
(async () => {
const result = await walletClient.execute('getmemoryinfo');
console.log(result);
})();
The above command returns JSON "result" like this:
{
"total": 133,
"jsHeap": 17,
"jsHeapTotal": 20,
"nativeHeap": 112,
"external": 30
}
Get information about memory usage. Identical to node RPC call getmemoryinfo.
Params
N. | Name | Default | Description |
---|---|---|---|
None. |
wallet setloglevel
let level;
level='debug'
curl $walletrpcurl \
-X POST \
--data '{
"method": "setloglevel",
"params": [ "'$level'" ]
}'
bwallet-cli rpc setloglevel $level
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
(async () => {
const result = await walletClient.execute('setloglevel', [level]);
console.log(result);
})();
The above command returns JSON "result" like this:
null
Change Log level of the running node.
Levels are: NONE
, ERROR
, WARNING
, INFO
, DEBUG
, SPAM
Params
N. | Name | Default | Description |
---|---|---|---|
1 | level | Required | Level for the logger |
wallet stop
curl $walletrpcurl \
-X POST \
--data '{ "method": "stop" }'
bwallet-cli rpc stop
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: 'api-key'
}
const walletClient = new WalletClient(walletOptions);
(async () => {
const result = await walletClient.execute('stop');
console.log(result);
})();
The above command returns JSON "result" like this:
"Stopping."
Closes the wallet database.
Params
N. | Name | Default | Description |
---|---|---|---|
None. |
Sockets
Socket events use the socket.io protocol.
Socket IO implementations:
- JS: https://github.com/socketio/socket.io-client
- Python: https://github.com/miguelgrinberg/python-socketio
- Go: https://github.com/googollee/go-socket.io
- C++: https://github.com/socketio/socket.io-client-cpp
- bsock: https://github.com/bcoin-org/bsock (recommended!)
bsock
is a minimal websocket-only implementation of the socket.io protocol,
complete with ES6/ES7 features, developed by the bcoin team. bsock
is used
throughout the bcoin ecosystem including
bclient
and bpanel
.
Examples below describe usage with bsock
specifically.
For a deeper dive into events and sockets in bcoin, including a tutorial
on using bsock
and bclient
, see the bcoin.io Events and Sockets Guide.
Node Sockets
Node sockets - bsock
(See JavaScript example)
(See JavaScript example)
const {ChainEntry, TX} = require('bcoin');
const bsock = require('bsock');
const nodeSocket = bsock.connect('<network node RPC port>');
// Authenticate and subscribe to channels after connection
nodeSocket.on('connect', async () => {
// Auth
await nodeSocket.call('auth', '<api-key>');
// Subscribe to chain events to listen for blocks
await nodeSocket.call('watch chain');
// Subscribe to mempool events to listen for transactions
await nodeSocket.call('watch mempool');
});
// Listen for new blocks -- from chain channel
nodeSocket.bind('chain connect', (raw) => {
console.log('Node -- Chain Connect Event:\n', ChainEntry.fromRaw(raw));
});
// Listen for new transactions -- from mempool channel (bloom filter required)
nodeSocket.bind('tx', (raw) => {
console.log('Node -- TX Event:\n', TX.fromRaw(raw));
});
Node Socket Authentication
Authentication with the API server must be completed before any other events will be accepted.
Joining a channel
Instead of joining wallets, the node server offers two "channels" of events:
chain
and mempool
. When the node has no mempool (for example in SPV mode)
transaction events will be relayed from the pool of peers instead. In both
channels, transactions are only returned if they match a bloom filter sent in
advance (see set filter).
Listening for events
Unlike the wallet events, data returned by node events are not converted into
JSON format. The results are raw Buffers or arrays of Buffers. Be sure to observe
how the examples use library modules from bcoin and fromRaw()
methods to recreate
the objects.
Making calls
The node socket server can also respond to more calls than the wallet socket server.
Node sockets - bclient
(See JavaScript example)
(See JavaScript example)
const {NodeClient} = require('bclient');
const {Network, ChainEntry} = require('bcoin');
const network = Network.get('regtest');
const nodeOptions = {
network: network.type,
port: network.rpcPort,
apiKey: '<api-key>'
}
const nodeClient = new NodeClient(nodeOptions);
(async () => {
// Connection and both channel subscriptions handled by opening client
await nodeClient.open();
})();
// Listen for new blocks
nodeClient.bind('chain connect', (raw) => {
console.log('Node -- Chain Connect Event:\n', ChainEntry.fromRaw(raw));
});
bclient
abstracts away the connection, subscription, and authentication steps
to make listening for events much easier.
Node sockets - Calls
watch chain
(See JavaScript example)
(See JavaScript example)
const bsock = require('bsock');
const nodeSocket = bsock.connect('<network node RPC port>');
nodeSocket.on('connect', async () => {
// Auth
await nodeSocket.call('auth', '<api-key>');
// Subscribe to chain events to listen for blocks
await nodeSocket.call('watch chain');
});
Subscribe to chain events:
Unsubscribe by calling unwatch chain
.
watch mempool
(See JavaScript example)
(See JavaScript example)
const bsock = require('bsock');
const nodeSocket = bsock.connect('<network node RPC port>');
nodeSocket.on('connect', async () => {
// Auth
await nodeSocket.call('auth', '<api-key>');
// Subscribe to chain events to listen for blocks
await nodeSocket.call('watch mempool');
});
Subscribe to mempool/pool events:
Unsubscribe by calling unwatch mempool
.
set filter
(See JavaScript example)
(See JavaScript example)
const {Address} = require('bcoin');
const {BloomFilter} = require('bfilter');
const bsock = require('bsock');
const nodeSocket = bsock.connect('<network node RPC port>');
(async () => {
// Authentication required
// Create new Bloom filter with standard false-positive parameters
const filter = BloomFilter.fromRate(20000, 0.001, BloomFilter.flags.ALL);
// Add address hash to Bloom filter
const addr = Address.fromString('2NGZrVvZG92qGYqzTLjCAewvPZ7JE8S8VxE', 'regtest');
filter.add(addr.getHash());
// Send the entire serialized BloomFilter to server.
nodeSocket.call('set filter', filter.toRaw());
})();
Load a bloom filter to the node socket server. Only transactions matching the filter
will be returned. Applies to node tx
events and the array
of transactions returned by the block connect
event.
add filter
(See JavaScript example)
(See JavaScript example)
const {Address} = require('bcoin');
const bsock = require('bsock');
const nodeSocket = bsock.connect('<network node RPC port>');
(async () => {
// Authentication required
// Bloom filter set required
// Get address hash
const addr = Address.fromString('mp33NDe153Umb4AbRgPDFKyKmmkYEVx1fX', 'regtest');
// Send to server to add to filter.
nodeSocket.call('add filter', [addr.getHash()]);
})();
Add an array of Buffers to the existing Bloom filter. set filter
required in advance.
reset filter
(See JavaScript example)
(See JavaScript example)
const bsock = require('bsock');
const nodeSocket = bsock.connect('<network node RPC port>');
(async () => {
// Authentication required
// Bloom filter set required
nodeSocket.call('reset filter');
})();
Resets the Bloom filter on the server to an empty buffer.
get tip
(See JavaScript example)
(See JavaScript example)
const {ChainEntry} = require('bcoin');
const bsock = require('bsock');
const nodeSocket = bsock.connect('<network node RPC port>');
(async () => {
// Authentication required
const tip = nodeSocket.call('get tip');
console.log(ChainEntry.fromRaw(tip));
})();
Returns the chain tip.
get entry
(See JavaScript example)
(See JavaScript example)
const {ChainEntry} = require('bcoin');
const bsock = require('bsock');
const nodeSocket = bsock.connect('<regtest node RPC port>');
(async () => {
// Authentication required
// Get the regtest genesis block by REVERSE hash
const hash = Buffer.from('06226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f', 'hex')
const entryByHash = await nodeSocket.call('get entry', hash);
console.log(ChainEntry.fromRaw(entryByHash));
// Get block at height 5
const entryByHeight = await nodeSocket.call('get entry', 5);
console.log(ChainEntry.fromRaw(entryByHeight));
})();
Returns a chain entry requested by little-endian block hash or by integer height. No response if entry is not found.
get hashes
(See JavaScript example)
(See JavaScript example)
const bsock = require('bsock');
const nodeSocket = bsock.connect('<network node RPC port>');
(async () => {
// Authentication required
// Get all block hashes from height 10 through 20
const hashes = await nodeSocket.call('get hashes', 10, 20);
console.log(hashes);
})();
Returns an array of block hashes (as Buffers) in the specified range of height (inclusive).
estimate fee
(See JavaScript example)
(See JavaScript example)
const bsock = require('bsock');
const nodeSocket = bsock.connect('<network node RPC port>');
(async () => {
// Authentication required
// Request fee estimation for inclusion within 6 blocks
const estimate = await nodeSocket.call('estimate fee', 6);
console.log(estimate);
})();
Returns an estimated fee rate (in satoshis per kB) necessary to include a transaction in the specified number of blocks.
send
(See JavaScript example)
(See JavaScript example)
const bsock = require('bsock');
const nodeSocket = bsock.connect('<network node RPC port>');
(async () => {
// Authentication required
// Send raw transaction
const rawtx = Buffer.from(
'01000000018613693410cbaba5aec0d2660fa17efa70bc6e6951a190f61b5c7096c2b58' +
'10f000000006a47304402202e6bc4acbcc6dc823cd188e7d4179ff2ebdee0bad1b2ef66' +
'21b73e9f28145a7e022051fdfe89c4322312038eb81193665b688b002c15d6b2ca8a5a1' +
'8505e90918ba20121036297333416f91d1db918882ec637c009f180b1f54b7c21663c2a' +
'53df48e09e57ffffffff02809698000000000017a9147bd7f36e8f4504f4eaf9ab0a74d' +
'65f3d2995e8d887ec496d29010000001976a914c1a47957fda3fdba2a7b5761f86c1dc4'
'03e23f8f88ac00000000',
'hex'
);
nodeSocket.call('send', rawtx);
})();
Send a raw transaction (as Buffer) to node server to broadcast. Server will attempt to broadcast the transaction without any checks.
rescan
(See JavaScript example)
(See JavaScript example)
const bsock = require('bsock');
const nodeSocket = bsock.connect('<regtest node RPC port>');
// Establish a socket hook to process the filter-matched blocks and transactions
nodeSocket.hook('block rescan', (entry, txs) => {
// Do something (like update your wallet DB)
});
(async () => {
// Authentication required
// Bloom filter set required
// Rescan the blockchain from height 5
const entry = await nodeSocket.call('rescan', 5);
})();
Rescan the chain from the specified integer height OR little-endian block hash (as Buffer). Requires Bloom filter. Returns a call back to the client after scanning each block:
socket.call('block rescan', block, txs)
Where block
is a raw ChainEntry
and txs
is an array of filter-matched
transactions (as Buffers).
Note that this is NOT a wallet rescan, but the returned data can be used by a client-side wallet to update its state.
Node sockets - Events
chain connect
Example:
# ChainEntry.fromRaw(raw)
{
hash:
'5e3b0f5ea3eb2305936191c7255625abee9890fb68625ca2279647533c7eac35',
version: '30000001',
prevBlock:
'5e585c5828132bead36f684ab4e2d23e78d563ab743081823d3a96c0077885b5',
merkleRoot:
'2090e1be81e0d9f740bd68bc42ab790cfc3edb8ce04451ff88dda50107bba103',
time: 1553614114,
bits: 545259519,
nonce: 0,
height: 234,
chainwork:
'00000000000000000000000000000000000000000000000000000000000001d6'
}
Channel: chain
Emitted when a block is added to the chain. Returns raw ChainEntry
of new
block.
block connect
Example:
# ChainEntry.fromRaw(raw), txs
{
hash:
'5e3b0f5ea3eb2305936191c7255625abee9890fb68625ca2279647533c7eac35',
version: '30000001',
prevBlock:
'5e585c5828132bead36f684ab4e2d23e78d563ab743081823d3a96c0077885b5',
merkleRoot:
'2090e1be81e0d9f740bd68bc42ab790cfc3edb8ce04451ff88dda50107bba103',
time: 1553614114,
bits: 545259519,
nonce: 0,
height: 234,
chainwork:
'00000000000000000000000000000000000000000000000000000000000001d6'
}
[
<Buffer 01 00 00 00 00 01 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ... >,
<Buffer 01 00 00 00 01 2f 32 30 94 24 88 42 4e b8 e4 08 9d 0d aa ee 3a ... >,
<Buffer 01 00 00 00 01 2f 9e 7d 93 16 1c 0f 0a 48 93 79 63 a8 2c 9f 6c ... >,
<Buffer 01 00 00 00 01 e2 47 a2 d1 2b 90 03 39 94 09 f2 bf d9 7a ff 6b ... >
]
Channel: chain
Emitted when a block is added to the chain. Returns raw ChainEntry
of new
block. If a Bloom filter has been loaded in advance,
this call will also return an array of filter-matching transactions (as raw
Buffers).
chain disconnect
Example:
# ChainEntry.fromRaw(raw)
{
hash:
'0fcf0745e15e9b05098e7d82628c2b3e3693a26779ecf18b728e2acbbb2c9d2f',
version: '30000001',
prevBlock:
'0d60d46a80201c8d50fb62bb8ff73dec62f0f90de6d14c0419ab57e06d46f888',
merkleRoot:
'0112fe4c48685b8bee773a939b3a5c1361e4c7fc0f9c1b7a0ee310be9431b12a',
time: 1553784886,
bits: 545259519,
nonce: 0,
height: 229,
chainwork:
'00000000000000000000000000000000000000000000000000000000000001cc'
}
Channel: chain
Emitted when a block is removed from the chain. Returns raw ChainEntry
of the
block being removed.
block disconnect
Identical to chain disconnect
chain reset
Example:
# ChainEntry.fromRaw(raw)
{
hash:
'7b3e9c3b8ea3924f44a1c3ac8b539be1a019cb1d5c384cb603aa99f44c8f9c55',
version: '30000001',
prevBlock:
'4a1871311ec860a82dc56d0b198757217b751458e03f5bbe557685d1e883c9fb',
merkleRoot:
'0fffb562f0aba5edd566047b4a226328a2284a361391ef477b9351f39a472771',
time: 1553783915,
bits: 545259519,
nonce: 1,
height: 226,
chainwork:
'00000000000000000000000000000000000000000000000000000000000001c6'
}
Channel: chain
Returns raw ChainEntry
of the new current tip.
Node tx
Example:
# TX.fromRaw(raw)
{
hash:
'c6ff80856c192179f1ee5a9462dcf9992fa145fc16e7332ead0dd58bdd8c5e12',
witnessHash:
'c6ff80856c192179f1ee5a9462dcf9992fa145fc16e7332ead0dd58bdd8c5e12',
size: 223,
virtualSize: 223,
value: '49.999955',
fee: '0.0',
rate: '0.0',
minFee: '0.00000223',
height: -1,
block: null,
time: 0,
date: null,
index: -1,
version: 1,
inputs:
[ { type: 'pubkeyhash',
subtype: null,
address:
<Address: type=pubkeyhash version=-1 str=1EMhzKJsFARX1To4nf8ZSkEitsSu1uPAAQ>,
script:
<Script: 0x47 0x304402201619988d47c70c0834bd0c0c407b116654f0fb29faabc68129ab66487ca86ba802204a683fa071f177db960b9bd98e62703c3cb1a7a0888ccc41ee854cb0633dcfe501 0x21 0x02c9e389af9245e7e38c64c46465d6d281e7cc822e909f20454dada561c47e0d3e>,
witness: <Witness: >,
redeem: null,
sequence: 4294967295,
prevout:
<Outpoint: a0b3d51f320493660af2f92171f1ed01bc1e85e1c66e2785fe42cb20069b4fb8/0>,
coin: null } ],
outputs:
[ { type: 'scripthash',
value: '0.1',
script:
<Script: OP_HASH160 0x14 0x7bd7f36e8f4504f4eaf9ab0a74d65f3d2995e8d8 OP_EQUAL>,
address:
<Address: type=scripthash version=-1 str=3Cyqjfs5KaLzS5mMsBzznwN9SAx814WVe2> },
{ type: 'pubkeyhash',
value: '49.899955',
script:
<Script: OP_DUP OP_HASH160 0x14 0x31cb0ced3ff113b82e5e7d935a5c0e23a9f659c3 OP_EQUALVERIFY OP_CHECKSIG>,
address:
<Address: type=pubkeyhash version=-1 str=15YHMbY1rFgss64CaqMZyGVDUqZKqHHetM> } ],
locktime: 0
}
Channel: mempool
Emitted when a transaction that matches a previously set Bloom filter is received by the node server. Returns transaction as raw Buffer.
Wallet Sockets
Wallet sockets - bsock
(See JavaScript example)
(See JavaScript example)
const bsock = require('bsock');
const walletSocket = bsock.connect('<network wallet RPC port>');
// Authenticate and join wallet after connection to listen for events
walletSocket.on('connect', async () => {
// Auth
await walletSocket.call('auth', '<api-key>');
// Join - All wallets
await walletSocket.call('join', '*', '<admin token>');
// Join - Specific wallet
await walletSocket.call('join', '<wallet id>', '<wallet token>');
});
// Listen for new transactions
walletSocket.bind('tx', (walletID, details) => {
console.log('Wallet -- TX Event, Wallet ID:\n', walletID);
console.log('Wallet -- TX Event, TX Details:\n', details);
});
// Leave
walletSocket.call('leave', <wallet id>);
Wallet Socket Authentication
Authentication with the API server must be completed before any other events will be accepted.
Joining a wallet
After creating a websocket and authing with the server, you must send a join
event to listen for events on a wallet. Join all wallets by passing '*'
.
Leave a wallet with the leave
event.
Wallet or admin token is required if wallet-auth
is true
.
Listening for events
All wallet events return the wallet-id
in addition to the JSON data described below.
Wallet sockets - bclient
(See JavaScript example)
(See JavaScript example)
const {WalletClient, Network} = require('bcoin');
const network = Network.get('regtest');
const walletOptions = {
network: network.type,
port: network.walletPort,
apiKey: '<api-key>'
}
const walletClient = new WalletClient(walletOptions);
(async () => {
// Connection and auth handled by opening client
await walletClient.open();
await walletClient.join('*', '<admin token>');
})();
// Listen for new transactions
walletClient.bind('tx', (walletID, details) => {
console.log('Wallet -- TX Event, Wallet ID:\n', walletID);
console.log('Wallet -- TX Event, TX Details:\n', details);
});
// Leave all wallets
walletClient.leave('<wallet id>');
bclient
abstracts away the connection and authentication steps to make listening
for events much easier.
Wallet sockets - Calls
The only wallet calls available are covered in the previous section.
They are:
auth
join
leave
Wallet sockets - Events
wallet tx
Example:
{
"hash": "e0ef577e307b9b798bf98a7aa56ebab431d1918f6c8b29ddd8a89dce5314acca",
"height": -1,
"block": null,
"time": 0,
"mtime": 1571774743,
"date": "1970-01-01T00:00:00Z",
"mdate": "2019-10-22T20:05:43Z",
"size": 226,
"virtualSize": 226,
"fee": 4540,
"rate": 20088,
"confirmations": 0,
"inputs": [
{
"value": 2500000000,
"address": "mhX1xHbKGzw3r8FoN5bUkmRixHPEDNywxh",
"path": {
"name": "default",
"account": 0,
"change": false,
"derivation": "m/0'/0/1"
}
}
],
"outputs": [
{
"value": 10000000,
"address": "msSaQkCXyrEefbSH9TCSWNjnacTwGGc55d",
"path": {
"name": "default",
"account": 0,
"change": false,
"derivation": "m/0'/0/4"
}
},
{
"value": 2489995460,
"address": "mtwN3Z4R7Mjdn1Dt6eDCUwoPdYKNFu6oiX",
"path": {
"name": "default",
"account": 0,
"change": true,
"derivation": "m/0'/1/5"
}
}
],
"tx": "0100000001bf932f6585ce47d552c9f18463820bb4064b97b032606a122947aba4e14f77e6000000006b4830450221009aa7abc5bcc058bbb3c85ea53fdc19bae9351a81ad3f6027b6dfc0437fb1010502202e768a07a9e073833fc7039bebfd5b9b4edc373159e93d5917f074c53355187201210336c99e45e00b73c863497a989fe6feb08439ca2d7cf98f55bc261ed70ed28a7bffffffff0280969800000000001976a91482cd93c2cbdd094599a92ce3317d3087a1975e0a88acc4506a94000000001976a9149337719ab611d0da2ec1317dd195844661e3732f88ac00000000"
}
Emitted on transaction.
Returns tx details.
conflict
Emitted on double spend.
Returns tx details of removed double spender.
confirmed
Example:
{
"hash": "e0ef577e307b9b798bf98a7aa56ebab431d1918f6c8b29ddd8a89dce5314acca",
"height": 846,
"block": "636982487fccf820bc1ca825b2cdd94be1bdd9863e8dec01979b62b45d894e73",
"time": 1571774818,
"mtime": 1571774743,
"date": "2019-10-22T20:06:58Z",
"mdate": "2019-10-22T20:05:43Z",
"size": 226,
"virtualSize": 226,
"fee": 4540,
"rate": 20088,
"confirmations": 1,
"inputs": [
{
"value": 2500000000,
"address": "mhX1xHbKGzw3r8FoN5bUkmRixHPEDNywxh",
"path": {
"name": "default",
"account": 0,
"change": false,
"derivation": "m/0'/0/1"
}
}
],
"outputs": [
{
"value": 10000000,
"address": "msSaQkCXyrEefbSH9TCSWNjnacTwGGc55d",
"path": {
"name": "default",
"account": 0,
"change": false,
"derivation": "m/0'/0/4"
}
},
{
"value": 2489995460,
"address": "mtwN3Z4R7Mjdn1Dt6eDCUwoPdYKNFu6oiX",
"path": {
"name": "default",
"account": 0,
"change": true,
"derivation": "m/0'/1/5"
}
}
],
"tx": "0100000001bf932f6585ce47d552c9f18463820bb4064b97b032606a122947aba4e14f77e6000000006b4830450221009aa7abc5bcc058bbb3c85ea53fdc19bae9351a81ad3f6027b6dfc0437fb1010502202e768a07a9e073833fc7039bebfd5b9b4edc373159e93d5917f074c53355187201210336c99e45e00b73c863497a989fe6feb08439ca2d7cf98f55bc261ed70ed28a7bffffffff0280969800000000001976a91482cd93c2cbdd094599a92ce3317d3087a1975e0a88acc4506a94000000001976a9149337719ab611d0da2ec1317dd195844661e3732f88ac00000000"
}
Emitted when a transaction is confirmed.
Returns tx details.
unconfirmed
Emitted if a transaction was changed from confirmed->unconfirmed as the result of a reorg.
Returns tx details.
balance
Example:
{
account: -1,
tx: 113,
coin: 113,
unconfirmed: 539999990920,
confirmed: 540000000000
}
Emitted on balance update. Only emitted for entire wallet balance (not individual accounts).
Returns Balance object.
address
Example:
[
{
"name": "default",
"account": 0,
"branch": 0,
"index": 16,
"witness": false,
"nested": false,
"publicKey": "0370d759cf5170e718ab02fccf844bc69a3c9ad6ece9899be55455930fb85ff674",
"script": null,
"program": null,
"type": "pubkeyhash",
"address": "mfzcPvKYNjzULJRjbaAhdR8fEJsTg7SSsV"
}
]
Emitted when a transaction is received by the wallet account's current receive address, causing the wallet to derive a new receive address.
Returns an array of KeyRing objects with new address details.
Errors
Any errors will be returned with an http status code other than 200, containing a JSON object in the form:
{"error": { message: "message" } }