8

Bitcoin implements both a peer-to-peer synchronization protocol (normally on port 8333) and a JSON-RPC API (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:

3 Answers 3

6

What are these designed to accomplish?

  • The peer-to-peer 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 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 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 (Java/Javascript). Not as complete, 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 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

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.

2

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.

Your Answer

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

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