<p>The Peer to Peer protocol (using <code>version</code>, <code>verack</code>, <code>getdata</code>, ... etc. messages) is used by all clients communicating on the network. This protocol is how data is spread through the network. This is done directly over TCP/IP. Messages have their own format (not JSON) and allow the spread of transactions and blocks through the network. Read more at: <a href="https://bitcoin.org/en/developer-reference#protocol-versions" rel="nofollow">https://bitcoin.org/en/developer-reference#protocol-versions</a>. </p>

<p>After a Bitcoin Core full node has received the block and transaction data via this P2P protocol, then a user can use the RPC interface to query the node about the data it has received. The JSON-RPC interface used is specific to Bitcoin Core, although other clients may introduce similar interfaces for ease of use. Nodes do not typically communicate with each other using the RPC interface at all, the RPC calls are more like tools that Bitcoin Core provides for developers to give them access to the blockchain data. </p>

CC BY-SA 3.0
2015-02-20T05:36:26.333Z
2015-02-20T05:36:26.333Z
morsecoder
<p>The P2P protocol is how Bitcoin nodes talk to eachother. All Bitcoin software implements (part of) this protocol.</p>

<p>The RPC protocol is how you communicate with Bitcoin Core's bitcoind. Other Bitcoin software may have other ways of operating it.</p>

CC BY-SA 3.0
2015-02-27T10:06:35.237Z
2015-02-27T10:06:35.237Z
Pieter Wuille
<blockquote>
  <p>What are these designed to accomplish?</p>
</blockquote>

<ul>
<li><p>The <a href="https://bitcoin.org/en/developer-guide#p2p-network" rel="noreferrer">peer-to-peer network</a> is designed primarily to communicate blocks and transactions between full nodes.  It has also been extended over time to allow SPV clients to request filtered data, as well as to communicate alerts for full nodes[1] and to distribute address information for full nodes that accept incoming connections.</p></li>
<li><p>The <a href="https://bitcoin.org/en/developer-reference#remote-procedure-calls-rpcs" rel="noreferrer">RPC interface</a> is designed to allow users to operate Bitcoin Core, either manually or programatically.  About half of its calls are related to Bitcoin Core's optional built-in wallet, with the other half being split among control functions, data retrieval functions, and utility functions.  A new <a href="https://bitcoin.org/en/developer-reference#http-rest" rel="noreferrer">HTTP REST interface</a> also provides some data retrieval functions.</p></li>
</ul>

<p>[1] Only Bitcoin Core uses this feature currently, although it's possible for the network to handle alerts propagated by other software.</p>

<blockquote>
  <p>If I'm trying to implement a wallet that doesn't need bitcoind to be installed to work, which one should I use?</p>
</blockquote>

<p>All wallets need Bitcoin Core to be installed somewhere, but it's possible to write a wallet that communicates with other people's Bitcoin Core instances using the peer-to-peer protocol.</p>

<blockquote>
  <p>What existing libraries implement the low-level details of these protocols?</p>
</blockquote>

<ul>
<li><p>The most popular library for interfacing with the peer-to-peer network is <a href="http://bitcoinj.github.io/" rel="noreferrer">BitcoinJ</a> (Java/Javascript).  Not as complete, <a href="https://github.com/petertodd/python-bitcoinlib" rel="noreferrer">python-bitcoinlib</a> provides code that is often line-for-line identical to Bitcoin Core (accounting for differences between C++/Python).  Other libraries exist, but most focus on interacting with the protocol as a client and do not fully implement the server-side.</p></li>
<li><p>For the RPC-JSON interface, some libraries such as <a href="https://github.com/darioteixeira/ocaml-bitcoin" rel="noreferrer">ocaml Bitcoin</a> provide an extensive wrapper around the native RPC-JSON interface, adding typing and other features.  However, all that is required to interface with Bitcoin Core's RPC-JSON interface is a library that handles HTTP sockets and a library that processes JSON.  (But, if you implement this yourself, please read the <a href="https://en.bitcoin.it/wiki/Proper_Money_Handling_%28JSON-RPC%29" rel="noreferrer">proper money handling wiki page</a></p></li>
</ul>

CC BY-SA 3.0
2015-02-27T10:07:32.593Z
2015-02-27T16:54:27.420Z
2015-02-27T16:54:27.420Z
David A. Harding
<p>Bitcoin implements both a <a href="https://en.bitcoin.it/wiki/Protocol_documentation" rel="noreferrer">peer-to-peer synchronization protocol</a> (normally on port 8333) and a <a href="https://en.bitcoin.it/wiki/API_reference_%28JSON-RPC%29" rel="noreferrer">JSON-RPC API</a> (normally on port 8332).</p>

