dash-docs/en/slate-example/includes/getblock
2018-06-20 11:11:28 -04:00

215 lines
9.4 KiB
Text

<h2 id='getblock'>GetBlock</h2>
<p>The <code>getblock</code> RPC gets a block with a particular header hash from the local block database either as a JSON object or as a serialized block.</p>
<blockquote>
<p>Get a block in raw hex:</p>
</blockquote>
<pre class="highlight plaintext"><code>dash-cli -testnet getblock \
0000000037955fcc39af8b1ae75914ffb422313c0fca7eba96a1ac99c2e57f84 \
false
0100002011f5719a0a0c4881ff98b4a68c1c828dc3b10f5b51033f5f93d48dbf\
000000004b8e38f197d6ee878e160d2bae3ce05ab898a6252458ec67ce770140\
260397c4dd2ed659a1dd001d00636b5601010000000100000000000000000000\
00000000000000000000000000000000000000000000ffffffff4b02041204dd\
2ed65908fabe6d6d7445746d63506b62572d2d35584853467a765a6748696972\
30657a3a6f6d656e010000000000000017fffff9020000000d2f6e6f64655374\
726174756d2f00000000058028bb13010000001976a914bad55652dffb1af943\
41015c94feea79793442fd88ac40e553b1020000001976a9142b7856de53d4c1\
823090c98f8ad79862842c09b588ac4094dd89000000001976a914c2c29ebc78\
7954ef99d01c5f79115abf7012fb8e88ac4094dd89000000001976a914d7b47d\
4b40a23c389f5a17754d7f60f511c7d0ec88ac4094dd89000000001976a914dc\
3e0793134b081145ec0c67a9c72a7b297df27c88ac00000000
</code></pre>
<p><em>Parameter #1---header hash</em></p>
<table><thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Required</th>
<th>Description</th>
</tr>
</thead><tbody>
<tr>
<td>Header Hash</td>
<td>string (hex)</td>
<td>Required<br>(exactly 1)</td>
<td>The hash of the header of the block to get, encoded as hex in RPC byte order</td>
</tr>
</tbody></table>
<p><em>Parameter #2---whether to get JSON or hex output</em></p>
<table><thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Required</th>
<th>Description</th>
</tr>
</thead><tbody>
<tr>
<td>Format</td>
<td>boolean</td>
<td>Optional<br>(true or false)</td>
<td>Set to <code>false</code> to get the block in serialized block format; set to <code>true</code> (the default) to get the decoded block as a JSON object</td>
</tr>
</tbody></table>
<p><em>Result (if format was <code>false</code>)---a serialized block</em></p>
<table><thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Required</th>
<th>Description</th>
</tr>
</thead><tbody>
<tr>
<td><code>result</code></td>
<td>string (hex)/null</td>
<td>Required<br>(exactly 1</td>
<td>&quot;The requested block as a serialized block, encoded as hex, or JSON <code>null</code> if an error occurred</td>
</tr>
</tbody></table>
<blockquote>
<p>Get the same block in JSON:</p>
</blockquote>
<pre class="highlight plaintext"><code>dash-cli -testnet getblock \
0000000037955fcc39af8b1ae75914ffb422313c0fca7eba96a1ac99c2e57f84
</code></pre><pre class="highlight json tab-json"><code><span class="p">{</span><span class="w">
</span><span class="s2">"hash"</span><span class="p">:</span><span class="w"> </span><span class="s2">"0000000037955fcc39af8b1ae75914ffb422313c0fca7eba96a1ac99c2e57f84"</span><span class="p">,</span><span class="w">
</span><span class="s2">"confirmations"</span><span class="p">:</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w">
</span><span class="s2">"size"</span><span class="p">:</span><span class="w"> </span><span class="mi">377</span><span class="p">,</span><span class="w">
</span><span class="s2">"height"</span><span class="p">:</span><span class="w"> </span><span class="mi">4612</span><span class="p">,</span><span class="w">
</span><span class="s2">"version"</span><span class="p">:</span><span class="w"> </span><span class="mi">536870913</span><span class="p">,</span><span class="w">
</span><span class="s2">"merkleroot"</span><span class="p">:</span><span class="w"> </span><span class="s2">"c4970326400177ce67ec582425a698b85ae03cae2b0d168e87eed697f1388e4b"</span><span class="p">,</span><span class="w">
</span><span class="s2">"tx"</span><span class="p">:</span><span class="w"> </span><span class="p">[</span><span class="w">
</span><span class="s2">"c4970326400177ce67ec582425a698b85ae03cae2b0d168e87eed697f1388e4b"</span><span class="w">
</span><span class="p">],</span><span class="w">
</span><span class="s2">"time"</span><span class="p">:</span><span class="w"> </span><span class="mi">1507208925</span><span class="p">,</span><span class="w">
</span><span class="s2">"mediantime"</span><span class="p">:</span><span class="w"> </span><span class="mi">1507208645</span><span class="p">,</span><span class="w">
</span><span class="s2">"nonce"</span><span class="p">:</span><span class="w"> </span><span class="mi">1449878272</span><span class="p">,</span><span class="w">
</span><span class="s2">"bits"</span><span class="p">:</span><span class="w"> </span><span class="s2">"1d00dda1"</span><span class="p">,</span><span class="w">
</span><span class="s2">"difficulty"</span><span class="p">:</span><span class="w"> </span><span class="mf">1.155066358813473</span><span class="p">,</span><span class="w">
</span><span class="s2">"chainwork"</span><span class="p">:</span><span class="w"> </span><span class="s2">"000000000000000000000000000000000000000000000000000001c3e86f0f04"</span><span class="p">,</span><span class="w">
</span><span class="s2">"previousblockhash"</span><span class="p">:</span><span class="w"> </span><span class="s2">"00000000bf8dd4935f3f03515b0fb1c38d821c8ca6b498ff81480c0a9a71f511"</span><span class="p">,</span><span class="w">
</span><span class="s2">"nextblockhash"</span><span class="p">:</span><span class="w"> </span><span class="s2">"0000000028817c7fce55d802f3647640600535a983d00e16076f284ec6cb001b"</span><span class="w">
</span><span class="p">}</span><span class="w">
</span></code></pre>
<p><em>Result (if format was <code>true</code> or omitted)---a JSON block</em></p>
<table><thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Required</th>
<th>Description</th>
</tr>
</thead><tbody>
<tr>
<td><code>result</code></td>
<td>object/null</td>
<td>Required<br>(exactly 1)</td>
<td>An object containing the requested block, or JSON <code>null</code> if an error occurred</td>
</tr>
<tr>
<td>→<br><code>hash</code></td>
<td>string (hex)</td>
<td>Required<br>(exactly 1)</td>
<td>The hash of this block&#39;s block header encoded as hex in RPC byte order. This is the same as the hash provided in parameter #1</td>
</tr>
<tr>
<td>→<br><code>confirmations</code></td>
<td>number (int)</td>
<td>Required<br>(exactly 1)</td>
<td>The number of confirmations the transactions in this block have, starting at 1 when this block is at the tip of the best block chain. This score will be -1 if the the block is not part of the best block chain&quot;</td>
</tr>
<tr>
<td>→<br><code>size</code></td>
<td>number (int)</td>
<td>Required<br>(exactly 1)</td>
<td>The size of this block in serialized block format, counted in bytes&quot;</td>
</tr>
<tr>
<td>→<br><code>height</code></td>
<td>number (int)</td>
<td>Required<br>(exactly 1)</td>
<td>The height of this block on its block chain&quot;</td>
</tr>
<tr>
<td>→<br><code>version</code></td>
<td>number (int)</td>
<td>Required<br>(exactly 1)</td>
<td>This block&#39;s version number. See [block version numbers][section block versions]&quot;</td>
</tr>
<tr>
<td>→<br><code>merkleroot</code></td>
<td>string (hex)</td>
<td>Required<br>(exactly 1)</td>
<td>The merkle root for this block, encoded as hex in RPC byte order&quot;</td>
</tr>
<tr>
<td>→<br><code>tx</code></td>
<td>array</td>
<td>Required<br>(exactly 1)</td>
<td>An array containing the TXIDs of all transactions in this block. The transactions appear in the array in the same order they appear in the serialized block&quot;</td>
</tr>
<tr>
<td>→ →<br>TXID</td>
<td>string (hex)</td>
<td>Required<br>(1 or more)</td>
<td>The TXID of a transaction in this block, encoded as hex in RPC byte order&quot;</td>
</tr>
<tr>
<td>→<br><code>time</code></td>
<td>number (int)</td>
<td>Required<br>(exactly 1)</td>
<td>The value of the <em>time</em> field in the block header, indicating approximately when the block was created&quot;</td>
</tr>
<tr>
<td>→<br><code>mediantime</code></td>
<td>number (int)</td>
<td>Required<br>(exactly 1)</td>
<td><em>Added in Bitcoin Core 0.12.0</em><br><br>The median block time in Unix epoch time&quot;</td>
</tr>
<tr>
<td>→<br><code>nonce</code></td>
<td>number (int)</td>
<td>Required<br>(exactly 1)</td>
<td>The nonce which was successful at turning this particular block into one that could be added to the best block chain&quot;</td>
</tr>
<tr>
<td>→<br><code>bits</code></td>
<td>string (hex)</td>
<td>Required<br>(exactly 1)</td>
<td>The value of the <em>nBits</em> field in the block header, indicating the target threshold this block&#39;s header had to pass&quot;</td>
</tr>
<tr>
<td>→<br><code>difficulty</code></td>
<td>number (real)</td>
<td>Required<br>(exactly 1)</td>
<td>The estimated amount of work done to find this block relative to the estimated amount of work done to find block 0&quot;</td>
</tr>
<tr>
<td>→<br><code>chainwork</code></td>
<td>string (hex)</td>
<td>Required<br>(exactly 1)</td>
<td>The estimated number of block header hashes miners had to check from the genesis block to this block, encoded as big-endian hex&quot;</td>
</tr>
<tr>
<td>→<br><code>previousblockhash</code></td>
<td>string (hex)</td>
<td>Optional<br>(0 or 1)</td>
<td>The hash of the header of the previous block, encoded as hex in RPC byte order. Not returned for genesis block&quot;</td>
</tr>
<tr>
<td>→<br><code>nextblockhash</code></td>
<td>string (hex)</td>
<td>Optional<br>(0 or 1)</td>
<td>The hash of the next block on the best block chain, if known, encoded as hex in RPC byte order&quot;</td>
</tr>
</tbody></table>