Backend

Building Ethereum with Javascript: Part 1

When it comes to developing for the blockchain, and especially for Ethereum, anyone who knows much about the core infrastructure of Ethereum knows that the flagship client, geth or go-ethereum is written in Golang. There are other clients built in C#, Rust, and Java. But what most everyone knows about Ethereum is that you don't really build core infrastructure on Javascript, or do you?

Backend development, blockchain style.

When people say "back-end dev" these days, I often think of a NodeJS express app sitting on a server somewhere that ships data to a React client sitting on someone's browser. But, when it comes to blockchain apps, "backend" generally means the blockchain itself. So, can we do backend development for the blockchain in Javascript? Sure. Enter EthereumJS.

Blockchain primitives, as viewed from Javascript

The EthereumJS monorepo is a suite of libraries that implement various blockchain primitives used in core blockchain development. These primitives are:

  • Transactions - how we update state on chain. Whenever you want to update the state of an account or a smart contract on Ethereum, you have create a transaction that describes your state change and submit it to the blockchain. The tx library contains all of the low level operations needed to construct a transaction and package it up in the serialization format necessary to broadcast it to the chain.

  • Blocks - how we define the units of history of the chain. A block is simply a collection of transactions in sequential order that conform to the basic rules defined in the Ethereum yellow paper with some metadata that proves it's valid. The block library puts all this together for you in one place.

  • Blockchain - the history of the chain. In its most simplistic form, the blockchain is just the collection of blocks in order as defined by some consensus mechanism that makes up the history of the chain. The blockchain library implements all of this, leveraging the block and tx libraries to construct the individual units of state change and history that make up the Ethereum chain.

  • Ethereum Virtual Machine (EVM), this is the "secret sauce" of Ethereum (though truth be told it's not very secret). The EVM is what separates Ethereum from Bitcoin and allows for all of the plethora of things most blockchain aficionados are familiar with, defi, NFTs, DAOs, etc. Think of the EVM as a simple machine that runs whatever instructions you send it (not unlike a calculator or a computer), and the transactions you submit contain the instructions necessary for the EVM to operate. The evm, vm, and statemanager libraries collectively make up a complete implementation of the Ethereum Virtual Machine and its operating environment.

  • The full node - the client that runs the Ethereum blockchain. Built on all of the above libraries, the client library is a mostly complete Javascript implementation of the Ethereum full node. Because of the performance limitations of Javascript as an interpreted rather than compiled language, this client can't realistically be run as a Mainnet client at present, but it is a working implementation and is capable of syncing testnets and exposes a mostly complete implementation of the Ethereum JSON-RPC. And, it's written in Javascript, so it's not completely inpenetrable to most web developers today (unlike say the almost complete incomprehensibility of Rust to poor JS devs like me).

Loading...
highlight
Collect this post to permanently own it.
Subscribe to Web3 Ninjitsu and never miss a post.
  • Loading comments...