<ul>
<li>What are these designed to accomplish?</li>
<li>If I'm trying to implement a wallet that doesn't need bitcoind to be installed to work, which one should I use?</li>
<li>What existing libraries implement the low-level details of these protocols?</li>
</ul>

<p>Related:</p>

<ul>
<li><a href="https://bitcoin.stackexchange.com/questions/5757/what-is-the-difference-between-the-rpc-port-8332-and-port-8333">What is the difference between the rpc port 8332 and port 8333?</a></li>
</ul>

<json-rpc>
What's the difference between the Bitcoin's peer to peer protocol and the RPC API?
Nick ODell
# What's the difference between the Bitcoin's peer to peer protocol and the RPC API?

(Asked by: username_0 on 2015-02-18)

Bitcoin implements both a [peer-to-peer synchronization protocol](https://en.bitcoin.it/wiki/Protocol_documentation) (normally on port 8333) and a [JSON-RPC API](https://en.bitcoin.it/wiki/API_reference_%28JSON-RPC%29) (normally on port 8332).

* What are these designed to accomplish?
* If I'm trying to implement a wallet that doesn't need bitcoind to be installed to work, which one should I use?
* What existing libraries implement the low-level details of these protocols?

Related:

* [What is the difference between the rpc port 8332 and port 8333?](https://bitcoin.stackexchange.com/questions/5757/what-is-the-difference-between-the-rpc-port-8332-and-port-8333)

**Tags:** json-rpc


---

## 3 answers

### Answer by username_3 on 2015-02-27. Score: 6 | Accepted answer

> What are these designed to accomplish?

* The [peer-to-peer network](https://bitcoin.org/en/developer-guide#p2p-network) is designed primarily to communicate blocks and transactions between full nodes. It has also been extended over time to allow SPV clients to request filtered data, as well as to communicate alerts for full nodes[1] and to distribute address information for full nodes that accept incoming connections.
* The [RPC interface](https://bitcoin.org/en/developer-reference#remote-procedure-calls-rpcs) is designed to allow users to operate Bitcoin Core, either manually or programatically. About half of its calls are related to Bitcoin Core's optional built-in wallet, with the other half being split among control functions, data retrieval functions, and utility functions. A new [HTTP REST interface](https://bitcoin.org/en/developer-reference#http-rest) also provides some data retrieval functions.

[1] Only Bitcoin Core uses this feature currently, although it's possible for the network to handle alerts propagated by other software.

> If I'm trying to implement a wallet that doesn't need bitcoind to be installed to work, which one should I use?

All wallets need Bitcoin Core to be installed somewhere, but it's possible to write a wallet that communicates with other people's Bitcoin Core instances using the peer-to-peer protocol.

> What existing libraries implement the low-level details of these protocols?

* The most popular library for interfacing with the peer-to-peer network is [BitcoinJ](http://bitcoinj.github.io/) (Java/Javascript). Not as complete, [python-bitcoinlib](https://github.com/petertodd/python-bitcoinlib) provides code that is often line-for-line identical to Bitcoin Core (accounting for differences between C++/Python). Other libraries exist, but most focus on interacting with the protocol as a client and do not fully implement the server-side.
* For the RPC-JSON interface, some libraries such as [ocaml Bitcoin](https://github.com/darioteixeira/ocaml-bitcoin) provide an extensive wrapper around the native RPC-JSON interface, adding typing and other features. However, all that is required to interface with Bitcoin Core's RPC-JSON interface is a library that handles HTTP sockets and a library that processes JSON. (But, if you implement this yourself, please read the [proper money handling wiki page](https://en.bitcoin.it/wiki/Proper_Money_Handling_%28JSON-RPC%29)


---

### Answer by username_1 on 2015-02-20. Score: 4

The Peer to Peer protocol (using `version`, `verack`, `getdata`, ... etc. messages) is used by all clients communicating on the network. This protocol is how data is spread through the network. This is done directly over TCP/IP. Messages have their own format (not JSON) and allow the spread of transactions and blocks through the network. Read more at: <https://bitcoin.org/en/developer-reference#protocol-versions>.

After a Bitcoin Core full node has received the block and transaction data via this P2P protocol, then a user can use the RPC interface to query the node about the data it has received. The JSON-RPC interface used is specific to Bitcoin Core, although other clients may introduce similar interfaces for ease of use. Nodes do not typically communicate with each other using the RPC interface at all, the RPC calls are more like tools that Bitcoin Core provides for developers to give them access to the blockchain data.


---

### Answer by username_2 on 2015-02-27. Score: 3

The P2P protocol is how Bitcoin nodes talk to eachother. All Bitcoin software implements (part of) this protocol.

The RPC protocol is how you communicate with Bitcoin Core's bitcoind. Other Bitcoin software may have other ways of operating it.


---

