<blockquote>
<p><strong>in clear text or in another format?  How is it for bitcoin protocol?</strong></p>
</blockquote>
<p>In binary. With numbers mostly in little-endian byte-order. Over TCP with a conventional target port number.</p>
<p>The details are at <a href="https://en.bitcoin.it/wiki/Protocol_documentation" rel="nofollow noreferrer">https://en.bitcoin.it/wiki/Protocol_documentation</a></p>
<p>For example:</p>
<blockquote>
<h2>Message structure</h2>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>Field Size</th>
<th>Description</th>
<th>Data type</th>
<th>Comments</th>
</tr>
</thead>
<tbody>
<tr>
<td>4</td>
<td>magic</td>
<td>uint32_t</td>
<td>Magic value indicating message origin network, and used to seek to next message when stream state is unknown</td>
</tr>
<tr>
<td>12</td>
<td>command</td>
<td>char[12]</td>
<td>ASCII string identifying the packet content, NULL padded (non-NULL padding results in packet rejected)</td>
</tr>
<tr>
<td>4</td>
<td>length</td>
<td>uint32_t</td>
<td>Length of payload in number of bytes</td>
</tr>
<tr>
<td>4</td>
<td>checksum</td>
<td>uint32_t</td>
<td>First 4 bytes of sha256(sha256(payload))</td>
</tr>
<tr>
<td>?</td>
<td>payload</td>
<td>uchar[]</td>
<td>The actual data</td>
</tr>
</tbody>
</table>
</div></blockquote>
<p>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.</p>
<p>You might also want to consider the <a href="https://en.wikipedia.org/wiki/Gossip_protocol" rel="nofollow noreferrer">Gossip protocol</a></p>

CC BY-SA 4.0
2022-04-07T11:15:52.303Z
Thank you ! What are the benefits of using binary instead of json/text ?
Lukkyz
CC BY-SA 4.0
2022-04-07T11:44:39.500Z
Compactness of data on the wire
RedGrittyBrick
CC BY-SA 4.0
2022-04-07T08:41:45.793Z
2022-04-07T10:16:28.390Z
2022-04-07T10:16:28.390Z
RedGrittyBrick
<p>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 ?</p>

<protocol>
In which format bitcoin protocol send message?
Lukkyz
# In which format bitcoin protocol send message?

(Asked by: username_0 on 2022-04-06)

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 ?

**Tags:** protocol


---

## 1 answers

### Answer by username_1 on 2022-04-07. Score: 0 | Accepted answer

> **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](https://en.wikipedia.org/wiki/Gossip_protocol)

> **Comments:**
> **username_0**: Thank you ! What are the benefits of using binary instead of json/text ?  
> **username_1**: Compactness of data on the wire  

---

