I am trying to create an inventory message of specific hashes that I select. Assuming I have all the hashes stored in a vector, how do I create the message 'manually'? (i.e stuff like getting total length, generating checksum and adding in all the inventory vector elements to the message and then sending it to all my peers.)

Any help is appreciated, if you can point me at any Bitcoin core (v0.14 or v0.15) source code that handles this kind of stuff that is also welcome.

1 Answer 1


You can use Peter Todd's python-bitcoinlib, which contains builders for all the network messages.

Simple example, given a list of hashes:

from bitcoin.net import *
from bitcoin.messages import *

m = msg_inv()
for h in hashes:
    assert len(h) == 32
    inv = CInv()
    inv.type = 1  # TX
    inv.hash = h

inv_msg = m.serialize()

This assumes that the list of hashes you have are little endian unhexlified strings.

  • Thank you for this, its a good starting point for what I aim to do. Do you have any suggestions for how to do this on a source code level in Bitcoin core?
    – Nabeel
    Oct 21, 2017 at 23:14
  • Not really, sorry. There's a few Core devs on this SE, they may be able to help you though.
    – sr_gi
    Oct 21, 2017 at 23:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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