Photo by NASA on Unsplash

Building a Blockchain: Introduction

One of my personal project involves writing a blockchain, in Java, using TDD (Test-Driven Development). The project is blockchainj. To me, a blockchain is a “case from the book” for TDD: I can implement the different pieces incrementally, guided by use cases, and enforcing simplicity. I’m really enjoying writing code for this project.

Unless you were trapped in a closet during the last ten years, you must know what is a blockchain: simply, a chain of blocks, managed by a distributed network of nodes. Bitcoin is the most known implementation, but there are many others, like Ethereum, EOS, IOTA, Hyperledger, Quorum, and dozens more.

Some use cases I’m implementing in my project:

  • Node sending message to other nodes
  • Node discovering other nodes
  • Receiving a new block
  • Receiving a new transaction
  • Building (mining) a new block with transactions
  • Deploy and invoke smart contracts, and querying their states

To support smart contracts, I planned to have more than one virtual machine, but the first one to be used is an Ethereum-like one. In this way, I could use the already existing Ethereum smart contracts, mainly written in Solidity programming languages (see my Solidity samples repo).

In order to leverage Ethereum ecosystem, I started to support JSON RPC interface so a node could be invoked from external applications, like dapps (decentralized applications) and wallets.

Another use cases to consider/implement:

  • Long synchronization of a node with the rest of the network
  • Fast synchronization of a node
  • Light node
  • Peer to peer protocol
  • Discovery protocol using a distributed hash table a la kademlia
  • Node protocol (send block, send transaction, query block, etc)
  • Other protocols (ie a swarm-like protocol for distributed storage)
  • Offline payment channels and smart contracts

I hope this post be the first one in a series about this project. I want discuss the design decisions, incremental implementation and emergent design.

TDD rocks!

Angel “Java” Lopez

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store