github.com/dashpay/godash@v0.0.0-20160726055534-e038a21e0e3d/docs/json_rpc_api.md (about) 1 ### Table of Contents 2 1. [Overview](#Overview)<br /> 3 2. [HTTP POST Versus Websockets](#HttpPostVsWebsockets)<br /> 4 3. [Authentication](#Authentication)<br /> 5 3.1. [Overview](#AuthenticationOverview)<br /> 6 3.2. [HTTP Basic Access Authentication](#HTTPAuth)<br /> 7 3.3. [JSON-RPC Authenticate Command (Websocket-specific)](#JSONAuth)<br /> 8 4. [Command-line Utility](#CLIUtil)<br /> 9 5. [Standard Methods](#Methods)<br /> 10 5.1. [Method Overview](#MethodOverview)<br /> 11 5.2. [Method Details](#MethodDetails)<br /> 12 6. [Extension Methods](#ExtensionMethods)<br /> 13 6.1. [Method Overview](#ExtMethodOverview)<br /> 14 6.2. [Method Details](#ExtMethodDetails)<br /> 15 7. [Websocket Extension Methods (Websocket-specific)](#WSExtMethods)<br /> 16 7.1. [Method Overview](#WSExtMethodOverview)<br /> 17 7.2. [Method Details](#WSExtMethodDetails)<br /> 18 8. [Notifications (Websocket-specific)](#Notifications)<br /> 19 8.1. [Notification Overview](#NotificationOverview)<br /> 20 8.2. [Notification Details](#NotificationDetails)<br /> 21 9. [Example Code](#ExampleCode)<br /> 22 9.1. [Go](#ExampleGoApp)<br /> 23 9.2. [node.js](#ExampleNodeJsCode)<br /> 24 25 <a name="Overview" /> 26 ### 1. Overview 27 28 btcd provides a [JSON-RPC](http://json-rpc.org/wiki/specification) API that is 29 fully compatible with the original bitcoind/bitcoin-qt. There are a few key 30 differences between btcd and bitcoind as far as how RPCs are serviced: 31 * Unlike bitcoind that has the wallet and chain intermingled in the same process 32 which leads to several issues, btcd intentionally splits the wallet and chain 33 services into independent processes. See the blog post 34 [here](https://blog.conformal.com/btcd-not-your-moms-bitcoin-daemon/) for 35 further details on why they were separated. This means that if you are 36 talking directly to btcd, only chain-related RPCs are available. However both 37 chain-related and wallet-related RPCs are available via 38 [btcwallet](https://github.com/btcsuite/btcwallet). 39 * btcd is secure by default which means that the RPC connection is TLS-enabled 40 by default 41 * btcd provides access to the API through both 42 [HTTP POST](http://en.wikipedia.org/wiki/POST_%28HTTP%29) requests and 43 [Websockets](http://en.wikipedia.org/wiki/WebSocket) 44 45 Websockets are the preferred transport for btcd RPC and are used by applications 46 such as [btcwallet](https://github.com/btcsuite/btcwallet) for inter-process 47 communication with btcd. The websocket connection endpoint for btcd is 48 `wss://your_ip_or_domain:8334/ws`. 49 50 In addition to the [standard API](#Methods), an [extension API](#WSExtMethods) 51 has been developed that is exclusive to clients using Websockets. In its current 52 state, this API attempts to cover features found missing in the standard API 53 during the development of btcwallet. 54 55 While the [standard API](#Methods) is stable, the 56 [Websocket extension API](#WSExtMethods) should be considered a work in 57 progress, incomplete, and susceptible to changes (both additions and removals). 58 59 The original bitcoind/bitcoin-qt JSON-RPC API documentation is available at [https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_Calls_list](https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_Calls_list) 60 61 <a name="HttpPostVsWebsockets" /> 62 ### 2. HTTP POST Versus Websockets 63 64 The btcd RPC server supports both [HTTP POST](http://en.wikipedia.org/wiki/POST_%28HTTP%29) 65 requests and the preferred [Websockets](http://en.wikipedia.org/wiki/WebSocket). 66 All of the [standard](#Methods) and [extension](#ExtensionMethods) methods 67 described in this documentation can be accessed through both. As the name 68 indicates, the [Websocket-specific extension](#WSExtMethods) methods can only be 69 accessed when connected via Websockets. 70 71 As mentioned in the [overview](#Overview), the websocket connection endpoint for 72 btcd is `wss://your_ip_or_domain:8334/ws`. 73 74 The most important differences between the two transports as it pertains to the 75 JSON-RPC API are: 76 77 | |HTTP POST Requests|Websockets| 78 |---|------------------|----------| 79 |Allows multiple requests across a single connection|No|Yes| 80 |Supports asynchronous notifications|No|Yes| 81 |Scales well with large numbers of requests|No|Yes| 82 83 <a name="Authentication" /> 84 ### 3. Authentication 85 86 <a name="AuthenticationOverview" /> 87 **3.1 Authentication Overview**<br /> 88 89 The following authentication details are needed before establishing a connection 90 to a btcd RPC server: 91 92 * **rpcuser** is the full-access username configured for the btcd RPC server 93 * **rpcpass** is the full-access password configured for the btcd RPC server 94 * **rpclimituser** is the limited username configured for the btcd RPC server 95 * **rpclimitpass** is the limited password configured for the btcd RPC server 96 * **rpccert** is the PEM-encoded X.509 certificate (public key) that the btcd 97 server is configured with. It is automatically generated by btcd and placed 98 in the btcd home directory (which is typically `%LOCALAPPDATA%\Btcd` on 99 Windows and `~/.btcd` on POSIX-like OSes) 100 101 **NOTE:** As mentioned above, btcd is secure by default which means the RPC 102 server is not running unless configured with a **rpcuser** and **rpcpass** 103 and/or a **rpclimituser** and **rpclimitpass**, and uses TLS authentication for 104 all connections. 105 106 Depending on which connection transaction you are using, you can choose one of 107 two, mutually exclusive, methods. 108 - [Use HTTP Authorization Header](#HTTPAuth) - HTTP POST requests and Websockets 109 - [Use the JSON-RPC "authenticate" command](#JSONAuth) - Websockets only 110 111 <a name="HTTPAuth" /> 112 **3.2 HTTP Basic Access Authentication**<br /> 113 114 The btcd RPC server uses HTTP [basic access authentication](http://en.wikipedia.org/wiki/Basic_access_authentication) with the **rpcuser** 115 and **rpcpass** detailed above. If the supplied credentials are invalid, you 116 will be disconnected immediately upon making the connection. 117 118 <a name="JSONAuth" /> 119 **3.3 JSON-RPC Authenticate Command (Websocket-specific)**<br /> 120 121 While the HTTP basic access authentication method is the preferred method, the 122 ability to set HTTP headers from websockets is not always available. In that 123 case, you will need to use the [authenticate](#authenticate) JSON-RPC method. 124 125 The [authenticate](#authenticate) command must be the first command sent after 126 connecting to the websocket. Sending any other commands before authenticating, 127 supplying invalid credentials, or attempting to authenticate again when already 128 authenticated will cause the websocket to be closed immediately. 129 130 131 <a name="CLIUtil" /> 132 ### 4. Command-line Utility 133 134 btcd comes with a separate utility named `btcctl` which can be used to issue 135 these RPC commands via HTTP POST requests to btcd after configuring it with the 136 information in the [Authentication](#Authentication) section above. It can also 137 be used to communicate with any server/daemon/service which provides a JSON-RPC 138 API compatible with the original bitcoind/bitcoin-qt client. 139 140 <a name="Methods" /> 141 ### 5. Standard Methods 142 143 <a name="MethodOverview" /> 144 **5.1 Method Overview**<br /> 145 146 The following is an overview of the RPC methods and their current status. Click 147 the method name for further details such as parameter and return information. 148 149 |#|Method|Safe for limited user?|Description| 150 |---|------|----------|-----------| 151 |1|[addnode](#addnode)|N|Attempts to add or remove a persistent peer.| 152 |2|[createrawtransaction](#createrawtransaction)|Y|Returns a new transaction spending the provided inputs and sending to the provided addresses.| 153 |3|[decoderawtransaction](#decoderawtransaction)|Y|Returns a JSON object representing the provided serialized, hex-encoded transaction.| 154 |4|[decodescript](#decodescript)|Y|Returns a JSON object with information about the provided hex-encoded script.| 155 |5|[getaddednodeinfo](#getaddednodeinfo)|N|Returns information about manually added (persistent) peers.| 156 |6|[getbestblockhash](#getbestblockhash)|Y|Returns the hash of the of the best (most recent) block in the longest block chain.| 157 |7|[getblock](#getblock)|Y|Returns information about a block given its hash.| 158 |8|[getblockcount](#getblockcount)|Y|Returns the number of blocks in the longest block chain.| 159 |9|[getblockhash](#getblockhash)|Y|Returns hash of the block in best block chain at the given height.| 160 |10|[getblockheader](#getblockheader)|Y|Returns the block header of the block.| 161 |11|[getconnectioncount](#getconnectioncount)|N|Returns the number of active connections to other peers.| 162 |12|[getdifficulty](#getdifficulty)|Y|Returns the proof-of-work difficulty as a multiple of the minimum difficulty.| 163 |13|[getgenerate](#getgenerate)|N|Return if the server is set to generate coins (mine) or not.| 164 |14|[gethashespersec](#gethashespersec)|N|Returns a recent hashes per second performance measurement while generating coins (mining).| 165 |15|[getinfo](#getinfo)|Y|Returns a JSON object containing various state info.| 166 |16|[getmempoolinfo](#getmempoolinfo)|N|Returns a JSON object containing mempool-related information.| 167 |17|[getmininginfo](#getmininginfo)|N|Returns a JSON object containing mining-related information.| 168 |18|[getnettotals](#getnettotals)|Y|Returns a JSON object containing network traffic statistics.| 169 |19|[getnetworkhashps](#getnetworkhashps)|Y|Returns the estimated network hashes per second for the block heights provided by the parameters.| 170 |20|[getpeerinfo](#getpeerinfo)|N|Returns information about each connected network peer as an array of json objects.| 171 |21|[getrawmempool](#getrawmempool)|Y|Returns an array of hashes for all of the transactions currently in the memory pool.| 172 |22|[getrawtransaction](#getrawtransaction)|Y|Returns information about a transaction given its hash.| 173 |23|[getwork](#getwork)|N|Returns formatted hash data to work on or checks and submits solved data.<br /><font color="orange">NOTE: Since btcd does not have the wallet integrated to provide payment addresses, btcd must be configured via the `--miningaddr` option to provide which payment addresses to pay created blocks to for this RPC to function.</font>| 174 |24|[help](#help)|Y|Returns a list of all commands or help for a specified command.| 175 |25|[ping](#ping)|N|Queues a ping to be sent to each connected peer.| 176 |26|[sendrawtransaction](#sendrawtransaction)|Y|Submits the serialized, hex-encoded transaction to the local peer and relays it to the network.<br /><font color="orange">btcd does not yet implement the `allowhighfees` parameter, so it has no effect</font>| 177 |27|[setgenerate](#setgenerate) |N|Set the server to generate coins (mine) or not.<br/>NOTE: Since btcd does not have the wallet integrated to provide payment addresses, btcd must be configured via the `--miningaddr` option to provide which payment addresses to pay created blocks to for this RPC to function.| 178 |28|[stop](#stop)|N|Shutdown btcd.| 179 |29|[submitblock](#submitblock)|Y|Attempts to submit a new serialized, hex-encoded block to the network.| 180 |30|[validateaddress](#validateaddress)|Y|Verifies the given address is valid. NOTE: Since btcd does not have a wallet integrated, btcd will only return whether the address is valid or not.| 181 |31|[verifychain](#verifychain)|N|Verifies the block chain database.| 182 183 <a name="MethodDetails" /> 184 **5.2 Method Details**<br /> 185 186 <a name="addnode"/> 187 188 | | | 189 |---|---| 190 |Method|addnode| 191 |Parameters|1. peer (string, required) - ip address and port of the peer to operate on<br />2. command (string, required) - `add` to add a persistent peer, `remove` to remove a persistent peer, or `onetry` to try a single connection to a peer| 192 |Description|Attempts to add or remove a persistent peer.| 193 |Returns|Nothing| 194 [Return to Overview](#MethodOverview)<br /> 195 196 *** 197 <a name="createrawtransaction"/> 198 199 | | | 200 |---|---| 201 |Method|createrawtransaction| 202 |Parameters|1. transaction inputs (JSON array, required) - json array of json objects<br />`[`<br /> `{`<br /> `"txid": "hash", (string, required) the hash of the input transaction`<br /> `"vout": n (numeric, required) the specific output of the input transaction to redeem`<br /> `}, ...`<br />`]`<br />2. addresses and amounts (JSON object, required) - json object with addresses as keys and amounts as values<br />`{`<br /> `"address": n.nnn (numeric, required) the address to send to as the key and the amount in BTC as the value`<br /> `, ...`<br />`}`<br />3. locktime (int64, optional, default=0) - specifies the transaction locktime. If non-zero, the inputs will also have their locktimes activated. | 203 |Description|Returns a new transaction spending the provided inputs and sending to the provided addresses.<br />The transaction inputs are not signed in the created transaction.<br />The `signrawtransaction` RPC command provided by wallet must be used to sign the resulting transaction.| 204 |Returns|`"transaction" (string) hex-encoded bytes of the serialized transaction`| 205 |Example Parameters|1. transaction inputs `[{"txid":"e6da89de7a6b8508ce8f371a3d0535b04b5e108cb1a6e9284602d3bfd357c018","vout":1}]`<br />2. addresses and amounts `{"13cgrTP7wgbZYWrY9BZ22BV6p82QXQT3nY": 0.49213337}`<br />3. locktime `0`| 206 |Example Return|`010000000118c057d3bfd3024628e9a6b18c105e4bb035053d1a378fce08856b7ade89dae6010000`<br />`0000ffffffff0199efee02000000001976a9141cb013db35ecccc156fdfd81d03a11c51998f99388`<br />`ac00000000`<br /><font color="orange">**Newlines added for display purposes. The actual return does not contain newlines.**</font>| 207 [Return to Overview](#MethodOverview)<br /> 208 209 *** 210 <a name="decoderawtransaction"/> 211 212 | | | 213 |---|---| 214 |Method|decoderawtransaction| 215 |Parameters|1. data (string, required) - serialized, hex-encoded transaction| 216 |Description|Returns a JSON object representing the provided serialized, hex-encoded transaction.| 217 |Returns|`{ (json object)`<br /> `"txid": "hash", (string) the hash of the transaction`<br /> `"version": n, (numeric) the transaction version`<br /> `"locktime": n, (numeric) the transaction lock time`<br /> `"vin": [ (array of json objects) the transaction inputs as json objects`<br /> <font color="orange">For coinbase transactions:</font><br /> `{ (json object)`<br /> `"coinbase": "data", (string) the hex-encoded bytes of the signature script`<br /> `"sequence": n, (numeric) the script sequence number`<br /> `}`<br /> <font color="orange">For non-coinbase transactions:</font><br /> `{ (json object)`<br /> `"txid": "hash", (string) the hash of the origin transaction`<br /> `"vout": n, (numeric) the index of the output being redeemed from the origin transaction`<br /> `"scriptSig": { (json object) the signature script used to redeem the origin transaction`<br /> `"asm": "asm", (string) disassembly of the script`<br /> `"hex": "data", (string) hex-encoded bytes of the script`<br /> `}`<br /> `"sequence": n, (numeric) the script sequence number`<br /> `}, ...`<br /> `]`<br /> `"vout": [ (array of json objects) the transaction outputs as json objects`<br /> `{ (json object)`<br /> `"value": n, (numeric) the value in BTC`<br /> `"n": n, (numeric) the index of this transaction output`<br /> `"scriptPubKey": { (json object) the public key script used to pay coins`<br /> `"asm": "asm", (string) disassembly of the script`<br /> `"hex": "data", (string) hex-encoded bytes of the script`<br /> `"reqSigs": n, (numeric) the number of required signatures`<br /> `"type": "scripttype" (string) the type of the script (e.g. 'pubkeyhash')`<br /> `"addresses": [ (json array of string) the bitcoin addresses associated with this output`<br /> `"bitcoinaddress", (string) the bitcoin address`<br /> `...`<br /> `]`<br /> `}`<br /> `}, ...`<br /> `]`<br />`}`| 218 |Example Return|`{`<br /> `"txid": "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b",`<br /> `"version": 1,`<br /> `"locktime": 0,`<br /> `"vin": [`<br /> <font color="orange">For coinbase transactions:</font><br /> `{ (json object)`<br /> `"coinbase": "04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6...",`<br /> `"sequence": 4294967295,`<br /> `}`<br /> <font color="orange">For non-coinbase transactions:</font><br /> `{`<br /> `"txid": "60ac4b057247b3d0b9a8173de56b5e1be8c1d1da970511c626ef53706c66be04",`<br /> `"vout": 0,`<br /> `"scriptSig": {`<br /> `"asm": "3046022100cb42f8df44eca83dd0a727988dcde9384953e830b1f8004d57485e2ede1b9c8f0...",`<br /> `"hex": "493046022100cb42f8df44eca83dd0a727988dcde9384953e830b1f8004d57485e2ede1b9c8...",`<br /> `}`<br /> `"sequence": 4294967295,`<br /> `}`<br /> `]`<br /> `"vout": [`<br /> `{`<br /> `"value": 50,`<br /> `"n": 0,`<br /> `"scriptPubKey": {`<br /> `"asm": "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4ce...",`<br /> `"hex": "4104678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4...",`<br /> `"reqSigs": 1,`<br /> `"type": "pubkey"`<br /> `"addresses": [`<br /> `"1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa",`<br /> `]`<br /> `}`<br /> `}`<br /> `]`<br />`}`| 219 [Return to Overview](#MethodOverview)<br /> 220 221 *** 222 <a name="decodescript"/> 223 224 | | | 225 |---|---| 226 |Method|decodescript| 227 |Parameters|1. script (string, required) - hex-encoded script| 228 |Description|Returns a JSON object with information about the provided hex-encoded script.| 229 |Returns|`{ (json object)`<br /> `"asm": "asm", (string) disassembly of the script`<br /> `"reqSigs": n, (numeric) the number of required signatures`<br /> `"type": "scripttype", (string) the type of the script (e.g. 'pubkeyhash')`<br /> `"addresses": [ (json array of string) the bitcoin addresses associated with this script`<br /> `"bitcoinaddress", (string) the bitcoin address`<br /> `...`<br /> `]`<br /> `"p2sh": "scripthash", (string) the script hash for use in pay-to-script-hash transactions`<br />`}`| 230 |Example Return|`{`<br /> `"asm": "OP_DUP OP_HASH160 b0a4d8a91981106e4ed85165a66748b19f7b7ad4 OP_EQUALVERIFY OP_CHECKSIG",`<br /> `"reqSigs": 1,`<br /> `"type": "pubkeyhash",`<br /> `"addresses": [`<br /> `"1H71QVBpzuLTNUh5pewaH3UTLTo2vWgcRJ"`<br /> `]`<br /> `"p2sh": "359b84ff799f48231990ff0298206f54117b08b6"`<br />`}`| 231 [Return to Overview](#MethodOverview)<br /> 232 233 *** 234 <a name="getaddednodeinfo"/> 235 236 | | | 237 |---|---| 238 |Method|getaddednodeinfo| 239 |Parameters|1. dns (boolean, required) - specifies whether the returned data is a JSON object including DNS and connection information, or just a list of added peers<br />2. node (string, optional) - only return information about this specific peer instead of all added peers.| 240 |Description|Returns information about manually added (persistent) peers.| 241 |Returns (dns=false)|`["ip:port", ...]`| 242 |Returns (dns=true)|`[ (json array of objects)`<br /> `{ (json object)`<br /> `"addednode": "ip_or_domain", (string) the ip address or domain of the added peer`<br /> `"connected": true or false, (boolean) whether or not the peer is currently connected`<br /> `"addresses": [ (json array or objects) DNS lookup and connection information about the peer`<br /> `{ (json object)`<br /> `"address": "ip", (string) the ip address for this DNS entry`<br /> `"connected": "inbound/outbound/false" (string) the connection 'direction' (if connected)`<br /> `}, ...`<br /> `]`<br /> `}, ...`<br />`]`| 243 |Example Return (dns=false)|`["192.168.0.10:8333", "mydomain.org:8333"]`| 244 |Example Return (dns=true)|`[`<br /> `{`<br /> `"addednode": "mydomain.org:8333",`<br /> `"connected": true,`<br /> `"addresses": [`<br /> `{`<br /> `"address": "1.2.3.4",`<br /> `"connected": "outbound"`<br /> `},`<br /> `{`<br /> `"address": "5.6.7.8",`<br /> `"connected": "false"`<br /> `}`<br /> `]`<br /> `}`<br />`]`| 245 [Return to Overview](#MethodOverview)<br /> 246 247 *** 248 <a name="getbestblockhash"/> 249 250 | | | 251 |---|---| 252 |Method|getbestblockhash| 253 |Parameters|None| 254 |Description|Returns the hash of the of the best (most recent) block in the longest block chain.| 255 |Returns|string| 256 |Example Return|`0000000000000001f356adc6b29ab42b59f913a396e170f80190dba615bd1e60`| 257 [Return to Overview](#MethodOverview)<br /> 258 259 *** 260 <a name="getblock"/> 261 262 | | | 263 |---|---| 264 |Method|getblock| 265 |Parameters|1. block hash (string, required) - the hash of the block<br />2. verbose (boolean, optional, default=true) - specifies the block is returned as a JSON object instead of hex-encoded string<br />3. verbosetx (boolean, optional, default=false) - specifies that each transaction is returned as a JSON object and only applies if the `verbose` flag is true.<font color="orange">**This parameter is a btcd extension**</font>| 266 |Description|Returns information about a block given its hash.| 267 |Returns (verbose=false)|`"data" (string) hex-encoded bytes of the serialized block`| 268 |Returns (verbose=true, verbosetx=false)|`{ (json object)`<br /> `"hash": "blockhash", (string) the hash of the block (same as provided)`<br /> `"confirmations": n, (numeric) the number of confirmations`<br /> `"size": n, (numeric) the size of the block`<br /> `"height": n, (numeric) the height of the block in the block chain`<br /> `"version": n, (numeric) the block version`<br /> `"merkleroot": "hash", (string) root hash of the merkle tree`<br /> `"tx": [ (json array of string) the transaction hashes`<br /> `"transactionhash", (string) hash of the parent transaction`<br /> `...`<br /> `]`<br /> `"time": n, (numeric) the block time in seconds since 1 Jan 1970 GMT`<br /> `"nonce": n, (numeric) the block nonce`<br /> `"bits", n, (numeric) the bits which represent the block difficulty`<br /> `difficulty: n.nn, (numeric) the proof-of-work difficulty as a multiple of the minimum difficulty`<br /> `"previousblockhash": "hash", (string) the hash of the previous block`<br /> `"nextblockhash": "hash", (string) the hash of the next block (only if there is one)`<br />`}`| 269 |Returns (verbose=true, verbosetx=true)|`{ (json object)`<br /> `"hash": "blockhash", (string) the hash of the block (same as provided)`<br /> `"confirmations": n, (numeric) the number of confirmations`<br /> `"size": n, (numeric) the size of the block`<br /> `"height": n, (numeric) the height of the block in the block chain`<br /> `"version": n, (numeric) the block version`<br /> `"merkleroot": "hash", (string) root hash of the merkle tree`<br /> `"rawtx": [ (array of json objects) the transactions as json objects`<br /> `(see getrawtransaction json object details)`<br /> `]`<br /> `"time": n, (numeric) the block time in seconds since 1 Jan 1970 GMT`<br /> `"nonce": n, (numeric) the block nonce`<br /> `"bits", n, (numeric) the bits which represent the block difficulty`<br /> `difficulty: n.nn, (numeric) the proof-of-work difficulty as a multiple of the minimum difficulty`<br /> `"previousblockhash": "hash", (string) the hash of the previous block`<br /> `"nextblockhash": "hash", (string) the hash of the next block`<br />`}`| 270 |Example Return (verbose=false)|`"010000000000000000000000000000000000000000000000000000000000000000000000`<br />`3ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a29ab5f49`<br />`ffff001d1dac2b7c01010000000100000000000000000000000000000000000000000000`<br />`00000000000000000000ffffffff4d04ffff001d0104455468652054696d65732030332f`<br />`4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f`<br />`6e64206261696c6f757420666f722062616e6b73ffffffff0100f2052a01000000434104`<br />`678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f`<br />`4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5fac00000000"`<br /><font color="orange">**Newlines added for display purposes. The actual return does not contain newlines.**</font>| 271 |Example Return (verbose=true, verbosetx=false)|`{`<br /> `"hash": "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f",`<br /> `"confirmations": 277113,`<br /> `"size": 285,`<br /> `"height": 0,`<br /> `"version": 1,`<br /> `"merkleroot": "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b",`<br /> `"tx": [`<br /> `"4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"`<br /> `],`<br /> `"time": 1231006505,`<br /> `"nonce": 2083236893,`<br /> `"bits": "1d00ffff",`<br /> `"difficulty": 1,`<br /> `"previousblockhash": "0000000000000000000000000000000000000000000000000000000000000000",`<br /> `"nextblockhash": "00000000839a8e6886ab5951d76f411475428afc90947ee320161bbf18eb6048"`<br />`}`| 272 [Return to Overview](#MethodOverview)<br /> 273 274 *** 275 <a name="getblockcount"/> 276 277 | | | 278 |---|---| 279 |Method|getblockcount| 280 |Parameters|None| 281 |Description|Returns the number of blocks in the longest block chain.| 282 |Returns|numeric| 283 |Example Return|`276820`| 284 [Return to Overview](#MethodOverview)<br /> 285 286 *** 287 <a name="getblockhash"/> 288 289 | | | 290 |---|---| 291 |Method|getblockhash| 292 |Parameters|1. block height (numeric, required)| 293 |Description|Returns hash of the block in best block chain at the given height.| 294 |Returns|string| 295 |Example Return|`000000000000000096579458d1c0f1531fcfc58d57b4fce51eb177d8d10e784d`| 296 [Return to Overview](#MethodOverview)<br /> 297 298 *** 299 <a name="getblockheader"/> 300 301 | | | 302 |---|---| 303 |Method|getblockheader| 304 |Parameters|1. block hash (string, required) - the hash of the block<br />2. verbose (boolean, optional, default=true) - specifies the block header is returned as a JSON object instead of a hex-encoded string| 305 |Description|Returns hex-encoded bytes of the serialized block header.| 306 |Returns (verbose=false)|`"data" (string) hex-encoded bytes of the serialized block`| 307 |Returns (verbose=true)|`{ (json object)`<br /> `"hash": "blockhash", (string) the hash of the block (same as provided)`<br /> `"confirmations": n, (numeric) the number of confirmations`<br /> `"height": n, (numeric) the height of the block in the block chain`<br /> `"version": n, (numeric) the block version`<br /> `"merkleroot": "hash", (string) root hash of the merkle tree`<br /> `"time": n, (numeric) the block time in seconds since 1 Jan 1970 GMT`<br /> `"nonce": n, (numeric) the block nonce`<br /> `"bits": n, (numeric) the bits which represent the block difficulty`<br /> `"difficulty": n.nn, (numeric) the proof-of-work difficulty as a multiple of the minimum difficulty`<br /> `"previousblockhash": "hash", (string) the hash of the previous block`<br /> `"nextblockhash": "hash", (string) the hash of the next block (only if there is one)`<br />`}`| 308 |Example Return (verbose=false)|`"0200000035ab154183570282ce9afc0b494c9fc6a3cfea05aa8c1add2ecc564900000000`<br />`38ba3d78e4500a5a7570dbe61960398add4410d278b21cd9708e6d9743f374d544fc0552`<br />`27f1001c29c1ea3b"`<br /><font color="orange">**Newlines added for display purposes. The actual return does not contain newlines.**</font>| 309 |Example Return (verbose=true)|`{`<br /> `"hash": "00000000009e2958c15ff9290d571bf9459e93b19765c6801ddeccadbb160a1e",`<br /> `"confirmations": 392076,`<br /> `"height": 100000,`<br /> `"version": 2,`<br /> `"merkleroot": "d574f343976d8e70d91cb278d21044dd8a396019e6db70755a0a50e4783dba38",`<br /> `"time": 1376123972,`<br /> `"nonce": 1005240617,`<br /> `"bits": "1c00f127",`<br /> `"difficulty": 271.75767393,`<br /> `"previousblockhash": "000000004956cc2edd1a8caa05eacfa3c69f4c490bfc9ace820257834115ab35",`<br /> `"nextblockhash": "0000000000629d100db387f37d0f37c51118f250fb0946310a8c37316cbc4028"`<br />`}`| 310 [Return to Overview](#MethodOverview)<br /> 311 312 *** 313 <a name="getconnectioncount"/> 314 315 | | | 316 |---|---| 317 |Method|getconnectioncount| 318 |Parameters|None| 319 |Description|Returns the number of active connections to other peers| 320 |Returns|numeric| 321 |Example Return|`8`| 322 [Return to Overview](#MethodOverview)<br /> 323 324 *** 325 <a name="getdifficulty"/> 326 327 | | | 328 |---|---| 329 |Method|getdifficulty| 330 |Parameters|None| 331 |Description|Returns the proof-of-work difficulty as a multiple of the minimum difficulty.| 332 |Returns|numeric| 333 |Example Return|`1180923195.260000`| 334 [Return to Overview](#MethodOverview)<br /> 335 336 *** 337 <a name="getgenerate"/> 338 339 | | | 340 |---|---| 341 |Method|getgenerate| 342 |Parameters|None| 343 |Description|Return if the server is set to generate coins (mine) or not.| 344 |Returns|`false` (boolean)| 345 [Return to Overview](#MethodOverview)<br /> 346 347 *** 348 <a name="gethashespersec"/> 349 350 | | | 351 |---|---| 352 |Method|gethashespersec| 353 |Parameters|None| 354 |Description|Returns a recent hashes per second performance measurement while generating coins (mining).| 355 |Returns|`0` (numeric)| 356 [Return to Overview](#MethodOverview)<br /> 357 358 *** 359 <a name="getinfo"/> 360 361 | | | 362 |---|---| 363 |Method|getinfo| 364 |Parameters|None| 365 |Description|Returns a JSON object containing various state info.| 366 |Notes|NOTE: Since btcd does NOT contain wallet functionality, wallet-related fields are not returned. See getinfo in btcwallet for a version which includes that information.| 367 |Returns|`{ (json object)`<br /> `"version": n, (numeric) the version of the server`<br /> `"protocolversion": n, (numeric) the latest supported protocol version`<br /> `"blocks": n, (numeric) the number of blocks processed`<br /> `"timeoffset": n, (numeric) the time offset`<br /> `"connections": n, (numeric) the number of connected peers`<br /> `"proxy": "host:port", (string) the proxy used by the server`<br /> `"difficulty": n.nn, (numeric) the current target difficulty`<br /> `"testnet": true or false, (boolean) whether or not server is using testnet`<br /> `"relayfee": n.nn, (numeric) the minimum relay fee for non-free transactions in BTC/KB`<br />`}`| 368 |Example Return|`{`<br /> `"version": 70000`<br /> `"protocolversion": 70001, `<br /> `"blocks": 298963,`<br /> `"timeoffset": 0,`<br /> `"connections": 17,`<br /> `"proxy": "",`<br /> `"difficulty": 8000872135.97,`<br /> `"testnet": false,`<br /> `"relayfee": 0.00001,`<br />`}`| 369 [Return to Overview](#MethodOverview)<br /> 370 371 *** 372 <a name="getmempoolinfo"/> 373 374 | | | 375 |---|---| 376 |Method|getmempoolinfo| 377 |Parameters|None| 378 |Description|Returns a JSON object containing mempool-related information.| 379 |Returns|`{ (json object)`<br /> `"bytes": n, (numeric) size in bytes of the mempool`<br /> `"size": n, (numeric) number of transactions in the mempool`<br />`}`| 380 Example Return|`{`<br /> `"bytes": 310768,`<br /> `"size": 157,`<br />`}`| 381 [Return to Overview](#MethodOverview)<br /> 382 383 *** 384 <a name="getmininginfo"/> 385 386 | | | 387 |---|---| 388 |Method|getmininginfo| 389 |Parameters|None| 390 |Description|Returns a JSON object containing mining-related information.| 391 |Returns|`{ (json object)`<br /> `"blocks": n, (numeric) latest best block`<br /> `"currentblocksize": n, (numeric) size of the latest best block`<br /> `"currentblocktx": n, (numeric) number of transactions in the latest best block`<br /> `"difficulty": n.nn, (numeric) current target difficulty`<br /> `"errors": "errors", (string) any current errors`<br /> `"generate": true or false, (boolean) whether or not server is set to generate coins`<br /> `"genproclimit": n, (numeric) number of processors to use for coin generation (-1 when disabled)`<br /> `"hashespersec": n, (numeric) recent hashes per second performance measurement while generating coins`<br /> `"networkhashps": n, (numeric) estimated network hashes per second for the most recent blocks`<br /> `"pooledtx": n, (numeric) number of transactions in the memory pool`<br /> `"testnet": true or false, (boolean) whether or not server is using testnet`<br />`}`| 392 |Example Return|`{`<br /> `"blocks": 236526,`<br /> `"currentblocksize": 185,`<br /> `"currentblocktx": 1,`<br /> `"difficulty": 256,`<br /> `"errors": "",`<br /> `"generate": false,`<br /> `"genproclimit": -1,`<br /> `"hashespersec": 0,`<br /> `"networkhashps": 33081554756,`<br /> `"pooledtx": 8,`<br /> `"testnet": true,`<br />`}`| 393 [Return to Overview](#MethodOverview)<br /> 394 395 *** 396 <a name="getnettotals"/> 397 398 | | | 399 |---|---| 400 |Method|getnettotals| 401 |Parameters|None| 402 |Description|Returns a JSON object containing network traffic statistics.| 403 |Returns|`{`<br /> `"totalbytesrecv": n, (numeric) total bytes received`<br /> `"totalbytessent": n, (numeric) total bytes sent`<br /> `"timemillis": n (numeric) number of milliseconds since 1 Jan 1970 GMT`<br />`}`| 404 |Example Return|`{`<br /> `"totalbytesrecv": 1150990,`<br /> `"totalbytessent": 206739,`<br /> `"timemillis": 1391626433845`<br />`}`| 405 [Return to Overview](#MethodOverview)<br /> 406 407 *** 408 <a name="getnetworkhashps"/> 409 410 | | | 411 |---|---| 412 |Method|getnetworkhashps| 413 |Parameters|1. blocks (numeric, optional, default=120) - The number of blocks, or -1 for blocks since last difficulty change<br />2. height (numeric, optional, default=-1) - Perform estimate ending with this height or -1 for current best chain block height| 414 |Description|Returns the estimated network hashes per second for the block heights provided by the parameters.| 415 |Returns|numeric| 416 |Example Return|`6573971939`| 417 [Return to Overview](#MethodOverview)<br /> 418 419 *** 420 <a name="getpeerinfo"/> 421 422 | | | 423 |---|---| 424 |Method|getpeerinfo| 425 |Parameters|None| 426 |Description|Returns data about each connected network peer as an array of json objects.| 427 |Returns|`[`<br /> `{`<br /> `"addr": "host:port", (string) the ip address and port of the peer`<br /> `"services": "00000001", (string) the services supported by the peer`<br /> `"lastrecv": n, (numeric) time the last message was received in seconds since 1 Jan 1970 GMT`<br /> `"lastsend": n, (numeric) time the last message was sent in seconds since 1 Jan 1970 GMT`<br /> `"bytessent": n, (numeric) total bytes sent`<br /> `"bytesrecv": n, (numeric) total bytes received`<br /> `"conntime": n, (numeric) time the connection was made in seconds since 1 Jan 1970 GMT`<br /> `"pingtime": n, (numeric) number of microseconds the last ping took`<br /> `"pingwait": n, (numeric) number of microseconds a queued ping has been waiting for a response`<br /> `"version": n, (numeric) the protocol version of the peer`<br /> `"subver": "useragent", (string) the user agent of the peer`<br /> `"inbound": true_or_false, (boolean) whether or not the peer is an inbound connection`<br /> `"startingheight": n, (numeric) the latest block height the peer knew about when the connection was established`<br /> `"currentheight": n, (numeric) the latest block height the peer is known to have relayed since connected`<br /> `"syncnode": true_or_false, (boolean) whether or not the peer is the sync peer`<br /> `}, ...`<br />`]`| 428 |Example Return|`[`<br /> `{`<br /> `"addr": "178.172.xxx.xxx:8333",`<br /> `"services": "00000001",`<br /> `"lastrecv": 1388183523,`<br /> `"lastsend": 1388185470,`<br /> `"bytessent": 287592965,`<br /> `"bytesrecv": 780340,`<br /> `"conntime": 1388182973,`<br /> `"pingtime": 405551,`<br /> `"pingwait": 183023,`<br /> `"version": 70001,`<br /> `"subver": "/btcd:0.4.0/",`<br /> `"inbound": false,`<br /> `"startingheight": 276921,`<br /> `"currentheight": 276955,`<br/> `"syncnode": true,`<br /> `}`<br />`]`| 429 [Return to Overview](#MethodOverview)<br /> 430 431 *** 432 <a name="getrawtransaction"/> 433 434 | | | 435 |---|---| 436 |Method|getrawtransaction| 437 |Parameters|1. transaction hash (string, required) - the hash of the transaction<br />2. verbose (int, optional, default=0) - specifies the transaction is returned as a JSON object instead of hex-encoded string| 438 |Description|Returns information about a transaction given its hash.| 439 |Returns (verbose=0)|`"data" (string) hex-encoded bytes of the serialized transaction`| 440 |Returns (verbose=1)|`{ (json object)`<br /> `"hex": "data", (string) hex-encoded transaction`<br /> `"txid": "hash", (string) the hash of the transaction`<br /> `"version": n, (numeric) the transaction version`<br /> `"locktime": n, (numeric) the transaction lock time`<br /> `"vin": [ (array of json objects) the transaction inputs as json objects`<br /> <font color="orange">For coinbase transactions:</font><br /> `{ (json object)`<br /> `"coinbase": "data", (string) the hex-encoded bytes of the signature script`<br /> `"sequence": n, (numeric) the script sequence number`<br /> `}`<br /> <font color="orange">For non-coinbase transactions:</font><br /> `{ (json object)`<br /> `"txid": "hash", (string) the hash of the origin transaction`<br /> `"vout": n, (numeric) the index of the output being redeemed from the origin transaction`<br /> `"scriptSig": { (json object) the signature script used to redeem the origin transaction`<br /> `"asm": "asm", (string) disassembly of the script`<br /> `"hex": "data", (string) hex-encoded bytes of the script`<br /> `}`<br /> `"sequence": n, (numeric) the script sequence number`<br /> `}, ...`<br /> `]`<br /> `"vout": [ (array of json objects) the transaction outputs as json objects`<br /> `{ (json object)`<br /> `"value": n, (numeric) the value in BTC`<br /> `"n": n, (numeric) the index of this transaction output`<br /> `"scriptPubKey": { (json object) the public key script used to pay coins`<br /> `"asm": "asm", (string) disassembly of the script`<br /> `"hex": "data", (string) hex-encoded bytes of the script`<br /> `"reqSigs": n, (numeric) the number of required signatures`<br /> `"type": "scripttype" (string) the type of the script (e.g. 'pubkeyhash')`<br /> `"addresses": [ (json array of string) the bitcoin addresses associated with this output`<br /> `"bitcoinaddress", (string) the bitcoin address`<br /> `...`<br /> `]`<br /> `}`<br /> `}, ...`<br /> `]`<br />`}`| 441 |Example Return (verbose=0)|`"010000000104be666c7053ef26c6110597dad1c1e81b5e6be53d17a8b9d0b34772054bac60000000`<br />`008c493046022100cb42f8df44eca83dd0a727988dcde9384953e830b1f8004d57485e2ede1b9c8f`<br />`022100fbce8d84fcf2839127605818ac6c3e7a1531ebc69277c504599289fb1e9058df0141045a33`<br />`76eeb85e494330b03c1791619d53327441002832f4bd618fd9efa9e644d242d5e1145cb9c2f71965`<br />`656e276633d4ff1a6db5e7153a0a9042745178ebe0f5ffffffff0280841e00000000001976a91406`<br />`f1b6703d3f56427bfcfd372f952d50d04b64bd88ac4dd52700000000001976a9146b63f291c295ee`<br />`abd9aee6be193ab2d019e7ea7088ac00000000`<br /><font color="orange">**Newlines added for display purposes. The actual return does not contain newlines.**</font>| 442 |Example Return (verbose=1)|`{`<br /> `"hex": "01000000010000000000000000000000000000000000000000000000000000000000000000f...",`<br /> `"txid": "90743aad855880e517270550d2a881627d84db5265142fd1e7fb7add38b08be9",`<br /> `"version": 1,`<br /> `"locktime": 0,`<br /> `"vin": [`<br /> <font color="orange">For coinbase transactions:</font><br /> `{ (json object)`<br /> `"coinbase": "03708203062f503253482f04066d605108f800080100000ea2122f6f7a636f696e4065757374726174756d2f",`<br /> `"sequence": 0,`<br /> `}`<br /> <font color="orange">For non-coinbase transactions:</font><br /> `{`<br /> `"txid": "60ac4b057247b3d0b9a8173de56b5e1be8c1d1da970511c626ef53706c66be04",`<br /> `"vout": 0,`<br /> `"scriptSig": {`<br /> `"asm": "3046022100cb42f8df44eca83dd0a727988dcde9384953e830b1f8004d57485e2ede1b9c8f0...",`<br /> `"hex": "493046022100cb42f8df44eca83dd0a727988dcde9384953e830b1f8004d57485e2ede1b9c8...",`<br /> `}`<br /> `"sequence": 4294967295,`<br /> `}`<br /> `]`<br /> `"vout": [`<br /> `{`<br /> `"value": 25.1394,`<br /> `"n": 0,`<br /> `"scriptPubKey": {`<br /> `"asm": "OP_DUP OP_HASH160 ea132286328cfc819457b9dec386c4b5c84faa5c OP_EQUALVERIFY OP_CHECKSIG",`<br /> `"hex": "76a914ea132286328cfc819457b9dec386c4b5c84faa5c88ac",`<br /> `"reqSigs": 1,`<br /> `"type": "pubkeyhash"`<br /> `"addresses": [`<br /> `"1NLg3QJMsMQGM5KEUaEu5ADDmKQSLHwmyh",`<br /> `]`<br /> `}`<br /> `}`<br /> `]`<br />`}`| 443 [Return to Overview](#MethodOverview)<br /> 444 445 *** 446 <a name="getwork"/> 447 448 | | | 449 |---|---| 450 |Method|getwork| 451 |Parameters|1. data (string, optional) - The hex| 452 |Description|Returns information about a transaction given its hash.| 453 |Notes|<font color="orange">NOTE: Since btcd does not have the wallet integrated to provide payment addresses, btcd must be configured via the `--miningaddr` option to provide which payment addresses to pay created blocks to for this RPC to function.</font> 454 |Returns (data not specified)|`{ (json object)`<br /> `"data": "hex", (string) hex-encoded block data`<br /> `"hash1": "hex", (string) (DEPRECATED) hex-encoded formatted hash buffer`<br /> `"midstate": "hex", (string) (DEPRECATED) hex-encoded precomputed hash state after hashing first half of the data`<br /> `"target": "hex", (string) the hex-encoded little-endian hash target`<br />`}`| 455 |Returns (data specified)|`true` or `false` (boolean)| 456 |Example Return (data not specified)|`{`<br /> `"data": "00000002c39b5d2b7a1e8f7356a1efce26b24bd15d7d906e85341ef9cec99b6a000000006474f...",`<br /> `"hash1": "00000000000000000000000000000000000000000000000000000000000000000000008000000...",`<br /> `"midstate": "ae4a80fc51476e452de855b4e20d5f33418c50fc7cae3b1ecd5badb819b8a584",`<br /> `"target": "0000000000000000000000000000000000000000000000008c96010000000000",`<br />`}`| 457 |Example Return (data specified)|`true`| 458 [Return to Overview](#MethodOverview)<br /> 459 460 *** 461 <a name="help"/> 462 463 | | | 464 |---|---| 465 |Method|help| 466 |Parameters|1. command (string, optional) - the command to get help for| 467 |Description|Returns a list of all commands or help for a specified command.<br />When no `command` parameter is specified, a list of avaialable commands is returned<br />When `command` is a valid method, the help text for that method is returned.| 468 |Returns|string| 469 |Example Return|getblockcount<br />Returns a numeric for the number of blocks in the longest block chain.| 470 [Return to Overview](#MethodOverview)<br /> 471 472 *** 473 <a name="ping"/> 474 475 | | | 476 |---|---| 477 |Method|ping| 478 |Parameters|None| 479 |Description|Queues a ping to be sent to each connected peer.<br />Ping times are provided by [getpeerinfo](#getpeerinfo) via the `pingtime` and `pingwait` fields.| 480 |Returns|Nothing| 481 [Return to Overview](#MethodOverview)<br /> 482 483 *** 484 <a name="getrawmempool"/> 485 486 | | | 487 |---|---| 488 |Method|getrawmempool| 489 |Parameters|1. verbose (boolean, optional, default=false)| 490 |Description|Returns an array of hashes for all of the transactions currently in the memory pool.<br />The `verbose` flag specifies that each transaction is returned as a JSON object.| 491 |Notes|<font color="orange">Since btcd does not perform any mining, the priority related fields `startingpriority` and `currentpriority` that are available when the `verbose` flag is set are always 0.</font>| 492 |Returns (verbose=false)|`[ (json array of string)`<br /> `"transactionhash", (string) hash of the transaction`<br /> `...`<br />`]`| 493 |Returns (verbose=true)|`{ (json object)`<br /> `"transactionhash": { (json object)`<br /> `"size": n, (numeric) transaction size in bytes`<br /> `"fee" : n, (numeric) transaction fee in bitcoins`<br /> `"time": n, (numeric) local time transaction entered pool in seconds since 1 Jan 1970 GMT`<br /> `"height": n, (numeric) block height when transaction entered the pool`<br /> `"startingpriority": n, (numeric) priority when transaction entered the pool`<br /> `"currentpriority": n, (numeric) current priority`<br /> `"depends": [ (json array) unconfirmed transactions used as inputs for this transaction`<br /> `"transactionhash", (string) hash of the parent transaction`<br /> `...`<br /> `]`<br /> `}, ...`<br />`}`| 494 |Example Return (verbose=false)|`[`<br /> `"3480058a397b6ffcc60f7e3345a61370fded1ca6bef4b58156ed17987f20d4e7",`<br /> `"cbfe7c056a358c3a1dbced5a22b06d74b8650055d5195c1c2469e6b63a41514a"`<br />`]`| 495 |Example Return (verbose=true)|`{`<br /> `"1697a19cede08694278f19584e8dcc87945f40c6b59a942dd8906f133ad3f9cc": {`<br /> `"size": 226,`<br /> `"fee" : 0.0001,`<br /> `"time": 1387992789,`<br /> `"height": 276836,`<br /> `"startingpriority": 0,`<br /> `"currentpriority": 0,`<br /> `"depends": [`<br /> `"aa96f672fcc5a1ec6a08a94aa46d6b789799c87bd6542967da25a96b2dee0afb",`<br /> `]`<br />`}`| 496 [Return to Overview](#MethodOverview)<br /> 497 498 *** 499 <a name="setgenerate"/> 500 501 | | | 502 |---|---| 503 |Method|setgenerate| 504 |Parameters|1. generate (boolean, required) - `true` to enable generation, `false` to disable it<br />2. genproclimit (numeric, optional) - the number of processors (cores) to limit generation to or `-1` for default| 505 |Description|Set the server to generate coins (mine) or not.| 506 |Notes|NOTE: Since btcd does not have the wallet integrated to provide payment addresses, btcd must be configured via the `--miningaddr` option to provide which payment addresses to pay created blocks to for this RPC to function.| 507 |Returns|Nothing| 508 [Return to Overview](#MethodOverview)<br /> 509 510 *** 511 <a name="sendrawtransaction"/> 512 513 | | | 514 |---|---| 515 |Method|sendrawtransaction| 516 |Parameters|1. signedhex (string, required) serialized, hex-encoded signed transaction<br />2. allowhighfees (boolean, optional, default=false) whether or not to allow insanely high fees| 517 |Description|Submits the serialized, hex-encoded transaction to the local peer and relays it to the network.| 518 |Notes|<font color="orange">btcd does not yet implement the `allowhighfees` parameter, so it has no effect</font>| 519 |Returns|`"hash" (string) the hash of the transaction`| 520 |Example Return|`"1697a19cede08694278f19584e8dcc87945f40c6b59a942dd8906f133ad3f9cc"`| 521 [Return to Overview](#MethodOverview)<br /> 522 523 *** 524 <a name="submitblock"/> 525 526 | | | 527 |---|---| 528 |Method|submitblock| 529 |Parameters|1. data (string, required) serialized, hex-encoded block<br />2. params (json object, optional, default=nil) this parameter is currently ignored| 530 |Description|Attempts to submit a new serialized, hex-encoded block to the network.| 531 |Returns (success)|Success: Nothing<br />Failure: `"rejected: reason"` (string)| 532 [Return to Overview](#MethodOverview)<br /> 533 534 *** 535 <a name="stop"/> 536 537 | | | 538 |---|---| 539 |Method|stop| 540 |Parameters|None| 541 |Description|Shutdown btcd.| 542 |Returns|`"btcd stopping."` (string)| 543 [Return to Overview](#MethodOverview)<br /> 544 545 *** 546 <a name="validateaddress"/> 547 548 | | | 549 |---|---| 550 |Method|validateaddress| 551 |Parameters|1. address (string, required) - bitcoin address| 552 |Description|Verify an address is valid.| 553 |Returns|`{ (json object)`<br /> `"isvalid": true or false, (bool) whether or not the address is valid.`<br /> `"address": "bitcoinaddress", (string) the bitcoin address validated.`<br />}| 554 [Return to Overview](#MethodOverview)<br /> 555 556 *** 557 <a name="verifychain"/> 558 559 | | | 560 |---|---| 561 |Method|verifychain| 562 |Parameters|1. checklevel (numeric, optional, default=3) - how in-depth the verification is (0=least amount of checks, higher levels are clamped to the highest supported level)<br />2. numblocks (numeric, optional, default=288) - the number of blocks starting from the end of the chain to verify| 563 |Description|Verifies the block chain database.<br />The actual checks performed by the `checklevel` parameter is implementation specific. For btcd this is:<br />`checklevel=0` - Look up each block and ensure it can be loaded from the database.<br />`checklevel=1` - Perform basic context-free sanity checks on each block.| 564 |Notes|<font color="orange">Btcd currently only supports `checklevel` 0 and 1, but the default is still 3 for compatibility. Per the information in the Parameters section above, higher levels are automatically clamped to the highest supported level, so this means the default is effectively 1 for btcd.</font>| 565 |Returns|`true` or `false` (boolean)| 566 |Example Return|`true`| 567 [Return to Overview](#MethodOverview)<br /> 568 569 570 <a name="ExtensionMethods" /> 571 ### 6. Extension Methods 572 573 <a name="ExtMethodOverview" /> 574 **6.1 Method Overview**<br /> 575 576 The following is an overview of the RPC methods which are implemented by btcd, but not the original bitcoind client. Click the method name for further details such as parameter and return information. 577 578 |#|Method|Safe for limited user?|Description| 579 |---|------|----------|-----------| 580 |1|[debuglevel](#debuglevel)|N|Dynamically changes the debug logging level.| 581 |2|[getbestblock](#getbestblock)|Y|Get block height and hash of best block in the main chain.|None| 582 |3|[getcurrentnet](#getcurrentnet)|Y|Get bitcoin network btcd is running on.|None| 583 |4|[searchrawtransactions](#searchrawtransactions)|Y|Query for transactions related to a particular address.|None| 584 |5|[node](#node)|N|Attempts to add or remove a peer. |None| 585 |6|[generate](#generate)|N|When in simnet or regtest mode, generate a set number of blocks. |None| 586 587 588 <a name="ExtMethodDetails" /> 589 **6.2 Method Details**<br /> 590 591 <a name="debuglevel"/> 592 593 | | | 594 |---|---| 595 |Method|debuglevel| 596 |Parameters|1. _levelspec_ (string)| 597 |Description|Dynamically changes the debug logging level.<br />The levelspec can either a debug level or of the form `<subsystem>=<level>,<subsystem2>=<level2>,...`<br />The valid debug levels are `trace`, `debug`, `info`, `warn`, `error`, and `critical`.<br />The valid subsystems are `AMGR`, `ADXR`, `BCDB`, `BMGR`, `BTCD`, `CHAN`, `DISC`, `PEER`, `RPCS`, `SCRP`, `SRVR`, and `TXMP`.<br />Additionally, the special keyword `show` can be used to get a list of the available subsystems.| 598 |Returns|string| 599 |Example Return|`Done.`| 600 |Example `show` Return|`Supported subsystems [AMGR ADXR BCDB BMGR BTCD CHAN DISC PEER RPCS SCRP SRVR TXMP]`| 601 [Return to Overview](#ExtMethodOverview)<br /> 602 603 *** 604 605 <a name="getbestblock"/> 606 607 | | | 608 |---|---| 609 |Method|getbestblock| 610 |Parameters|None| 611 |Description|Get block height and hash of best block in the main chain.| 612 |Returns|`{ (json object)`<br /> `"hash": "data", (string) the hex-encoded bytes of the best block hash`<br /> `"height": n (numeric) the block height of the best block`<br />`}`| 613 [Return to Overview](#ExtMethodOverview)<br /> 614 615 *** 616 617 <a name="getcurrentnet"/> 618 619 | | | 620 |---|---| 621 |Method|getcurrentnet| 622 |Parameters|None| 623 |Description|Get bitcoin network btcd is running on.| 624 |Returns|numeric| 625 |Example Return|`3652501241` (mainnet)<br />`118034699` (testnet3)| 626 [Return to Overview](#ExtMethodOverview)<br /> 627 628 *** 629 630 <a name="searchrawtransactions"/> 631 632 | | | 633 |---|---| 634 |Method|searchrawtransactions| 635 |Parameters|1. address (string, required) - bitcoin address <br /> 2. verbose (int, optional, default=true) - specifies the transaction is returned as a JSON object instead of hex-encoded string <br />3. skip (int, optional, default=0) - the number of leading transactions to leave out of the final response <br /> 4. count (int, optional, default=100) - the maximum number of transactions to return <br /> 5. vinextra (int, optional, default=0) - Specify that extra data from previous output will be returned in vin <br /> 6. reverse (boolean, optional, default=false) - Specifies that the transactions should be returned in reverse chronological order| 636 |Description|Returns raw data for transactions involving the passed address. Returned transactions are pulled from both the database, and transactions currently in the mempool. Transactions pulled from the mempool will have the `"confirmations"` field set to 0. Usage of this RPC requires the optional `--addrindex` flag to be activated, otherwise all responses will simply return with an error stating the address index has not yet been built up. Similarly, until the address index has caught up with the current best height, all requests will return an error response in order to avoid serving stale data.| 637 |Returns (verbose=0)|`[ (json array of strings)` <br/> `"serializedtx", ... hex-encoded bytes of the serialized transaction` <br/>`]` | 638 |Returns (verbose=1)|`[ (array of json objects)` <br/> `{ (json object)`<br /> `"hex": "data", (string) hex-encoded transaction`<br /> `"txid": "hash", (string) the hash of the transaction`<br /> `"version": n, (numeric) the transaction version`<br /> `"locktime": n, (numeric) the transaction lock time`<br /> `"vin": [ (array of json objects) the transaction inputs as json objects`<br /> <font color="orange">For coinbase transactions:</font><br /> `{ (json object)`<br /> `"coinbase": "data", (string) the hex-encoded bytes of the signature script`<br /> `"sequence": n, (numeric) the script sequence number`<br /> `}`<br /> <font color="orange">For non-coinbase transactions:</font><br /> `{ (json object)`<br /> `"txid": "hash", (string) the hash of the origin transaction`<br /> `"vout": n, (numeric) the index of the output being redeemed from the origin transaction`<br /> `"scriptSig": { (json object) the signature script used to redeem the origin transaction`<br /> `"asm": "asm", (string) disassembly of the script`<br /> `"hex": "data", (string) hex-encoded bytes of the script`<br /> `}`<br /> `"prevOut": { (json object) Data from the origin transaction output with index vout.`<br /> `"addresses": ["value",...], (array of string) previous output addresses`<br /> `"value": n.nnn, (numeric) previous output value`<br /> `}`<br /> `"sequence": n, (numeric) the script sequence number`<br /> `}, ...`<br /> `]`<br /> `"vout": [ (array of json objects) the transaction outputs as json objects`<br /> `{ (json object)`<br /> `"value": n, (numeric) the value in BTC`<br /> `"n": n, (numeric) the index of this transaction output`<br /> `"scriptPubKey": { (json object) the public key script used to pay coins`<br /> `"asm": "asm", (string) disassembly of the script`<br /> `"hex": "data", (string) hex-encoded bytes of the script`<br /> `"reqSigs": n, (numeric) the number of required signatures`<br /> `"type": "scripttype" (string) the type of the script (e.g. 'pubkeyhash')`<br /> `"addresses": [ (json array of string) the bitcoin addresses associated with this output`<br /> `"address", (string) the bitcoin address`<br /> `...`<br /> `]`<br /> `}`<br /> `}, ...`<br /> `]`<br /> `"blockhash":"hash" Hash of the block the transaction is part of.` <br /> `"confirmations":n, Number of numeric confirmations of block.` <br /> `"time":t, Transaction time in seconds since the epoch.` <br /> `"blocktime":t, Block time in seconds since the epoch.`<br />`},...`<br/> `]`| 639 [Return to Overview](#ExtMethodOverview)<br /> 640 641 *** 642 643 <a name="node"/> 644 645 | | | 646 |---|---| 647 |Method|node| 648 |Parameters|1. command (string, required) - `connect` to add a peer (defaults to temporary), `remove` to remove a persistent peer, or `disconnect` to remove all matching non-persistent peers <br /> 2. peer (string, required) - ip address and port, or ID of the peer to operate on<br /> 3. connection type (string, optional) - `perm` indicates the peer should be added as a permanent peer, `temp` indicates a connection should only be attempted once. | 649 |Description|Attempts to add or remove a peer.| 650 |Returns|Nothing| 651 [Return to Overview](#MethodOverview)<br /> 652 653 *** 654 655 <a name="generate"/> 656 657 | | | 658 |---|---| 659 |Method|generate| 660 |Parameters|1. numblocks (int, required) - The number of blocks to generate | 661 |Description|When in simnet or regtest mode, generates `numblocks` blocks. If blocks arrive from elsewhere, they are built upon but don't count toward the number of blocks to generate. Only generated blocks are returned. This RPC call will exit with an error if the server is already CPU mining, and will prevent the server from CPU mining for another command while it runs. | 662 |Returns|`[ (json array of strings)` <br/> `"blockhash", ... hash of the generated block` <br/>`]` | 663 [Return to Overview](#MethodOverview)<br /> 664 665 *** 666 667 <a name="WSExtMethods" /> 668 ### 7. Websocket Extension Methods (Websocket-specific) 669 670 <a name="WSExtMethodOverview" /> 671 **7.1 Method Overview**<br /> 672 673 The following is an overview of the RPC method requests available exclusively to Websocket clients. All of these RPC methods are available to the limited 674 user. Click the method name for further details such as parameter and return information. 675 676 |#|Method|Description|Notifications| 677 |---|------|-----------|-------------| 678 |1|[authenticate](#authenticate)|Authenticate the connection against the username and passphrase configured for the RPC server.<br /><font color="orange">NOTE: This is only required if an HTTP Authorization header is not being used.</font>|None| 679 |2|[notifyblocks](#notifyblocks)|Send notifications when a block is connected or disconnected from the best chain.|[blockconnected](#blockconnected) and [blockdisconnected](#blockdisconnected)| 680 |3|[stopnotifyblocks](#stopnotifyblocks)|Cancel registered notifications for whenever a block is connected or disconnected from the main (best) chain. |None| 681 |4|[notifyreceived](#notifyreceived)|Send notifications when a txout spends to an address.|[recvtx](#recvtx) and [redeemingtx](#redeemingtx)| 682 |5|[stopnotifyreceived](#stopnotifyreceived)|Cancel registered notifications for when a txout spends to any of the passed addresses.|None| 683 |6|[notifyspent](#notifyspent)|Send notification when a txout is spent.|[redeemingtx](#redeemingtx)| 684 |7|[stopnotifyspent](#stopnotifyspent)|Cancel registered spending notifications for each passed outpoint.|None| 685 |8|[rescan](#rescan)|Rescan block chain for transactions to addresses and spent transaction outpoints.|[recvtx](#recvtx), [redeemingtx](#redeemingtx), [rescanprogress](#rescanprogress), and [rescanfinished](#rescanfinished) | 686 |9|[notifynewtransactions](#notifynewtransactions)|Send notifications for all new transactions as they are accepted into the mempool.|[txaccepted](#txaccepted) or [txacceptedverbose](#txacceptedverbose)| 687 |10|[stopnotifynewtransactions](#stopnotifynewtransactions)|Stop sending either a txaccepted or a txacceptedverbose notification when a new transaction is accepted into the mempool.|None| 688 |11|[session](#session)|Return details regarding a websocket client's current connection.|None| 689 690 <a name="WSExtMethodDetails" /> 691 **7.2 Method Details**<br /> 692 693 <a name="authenticate"/> 694 695 | | | 696 |---|---| 697 |Method|authenticate| 698 |Parameters|1. username (string, required)<br />2. passphrase (string, required)| 699 |Description|Authenticate the connection against the username and password configured for the RPC server.<br /> Invoking any other method before authenticating with this command will close the connection.<br /><font color="orange">NOTE: This is only required if an HTTP Authorization header is not being used.</font>| 700 |Returns|Success: Nothing<br />Failure: Nothing (websocket disconnected)| 701 [Return to Overview](#WSExtMethodOverview)<br /> 702 703 *** 704 705 <a name="notifyblocks"/> 706 707 | | | 708 |---|---| 709 |Method|notifyblocks| 710 |Notifications|[blockconnected](#blockconnected) and [blockdisconnected](#blockdisconnected)| 711 |Parameters|None| 712 |Description|Request notifications for whenever a block is connected or disconnected from the main (best) chain.<br />NOTE: If a client subscribes to both block and transaction (recvtx and redeemingtx) notifications, the blockconnected notification will be sent after all transaction notifications have been sent. This allows clients to know when all relevant transactions for a block have been received.| 713 |Returns|Nothing| 714 [Return to Overview](#WSExtMethodOverview)<br /> 715 716 *** 717 <a name="stopnotifyblocks"/> 718 719 | | | 720 |---|---| 721 |Method|stopnotifyblocks| 722 |Notifications|None| 723 |Parameters|None| 724 |Description|Cancel sending notifications for whenever a block is connected or disconnected from the main (best) chain.| 725 |Returns|Nothing| 726 [Return to Overview](#WSExtMethodOverview)<br /> 727 728 *** 729 730 <a name="notifyreceived"/> 731 732 | | | 733 |---|---| 734 |Method|notifyreceived| 735 |Notifications|[recvtx](#recvtx) and [redeemingtx](#redeemingtx)| 736 |Parameters|1. Addresses (JSON array, required)<br /> `[ (json array of strings)`<br /> `"bitcoinaddress", (string) the bitcoin address`<br /> `...`<br /> `]`| 737 |Description|Send a recvtx notification when a transaction added to mempool or appears in a newly-attached block contains a txout pkScript sending to any of the passed addresses. Matching outpoints are automatically registered for redeemingtx notifications.| 738 |Returns|Nothing| 739 [Return to Overview](#WSExtMethodOverview)<br /> 740 741 *** 742 743 <a name="stopnotifyreceived"/> 744 745 | | | 746 |---|---| 747 |Method|stopnotifyreceived| 748 |Notifications|None| 749 |Parameters|1. Addresses (JSON array, required)<br /> `[ (json array of strings)`<br /> `"bitcoinaddress", (string) the bitcoin address`<br /> `...`<br /> `]`| 750 |Description|Cancel registered receive notifications for each passed address.| 751 |Returns|Nothing| 752 [Return to Overview](#WSExtMethodOverview)<br /> 753 754 *** 755 756 <a name="notifyspent"/> 757 758 | | | 759 |---|---| 760 |Method|notifyspent| 761 |Notifications|[redeemingtx](#redeemingtx)| 762 |Parameters|1. Outpoints (JSON array, required)<br /> `[ (JSON array)`<br /> `{ (JSON object)`<br /> `"hash":"data", (string) the hex-encoded bytes of the outpoint hash`<br /> `"index":n (numeric) the txout index of the outpoint`<br /> `},`<br /> `...`<br /> `]`| 763 |Description|Send a redeemingtx notification when a transaction spending an outpoint appears in mempool (if relayed to this btcd instance) and when such a transaction first appears in a newly-attached block.| 764 |Returns|Nothing| 765 [Return to Overview](#WSExtMethodOverview)<br /> 766 767 *** 768 769 <a name="stopnotifyspent"/> 770 771 | | | 772 |---|---| 773 |Method|stopnotifyspent| 774 |Notifications|None| 775 |Parameters|1. Outpoints (JSON array, required)<br /> `[ (JSON array)`<br /> `{ (JSON object)`<br /> `"hash":"data", (string) the hex-encoded bytes of the outpoint hash`<br /> `"index":n (numeric) the txout index of the outpoint`<br /> `},`<br /> `...`<br /> `]`| 776 |Description|Cancel registered spending notifications for each passed outpoint.| 777 |Returns|Nothing| 778 [Return to Overview](#WSExtMethodOverview)<br /> 779 780 *** 781 782 <a name="rescan"/> 783 784 | | | 785 |---|---| 786 |Method|rescan| 787 |Notifications|[recvtx](#recvtx), [redeemingtx](#redeemingtx), [rescanprogress](#rescanprogress), and [rescanfinished](#rescanfinished)| 788 |Parameters|1. BeginBlock (string, required) block hash to begin rescanning from<br />2. Addresses (JSON array, required)<br /> `[ (json array of strings)`<br /> `"bitcoinaddress", (string) the bitcoin address`<br /> `...` <br /> `]`<br />3. Outpoints (JSON array, required)<br /> `[ (JSON array)`<br /> `{ (JSON object)`<br /> `"hash":"data", (string) the hex-encoded bytes of the outpoint hash`<br /> `"index":n (numeric) the txout index of the outpoint`<br /> `},`<br /> `...`<br /> `]`<br />4. EndBlock (string, optional) hash of final block to rescan| 789 |Description|Rescan block chain for transactions to addresses, starting at block BeginBlock and ending at EndBlock. The current known UTXO set for all passed addresses at height BeginBlock should included in the Outpoints argument. If EndBlock is omitted, the rescan continues through the best block in the main chain. Additionally, if no EndBlock is provided, the client is automatically registered for transaction notifications for all rescanned addresses and the final UTXO set. Rescan results are sent as recvtx and redeemingtx notifications. This call returns once the rescan completes.| 790 |Returns|Nothing| 791 [Return to Overview](#WSExtMethodOverview)<br /> 792 793 *** 794 795 <a name="notifynewtransactions"/> 796 797 | | | 798 |---|---| 799 |Method|notifynewtransactions| 800 |Notifications|[txaccepted](#txaccepted) or [txacceptedverbose](#txacceptedverbose)| 801 |Parameters|1. verbose (boolean, optional, default=false) - specifies which type of notification to receive. If verbose is true, then the caller receives [txacceptedverbose](#txacceptedverbose), otherwise the caller receives [txaccepted](#txaccepted)| 802 |Description|Send either a [txaccepted](#txaccepted) or a [txacceptedverbose](#txacceptedverbose) notification when a new transaction is accepted into the mempool.| 803 |Returns|Nothing| 804 [Return to Overview](#WSExtMethodOverview)<br /> 805 806 *** 807 808 <a name="stopnotifynewtransactions"/> 809 810 | | | 811 |---|---| 812 |Method|stopnotifynewtransactions| 813 |Notifications|None| 814 |Parameters|None| 815 |Description|Stop sending either a [txaccepted](#txaccepted) or a [txacceptedverbose](#txacceptedverbose) notification when a new transaction is accepted into the mempool.| 816 |Returns|Nothing| 817 [Return to Overview](#WSExtMethodOverview)<br /> 818 819 *** 820 821 <a name="session"/> 822 823 | | | 824 |---|---| 825 |Method|session| 826 |Notifications|None| 827 |Parameters|None| 828 |Description|Return a JSON object with details regarding a websocket client's current connection to the RPC server. This currently only includes the session ID, a random unsigned 64-bit integer that is created for each newly connected client. Session IDs may be used to verify that the current connection was not lost and subsequently reestablished.| 829 |Returns|`{ (json object)`<br /> `"sessionid": n (numeric) the session ID`<br />`}`| 830 |Example Return|`{`<br /> `"sessionid": 67089679842`<br />`}`| 831 [Return to Overview](#WSExtMethodOverview)<br /> 832 833 834 <a name="Notifications" /> 835 ### 8. Notifications (Websocket-specific) 836 837 btcd uses standard JSON-RPC notifications to notify clients of changes, rather than requiring clients to poll btcd for updates. JSON-RPC notifications are a subset of requests, but do not contain an ID. The notification type is categorized by the `method` field and additional details are sent as a JSON array in the `params` field. 838 839 <a name="NotificationOverview" /> 840 **8.1 Notification Overview**<br /> 841 842 The following is an overview of the JSON-RPC notifications used for Websocket connections. Click the method name for further details of the context(s) in which they are sent and their parameters. 843 844 |#|Method|Description|Request| 845 |---|------|-----------|-------| 846 |1|[blockconnected](#blockconnected)|Block connected to the main chain.|[notifyblocks](#notifyblocks)| 847 |2|[blockdisconnected](#blockdisconnected)|Block disconnected from the main chain.|[notifyblocks](#notifyblocks)| 848 |3|[recvtx](#recvtx)|Processed a transaction output spending to a wallet address.|[notifyreceived](#notifyreceived) and [rescan](#rescan)| 849 |4|[redeemingtx](#redeemingtx)|Processed a transaction that spends a registered outpoint.|[notifyspent](#notifyspent) and [rescan](#rescan)| 850 |5|[txaccepted](#txaccepted)|Received a new transaction after requesting simple notifications of all new transactions accepted into the mempool.|[notifynewtransactions](#notifynewtransactions)| 851 |6|[txacceptedverbose](#txacceptedverbose)|Received a new transaction after requesting verbose notifications of all new transactions accepted into the mempool.|[notifynewtransactions](#notifynewtransactions)| 852 |7|[rescanprogress](#rescanprogress)|A rescan operation that is underway has made progress.|[rescan](#rescan)| 853 |8|[rescanfinished](#rescanfinished)|A rescan operation has completed.|[rescan](#rescan)| 854 855 <a name="NotificationDetails" /> 856 **8.2 Notification Details**<br /> 857 858 <a name="blockconnected"/> 859 860 | | | 861 |---|---| 862 |Method|blockconnected| 863 |Request|[notifyblocks](#notifyblocks)| 864 |Parameters|1. BlockHash (string) hex-encoded bytes of the attached block hash<br />2. BlockHeight (numeric) height of the attached block<br />3. BlockTime (numeric) unix time of the attached block| 865 |Description|Notifies when a block has been added to the main chain. Notification is sent to all connected clients.| 866 |Example|Example blockconnected notification for mainnet block 280330 (newlines added for readability):<br />`{`<br /> `"jsonrpc": "1.0",`<br /> `"method": "blockconnected",`<br /> `"params":`<br /> `[`<br /> `"000000000000000004cbdfe387f4df44b914e464ca79838a8ab777b3214dbffd",`<br /> `280330,`<br /> `1389636265`<br /> `],`<br /> `"id": null`<br />`}`| 867 [Return to Overview](#NotificationOverview)<br /> 868 869 *** 870 871 <a name="blockdisconnected"/> 872 873 | | | 874 |---|---| 875 |Method|blockdisconnected| 876 |Request|[notifyblocks](#notifyblocks)| 877 |Parameters|1. BlockHash (string) hex-encoded bytes of the disconnected block hash<br />2. BlockHeight (numeric) height of the disconnected block<br />3. BlockTime (numeric) unix time of the disconnected block| 878 |Description|Notifies when a block has been removed from the main chain. Notification is sent to all connected clients.| 879 |Example|Example blockdisconnected notification for mainnet block 280330 (newlines added for readability):<br />`{`<br /> `"jsonrpc": "1.0",`<br /> `"method": "blockdisconnected",`<br /> `"params":`<br /> `[`<br /> `"000000000000000004cbdfe387f4df44b914e464ca79838a8ab777b3214dbffd",`<br /> `280330,`<br /> `1389636265`<br /> `],`<br /> `"id": null`<br />`}`| 880 [Return to Overview](#NotificationOverview)<br /> 881 882 *** 883 884 <a name="recvtx"/> 885 886 | | | 887 |---|---| 888 |Method|recvtx| 889 |Request|[rescan](#rescan) or [notifyreceived](#notifyreceived)| 890 |Parameters|1. Transaction (string) full transaction encoded as a hex string<br />2. Block details (object, optional) details about a block and the index of the transaction within a block, if the transaction is mined| 891 |Description|Notifies a client when a transaction is processed that contains at least a single output with a pkScript sending to a requested address. If multiple outputs send to requested addresses, a single notification is sent. If a mempool (unmined) transaction is processed, the block details object (second parameter) is excluded.| 892 |Example|Example recvtx notification for mainnet transaction 61d3696de4c888730cbe06b0ad8ecb6d72d6108e893895aa9bc067bd7eba3fad when processed by mempool (newlines added for readability):<br />`{`<br /> `"jsonrpc": "1.0",`<br /> `"method": "recvtx",`<br /> `"params":`<br /> `[`<br /> `"010000000114d9ff358894c486b4ae11c2a8cf7851b1df64c53d2e511278eff17c22fb737300000000..."`<br /> `],`<br /> `"id": null`<br />`}`<br />The recvtx notification for the same txout, after the transaction was mined into block 276425:<br />`{`<br /> `"jsonrpc": "1.0",`<br /> `"method": "recvtx",`<br /> `"params":`<br /> `[`<br /> `"010000000114d9ff358894c486b4ae11c2a8cf7851b1df64c53d2e511278eff17c22fb737300000000...",`<br /> `{`<br /> `"height": 276425,`<br /> `"hash": "000000000000000325474bb799b9e591f965ca4461b72cb7012b808db92bb2fc",`<br /> `"index": 684,`<br /> `"time": 1387737310`<br /> `}`<br /> `],`<br /> `"id": null`<br />`}`| 893 [Return to Overview](#NotificationOverview)<br /> 894 895 *** 896 897 <a name="redeemingtx"/> 898 899 | | | 900 |---|---| 901 |Method|redeemingtx| 902 |Requests|[notifyspent](#notifyspent) and [rescan](#rescan)| 903 |Parameters|1. Transaction (string) full transaction encoded as a hex string<br />2. Block details (object, optional) details about a block and the index of the transaction within a block, if the transaction is mined| 904 |Description|Notifies a client when an registered outpoint is spent by a transaction accepted to mempool and/or mined into a block.| 905 |Example|Example redeemingtx notification for mainnet outpoint 61d3696de4c888730cbe06b0ad8ecb6d72d6108e893895aa9bc067bd7eba3fad:0 after being spent by transaction 4ad0c16ac973ff675dec1f3e5f1273f1c45be2a63554343f21b70240a1e43ece (newlines added for readability):<br />`{`<br /> `"jsonrpc": "1.0",`<br /> `"method": "redeemingtx",`<br /> `"params":`<br /> `[`<br /> `"0100000003ad3fba7ebd67c09baa9538898e10d6726dcb8eadb006be0c7388c8e46d69d3610000000..."`<br /> `],`<br /> `"id": null`<br />`}`<br />The redeemingtx notification for the same txout, after the spending transaction was mined into block 279143:<br />`{`<br /> `"jsonrpc": "1.0",`<br /> `"method": "recvtx",`<br /> `"params":`<br /> `[`<br /> `"0100000003ad3fba7ebd67c09baa9538898e10d6726dcb8eadb006be0c7388c8e46d69d3610000000...",`<br /> `{`<br /> `"height": 279143,`<br /> `"hash": "00000000000000017188b968a371bab95aa43522665353b646e41865abae02a4",`<br /> `"index": 6,`<br /> `"time": 1389115004`<br /> `}`<br /> `],`<br /> `"id": null`<br />`}`| 906 [Return to Overview](#NotificationOverview)<br /> 907 908 *** 909 910 <a name="txaccepted"/> 911 912 | | | 913 |---|---| 914 |Method|txaccepted| 915 |Request|[notifynewtransactions](#notifynewtransactions)| 916 |Parameters|1. TxSha (string) hex-encoded bytes of the transaction hash<br />2. Amount (numeric) sum of the value of all the transaction outpoints| 917 |Description|Notifies when a new transaction has been accepted and the client has requested standard transaction details.| 918 |Example|Example txaccepted notification for mainnet transaction id "16c54c9d02fe570b9d41b518c0daefae81cc05c69bbe842058e84c6ed5826261" (newlines added for readability):<br />`{`<br /> `"jsonrpc": "1.0",`<br /> `"method": "txaccepted",`<br /> `"params":`<br /> `[`<br /> `"16c54c9d02fe570b9d41b518c0daefae81cc05c69bbe842058e84c6ed5826261",`<br /> `55838384`<br /> `],`<br /> `"id": null`<br />`}`| 919 [Return to Overview](#NotificationOverview)<br /> 920 921 *** 922 923 <a name="txacceptedverbose"/> 924 925 | | | 926 |---|---| 927 |Method|txacceptedverbose| 928 |Request|[notifynewtransactions](#notifynewtransactions)| 929 |Parameters|1. RawTx (json object) the transaction as a json object (see getrawtransaction json object details)| 930 |Description|Notifies when a new transaction has been accepted and the client has requested verbose transaction details.| 931 |Example|Example txacceptedverbose notification (newlines added for readability):<br />`{`<br /> `"jsonrpc": "1.0",`<br /> `"method": "txacceptedverbose",`<br /> `"params":`<br /> `[`<br /> `{`<br /> `"hex": "01000000010000000000000000000000000000000000000000000000000000000000000000f...",`<br /> `"txid": "90743aad855880e517270550d2a881627d84db5265142fd1e7fb7add38b08be9",`<br /> `"version": 1,`<br /> `"locktime": 0,`<br /> `"vin": [`<br /> <font color="orange">For coinbase transactions:</font><br /> `{ (json object)`<br /> `"coinbase": "03708203062f503253482f04066d605108f800080100000ea2122f6f7a636f696e4065757374726174756d2f",`<br /> `"sequence": 0,`<br /> `}`<br /> <font color="orange">For non-coinbase transactions:</font><br /> `{`<br /> `"txid": "60ac4b057247b3d0b9a8173de56b5e1be8c1d1da970511c626ef53706c66be04",`<br /> `"vout": 0,`<br /> `"scriptSig": {`<br /> `"asm": "3046022100cb42f8df44eca83dd0a727988dcde9384953e830b1f8004d57485e2ede1b9c8f0...",`<br /> `"hex": "493046022100cb42f8df44eca83dd0a727988dcde9384953e830b1f8004d57485e2ede1b9c8...",`<br /> `}`<br /> `"sequence": 4294967295,`<br /> `}`<br /> `],`<br /> `"vout": [`<br /> `{`<br /> `"value": 25.1394,`<br /> `"n": 0,`<br /> `"scriptPubKey": {`<br /> `"asm": "OP_DUP OP_HASH160 ea132286328cfc819457b9dec386c4b5c84faa5c OP_EQUALVERIFY OP_CHECKSIG",`<br /> `"hex": "76a914ea132286328cfc819457b9dec386c4b5c84faa5c88ac",`<br /> `"reqSigs": 1,`<br /> `"type": "pubkeyhash"`<br /> `"addresses": [`<br /> `"1NLg3QJMsMQGM5KEUaEu5ADDmKQSLHwmyh",`<br /> `]`<br /> `}`<br /> `]`<br /> `}`<br /> `],`<br /> `"id": null`<br />`}`| 932 [Return to Overview](#NotificationOverview)<br /> 933 934 *** 935 936 <a name="rescanprogress"/> 937 938 | | | 939 |---|---| 940 |Method|rescanprogress| 941 |Request|[rescan](#rescan)| 942 |Parameters|1. Hash (string) hash of the last processed block<br />2. Height (numeric) height of the last processed block<br />3. Time (numeric) UNIX time of the last processed block| 943 |Description|Notifies a client with the current progress at periodic intervals when a long-running [rescan](#rescan) is underway.| 944 |Example|`{`<br /> `"jsonrpc": "1.0",`<br /> `"method": "rescanprogress",`<br /> `"params":`<br /> `[`<br /> `"0000000000000ea86b49e11843b2ad937ac89ae74a963c7edd36e0147079b89d",`<br /> `127213,`<br /> `1306533807`<br /> `],`<br /> `"id": null`<br />`}`| 945 [Return to Overview](#NotificationOverview)<br /> 946 947 *** 948 949 <a name="rescanfinished"/> 950 951 | | | 952 |---|---| 953 |Method|rescanfinished| 954 |Request|[rescan](#rescan)| 955 |Parameters|1. Hash (string) hash of the last rescanned block<br />2. Height (numeric) height of the last rescanned block<br />3. Time (numeric) UNIX time of the last rescanned block | 956 |Description|Notifies a client that the [rescan](#rescan) has completed and no further notifications will be sent.| 957 |Example|`{`<br /> `"jsonrpc": "1.0",`<br /> `"method": "rescanfinished",`<br /> `"params":`<br /> `[`<br /> `"0000000000000ea86b49e11843b2ad937ac89ae74a963c7edd36e0147079b89d",`<br /> `127213,`<br /> `1306533807`<br /> `],`<br /> `"id": null`<br />`}`| 958 [Return to Overview](#NotificationOverview)<br /> 959 960 961 <a name="ExampleCode" /> 962 ### 9. Example Code 963 964 This section provides example code for interacting with the JSON-RPC API in 965 various languages. 966 967 * [Go](#ExampleGoApp) 968 * [node.js](#ExampleNodeJsCode) 969 970 <a name="ExampleGoApp" /> 971 **9.1 Go** 972 973 This section provides examples of using the RPC interface using Go and the 974 [btcrpcclient](https://github.com/btcsuite/btcrpcclient) package. 975 976 * [Using getblockcount to Retrieve the Current Block Height](#ExampleGetBlockCount) 977 * [Using getblock to Retrieve the Genesis Block](#ExampleGetBlock) 978 * [Using notifyblocks to Receive blockconnected and blockdisconnected Notifications (Websocket-specific)](#ExampleNotifyBlocks) 979 980 981 <a name="ExampleGetBlockCount" /> 982 **9.1.1 Using getblockcount to Retrieve the Current Block Height**<br /> 983 984 The following is an example Go application which uses the 985 [btcrpcclient](https://github.com/btcsuite/btcrpcclient) package to connect with 986 a btcd instance via Websockets, issues [getblockcount](#getblockcount) to 987 retrieve the current block height, and displays it. 988 989 ```Go 990 package main 991 992 import ( 993 "github.com/btcsuite/btcrpcclient" 994 "github.com/dashpay/godashutil" 995 "io/ioutil" 996 "log" 997 "path/filepath" 998 ) 999 1000 func main() { 1001 // Load the certificate for the TLS connection which is automatically 1002 // generated by btcd when it starts the RPC server and doesn't already 1003 // have one. 1004 btcdHomeDir := godashutil.AppDataDir("btcd", false) 1005 certs, err := ioutil.ReadFile(filepath.Join(btcdHomeDir, "rpc.cert")) 1006 if err != nil { 1007 log.Fatal(err) 1008 } 1009 1010 // Create a new RPC client using websockets. Since this example is 1011 // not long-lived, the connection will be closed as soon as the program 1012 // exits. 1013 connCfg := &btcrpcclient.ConnConfig{ 1014 Host: "localhost:8334", 1015 Endpoint: "ws", 1016 User: "yourrpcuser", 1017 Pass: "yourrpcpass", 1018 Certificates: certs, 1019 } 1020 client, err := btcrpcclient.New(connCfg, nil) 1021 if err != nil { 1022 log.Fatal(err) 1023 } 1024 defer client.Shutdown() 1025 1026 // Query the RPC server for the current block count and display it. 1027 blockCount, err := client.GetBlockCount() 1028 if err != nil { 1029 log.Fatal(err) 1030 } 1031 log.Printf("Block count: %d", blockCount) 1032 } 1033 ``` 1034 1035 Which results in: 1036 1037 ```bash 1038 Block count: 276978 1039 ``` 1040 1041 <a name="ExampleGetBlock" /> 1042 **9.1.2 Using getblock to Retrieve the Genesis Block**<br /> 1043 1044 The following is an example Go application which uses the 1045 [btcrpcclient](https://github.com/btcsuite/btcrpcclient) package to connect with 1046 a btcd instance via Websockets, issues [getblock](#getblock) to retrieve 1047 information about the Genesis block, and display a few details about it. 1048 1049 ```Go 1050 package main 1051 1052 import ( 1053 "github.com/btcsuite/btcrpcclient" 1054 "github.com/dashpay/godashutil" 1055 "github.com/dashpay/godash/wire" 1056 "io/ioutil" 1057 "log" 1058 "path/filepath" 1059 "time" 1060 ) 1061 1062 func main() { 1063 // Load the certificate for the TLS connection which is automatically 1064 // generated by btcd when it starts the RPC server and doesn't already 1065 // have one. 1066 btcdHomeDir := godashutil.AppDataDir("btcd", false) 1067 certs, err := ioutil.ReadFile(filepath.Join(btcdHomeDir, "rpc.cert")) 1068 if err != nil { 1069 log.Fatal(err) 1070 } 1071 1072 // Create a new RPC client using websockets. Since this example is 1073 // not long-lived, the connection will be closed as soon as the program 1074 // exits. 1075 connCfg := &btcrpcclient.ConnConfig{ 1076 Host: "localhost:18334", 1077 Endpoint: "ws", 1078 User: "yourrpcuser", 1079 Pass: "yourrpcpass", 1080 Certificates: certs, 1081 } 1082 client, err := btcrpcclient.New(connCfg, nil) 1083 if err != nil { 1084 log.Fatal(err) 1085 } 1086 defer client.Shutdown() 1087 1088 // Query the RPC server for the genesis block using the "getblock" 1089 // command with the verbose flag set to true and the verboseTx flag 1090 // set to false. 1091 genesisHashStr := "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f" 1092 blockHash, err := wire.NewShaHashFromStr(genesisHashStr) 1093 if err != nil { 1094 log.Fatal(err) 1095 } 1096 block, err := client.GetBlockVerbose(blockHash, false) 1097 if err != nil { 1098 log.Fatal(err) 1099 } 1100 1101 // Display some details about the returned block. 1102 log.Printf("Hash: %v\n", block.Hash) 1103 log.Printf("Previous Block: %v\n", block.PreviousHash) 1104 log.Printf("Next Block: %v\n", block.NextHash) 1105 log.Printf("Merkle root: %v\n", block.MerkleRoot) 1106 log.Printf("Timestamp: %v\n", time.Unix(block.Time, 0).UTC()) 1107 log.Printf("Confirmations: %v\n", block.Confirmations) 1108 log.Printf("Difficulty: %f\n", block.Difficulty) 1109 log.Printf("Size (in bytes): %v\n", block.Size) 1110 log.Printf("Num transactions: %v\n", len(block.Tx)) 1111 } 1112 ``` 1113 1114 Which results in: 1115 1116 ```bash 1117 Hash: 000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f 1118 Previous Block: 0000000000000000000000000000000000000000000000000000000000000000 1119 Next Block: 00000000839a8e6886ab5951d76f411475428afc90947ee320161bbf18eb6048 1120 Merkle root: 4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b 1121 Timestamp: 2009-01-03 18:15:05 +0000 UTC 1122 Confirmations: 277290 1123 Difficulty: 1.000000 1124 Size (in bytes): 285 1125 Num transactions: 1 1126 ``` 1127 1128 <a name="ExampleNotifyBlocks" /> 1129 **9.1.3 Using notifyblocks to Receive blockconnected and blockdisconnected 1130 Notifications (Websocket-specific)**<br /> 1131 1132 The following is an example Go application which uses the 1133 [btcrpcclient](https://github.com/btcsuite/btcrpcclient) package to connect with 1134 a btcd instance via Websockets and registers for 1135 [blockconnected](#blockconnected) and [blockdisconnected](#blockdisconnected) 1136 notifications with [notifyblocks](#notifyblocks). It also sets up handlers for 1137 the notifications. 1138 1139 ```Go 1140 package main 1141 1142 import ( 1143 "github.com/btcsuite/btcrpcclient" 1144 "github.com/dashpay/godashutil" 1145 "github.com/dashpay/godash/wire" 1146 "io/ioutil" 1147 "log" 1148 "path/filepath" 1149 "time" 1150 ) 1151 1152 func main() { 1153 // Setup handlers for blockconnected and blockdisconnected 1154 // notifications. 1155 ntfnHandlers := btcrpcclient.NotificationHandlers{ 1156 OnBlockConnected: func(hash *wire.ShaHash, height int32) { 1157 log.Printf("Block connected: %v (%d)", hash, height) 1158 }, 1159 OnBlockDisconnected: func(hash *wire.ShaHash, height int32) { 1160 log.Printf("Block disconnected: %v", hash, height) 1161 }, 1162 } 1163 1164 // Load the certificate for the TLS connection which is automatically 1165 // generated by btcd when it starts the RPC server and doesn't already 1166 // have one. 1167 btcdHomeDir := godashutil.AppDataDir("btcd", false) 1168 certs, err := ioutil.ReadFile(filepath.Join(btcdHomeDir, "rpc.cert")) 1169 if err != nil { 1170 log.Fatal(err) 1171 } 1172 1173 // Create a new RPC client using websockets. 1174 connCfg := &btcrpcclient.ConnConfig{ 1175 Host: "localhost:8334", 1176 Endpoint: "ws", 1177 User: "yourrpcuser", 1178 Pass: "yourrpcpass", 1179 Certificates: certs, 1180 } 1181 client, err := btcrpcclient.New(connCfg, &ntfnHandlers) 1182 if err != nil { 1183 log.Fatal(err) 1184 } 1185 1186 // Register for blockconnected and blockdisconneted notifications. 1187 if err := client.NotifyBlocks(); err != nil { 1188 client.Shutdown() 1189 log.Fatal(err) 1190 } 1191 1192 // For this example, gracefully shutdown the client after 10 seconds. 1193 // Ordinarily when to shutdown the client is highly application 1194 // specific. 1195 log.Println("Client shutdown in 10 seconds...") 1196 time.AfterFunc(time.Second*10, func() { 1197 log.Println("Client shutting down...") 1198 client.Shutdown() 1199 log.Println("Client shutdown complete.") 1200 }) 1201 1202 // Wait until the client either shuts down gracefully (or the user 1203 // terminates the process with Ctrl+C). 1204 client.WaitForShutdown() 1205 } 1206 ``` 1207 1208 Example output: 1209 1210 ``` 1211 2014/05/12 20:33:17 Client shutdown in 10 seconds... 1212 2014/05/12 20:33:19 Block connected: 000000000000000007dff1f95f7b3f5eac2892a4123069517caf34e2c417650d (300461) 1213 2014/05/12 20:33:27 Client shutting down... 1214 2014/05/12 20:31:27 Client shutdown complete. 1215 ``` 1216 1217 <a name="ExampleNodeJsCode" /> 1218 ### 9.2. Example node.js Code 1219 1220 <a name="ExampleNotifyBlocks" /> 1221 **9.2.1 Using notifyblocks to be Notified of Block Connects and Disconnects**<br /> 1222 1223 The following is example node.js code which uses [ws](https://github.com/einaros/ws) 1224 (can be installed with `npm install ws`) to connect with a btcd instance, 1225 issues [notifyblocks](#notifyblocks) to register for 1226 [blockconnected](#blockconnected) and [blockdisconnected](#blockdisconnected) 1227 notifications, and displays all incoming messages. 1228 1229 ```javascript 1230 var fs = require('fs'); 1231 var WebSocket = require('ws'); 1232 1233 // Load the certificate for the TLS connection which is automatically 1234 // generated by btcd when it starts the RPC server and doesn't already 1235 // have one. 1236 var cert = fs.readFileSync('/path/to/btcd/appdata/rpc.cert'); 1237 var user = "yourusername"; 1238 var password = "yourpassword"; 1239 1240 1241 // Initiate the websocket connection. The btcd generated certificate acts as 1242 // its own certificate authority, so it needs to be specified in the 'ca' array 1243 // for the certificate to properly validate. 1244 var ws = new WebSocket('wss://127.0.0.1:8334/ws', { 1245 headers: { 1246 'Authorization': 'Basic '+new Buffer(user+':'+password).toString('base64') 1247 }, 1248 cert: cert, 1249 ca: [cert] 1250 }); 1251 ws.on('open', function() { 1252 console.log('CONNECTED'); 1253 // Send a JSON-RPC command to be notified when blocks are connected and 1254 // disconnected from the chain. 1255 ws.send('{"jsonrpc":"1.0","id":"0","method":"notifyblocks","params":[]}'); 1256 }); 1257 ws.on('message', function(data, flags) { 1258 console.log(data); 1259 }); 1260 ws.on('error', function(derp) { 1261 console.log('ERROR:' + derp); 1262 }) 1263 ws.on('close', function(data) { 1264 console.log('DISCONNECTED'); 1265 }) 1266 ```