<p>The second parameter of the RPC call is a boolean for decoding the results or not.</p>

<p>Setting this to False will return the hex encoded block. </p>

<pre><code>hash = "00000000839a8e6886ab5951d76f411475428afc90947ee320161bbf18eb6048"
print rpc_connection.getblock(hash, False)
</code></pre>

CC BY-SA 3.0
2015-07-08T14:43:38.930Z
2015-07-08T15:02:53.100Z
2015-07-08T15:02:53.100Z
Claris
<p>how can i get the hex output in bitcoin-rpc for blocks? i'm using <a href="https://github.com/jgarzik/python-bitcoinrpc" rel="nofollow">python-bitcoinrpc</a>.</p>

<p>in <code>bitcoin-cli</code> i can go:</p>

<pre><code>$ bitcoin-cli getblock 00000000839a8e6886ab5951d76f411475428afc90947ee320161bbf18eb6048 false
010000006fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000982051fd1e4ba744bbbe680e1fee14677ba1a3c3540bf7b1cdb606e857233e0e61bc6649ffff001d01e362990101000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0704ffff001d0104ffffffff0100f2052a0100000043410496b538e853519c726a2c91e61ec11600ae1390813a627c66fb8be7947be63c52da7589379515d4e0a604f8141781e62294721166bf621e73a82cbf2342c858eeac00000000
</code></pre>

<p>but trying the same thing in bitcoinrpc gives a json output:</p>

<pre><code>print rpc_connection.getblock("00000000839a8e6886ab5951d76f411475428afc90947ee320161bbf18eb6048 false")
{u'merkleroot': u'0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098', u'nonce': 2573394689, u'previousblockhash': u'000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f', u'hash': u'00000000839a8e6886ab5951d76f411475428afc90947ee320161bbf18eb6048', u'version': 1, u'tx': [u'0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098'], u'chainwork': u'0000000000000000000000000000000000000000000000000000000200020002', u'height': 1, u'difficulty': Decimal('1.00000000'), u'nextblockhash': u'000000006a625f06636b8bb6ac7b960a8d03705d1ace08b1a19da3fdcc99ddbd', u'confirmations': 364412, u'time': 1231469665, u'bits': u'1d00ffff', u'size': 215}
</code></pre>

<p><code>getrawtransaction</code> just works naturally this way:</p>

<pre><code>$ print rpc_connection.getrawtransaction("0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098")
01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0704ffff001d0104ffffffff0100f2052a0100000043410496b538e853519c726a2c91e61ec11600ae1390813a627c66fb8be7947be63c52da7589379515d4e0a604f8141781e62294721166bf621e73a82cbf2342c858eeac00000000
</code></pre>

<p>there seems to be some json on/off flag that is not well documented...</p>

<json-rpc>
rpc get hex not json
mulllhausen
# rpc get hex not json

(Asked by: username_0 on 2015-07-08)

how can i get the hex output in bitcoin-rpc for blocks? i'm using [python-bitcoinrpc](https://github.com/jgarzik/python-bitcoinrpc).

in `bitcoin-cli` i can go:

```
$ bitcoin-cli getblock 00000000839a8e6886ab5951d76f411475428afc90947ee320161bbf18eb6048 false
010000006fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000982051fd1e4ba744bbbe680e1fee14677ba1a3c3540bf7b1cdb606e857233e0e61bc6649ffff001d01e362990101000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0704ffff001d0104ffffffff0100f2052a0100000043410496b538e853519c726a2c91e61ec11600ae1390813a627c66fb8be7947be63c52da7589379515d4e0a604f8141781e62294721166bf621e73a82cbf2342c858eeac00000000

```

but trying the same thing in bitcoinrpc gives a json output:

```
print rpc_connection.getblock("00000000839a8e6886ab5951d76f411475428afc90947ee320161bbf18eb6048 false")
{u'merkleroot': u'0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098', u'nonce': 2573394689, u'previousblockhash': u'000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f', u'hash': u'00000000839a8e6886ab5951d76f411475428afc90947ee320161bbf18eb6048', u'version': 1, u'tx': [u'0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098'], u'chainwork': u'0000000000000000000000000000000000000000000000000000000200020002', u'height': 1, u'difficulty': Decimal('1.00000000'), u'nextblockhash': u'000000006a625f06636b8bb6ac7b960a8d03705d1ace08b1a19da3fdcc99ddbd', u'confirmations': 364412, u'time': 1231469665, u'bits': u'1d00ffff', u'size': 215}

```

`getrawtransaction` just works naturally this way:

```
$ print rpc_connection.getrawtransaction("0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098")
01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0704ffff001d0104ffffffff0100f2052a0100000043410496b538e853519c726a2c91e61ec11600ae1390813a627c66fb8be7947be63c52da7589379515d4e0a604f8141781e62294721166bf621e73a82cbf2342c858eeac00000000

```

there seems to be some json on/off flag that is not well documented...

**Tags:** json-rpc


---

## 1 answers

### Answer by username_1 on 2015-07-08. Score: 2 | Accepted answer

The second parameter of the RPC call is a boolean for decoding the results or not.

Setting this to False will return the hex encoded block.

```
hash = "00000000839a8e6886ab5951d76f411475428afc90947ee320161bbf18eb6048"
print rpc_connection.getblock(hash, False)

```


---

