I'm writing a small p2p network and I don't know if I have to transmit message (between nodes) in clear text or in another format ? How is it for bitcoin protocol ?

1 Answer 1


in clear text or in another format? How is it for bitcoin protocol?

In binary. With numbers mostly in little-endian byte-order. Over TCP with a conventional target port number.

The details are at https://en.bitcoin.it/wiki/Protocol_documentation

For example:

Message structure

Field Size Description Data type Comments
4 magic uint32_t Magic value indicating message origin network, and used to seek to next message when stream state is unknown
12 command char[12] ASCII string identifying the packet content, NULL padded (non-NULL padding results in packet rejected)
4 length uint32_t Length of payload in number of bytes
4 checksum uint32_t First 4 bytes of sha256(sha256(payload))
? payload uchar[] The actual data

Unless message size and volume is important, I would instead use JSON in UTF8 for any protocol I create. You should make your own evaluation.

You might also want to consider the Gossip protocol

  • Thank you ! What are the benefits of using binary instead of json/text ?
    – Lukkyz
    Apr 7, 2022 at 11:15
  • Compactness of data on the wire Apr 7, 2022 at 11:44

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.