This post will give you a basic introduction to the bitcoin protocol by guiding you through how to create a simple, real-time visualization of transactions in the bitcoin network.
Bitcoin is easy to understand on the surface, but very complex when you get into the details. The explanations in this guide are simplified to make the content accessible to people unfamiliar with bitcoins. In-depth documentation can be found at https://bitcoin.org.
Overview of the bitcoin network
Bitcoin is a public P2P payment network and ledger enabling people or machines to securely transfer value over the Internet without trusting a third party. The tokens used for this value exchange are called bitcoins (lowercase “b”). A bitcoin is divisible to eight decimal places. Currently one bitcoin has a market value of about $350.
Bitcoins “sit” at a bitcoin address, just like money “sits” in a bank account. A bitcoin address is a public identifier like a bank account number. In order to send bitcoins from one address to another you must prove ownership of the sending address by signing a transaction with the private key of the sending address. This private key is like the PIN or password to your bank account. Every bitcoin address has a unique corresponding private key.
The amount of bitcoins in each of the existing addresses is stored in a public ledger called the blockchain. The blockchain holds the history of all valid/accepted transactions sent through the bitcoin network. These transactions are what we will be visualizing.
To create a live visualization of the network we must connect to a bitcoin node or set of nodes. Nodes are servers in the bitcoin network responsible for propagating and relaying transactions. It’s important to note that not all transactions sent into the bitcoin network are valid, and most nodes will not relay an invalid transaction. Therefore, although a single node will eventually see any transaction accepted by the network, it will not see many of the spam or malicious transactions because most other nodes will not propagate them.
There are some very well connected nodes (super nodes) or clusters of nodes that can provide a more comprehensive view of the live state of the network. [Blockchain.info](https://blockchain.info) operates a super node and allows developers free access to its data through both REST and WebSockets APIs. We will be using their WebSockets API for this project.
Let’s get coding. You can see the finished project code here: https://github.com/leishman/btc_network_visualizer.
First we will create a basic index.html file with jQuery and our main.js file required.
The only HTML element we need is a