2

how can i get the hex output in bitcoin-rpc for blocks? i'm using 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...

2

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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.