I'm currently doing RPC calls to bitcoin-cli within python to get raw block data:

bitcoin-cli getblock BLOCKHASH False

I've already written a function that cuts off the block header and splits the transaction block into individual transactions, resulting in the same result as:

bitcoin-cli getrawblock TXID

I'm now trying to convert this data into the same result as

bitcoin-cli getrawblock TXID 1

without doing another RPC call to bitcoind. Would prefer to use pre-existing modules if possible.

Python packages would be appreciated.


Yes, Pybitcointools (or this fork which has BIP39, file embedding and mk_opreturn) can do this.

Install either version of pybitcointools using setup.py install, as usual.

Then, with a raw hex transaction, rawtx, simply use txo = deserialize(rawtx). rawtx can be either a signed or unsigned hex transaction. The returned txo is deserialized as a dict object. Use serialize(txo) to get back to rawtx.

You can fetch TxIDs using fetchtx(hex_txid, source="blockr") and send signed Txs with pushtx(signed_hex_tx, source="bci").

  • Does Pybitcointools send an RPC call to bitcoind to deserialize raw transactions or does it do the conversion within the module? – SLee Jul 13 '15 at 0:48
  • 1
    @SLee From the module: no RPC required – Wizard Of Ozzie Jul 13 '15 at 2:47

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.