Every day, I’m having fun implementing a blockchain in Java (see project, see posts), based on Ethereum, like others, like RSK, my daily job. One of the interesting part to code is the representation of the world state. In the last years I implemented the Trie, many times, in many languages (like Java and C#), and one thing it is for sure: it is important in the most popular use case a blockchain node has: the execution of block.

(If you don’t know what a Trie is and how it is used in Ethereum blockchains, read Understanding the Ethereum Trie

When you deploy a compiled smart contract to an Ethereum-like blockchain like RSK, your transaction includes the compiled bytecode, including the constructor code.

An example, if you want to deploy Counter.sol:

pragma solidity >=0.5.0 <0.6.0;contract Counter {
uint public counter;

function increment() public {

function add(uint value) public {
counter += value;

function incrementFail() public {
require(false, "fail error");

function fail() public pure {
require(false, "fail error");

your transaction will contain:

Photo by Jan Antonin Kolar on Unsplash

These days I am practicing programming smart contracts in Solidity using TDD. There are several projects I am working on: some DeFi projects, a programmatic faucet, user login and onboarding, personal notes, some games. One of the projects already has something to show: I have been able to upload (image) files to RSK’s testnet.

One comment: a blockchain is not the more appropriate place to save files, at least an Ethereum-like. The upload of a file could cost many millions of gas units. And the retrieval is not the fastest. …

Based on an idea by bguiz published in RSK reseach forum: Crazy Idea: New opcodes for relational DB like data reads and writes, I was writing Solidity code to explore an alternative implementation in an Ethereum-like blockchain. I don’t add opcodes because these are scarce, and adding them could broke compability with Ethereum. My project is BDTables.

The base idea is to have an smart contract representing a database-like table with rows and columns:

Table smart contract storage

That is, a Table smart contract has: no of rows, no of columns, and a data offset where the data START to reside. …

These years I was programming a log, using TDD (Test-Driven Programming), to keep me trained in design and developer skills. To me, TDD is a great workflow to discover emergence design solutions, to simple and complex domains. One of my preferred domains is blockchain, and I wrote tons of code in Java, C# and JavaScript, even Solidity smart contracts. The top example is my personal blockchain project in Java (see also my published posts).

I learned about blockchain thanks to my work in RSK. The company flag product is an Ethereum-like blockchain, connected to the Bitcoin blockhain.

In an Ethereum-like blockchain (like RSK or my personal project BlockchainJ) the smart contracts have a linear storage, composed by cells thafied by a key.

In case of storage, the key is a data word of 32 bytes (a kind of unsigned big number) and the value is also a data word (well, in RSK and my implementation, the value could be any byte array, is up to the consumer code the interpretation of that value).

Smart contract storage

The storage looks linear BUT only the values that are not zero are saved. …

I’m very proud of my favorite personal project BlockchainJ: build a Blockchain in Java, from scratch, using TDD (Test-Driven Development). Previous posts:

Building a Blockchain: Introduction
Building a Blockchain: Main Entities
Building a Blockchain: Serialization
Building a Blockchain: Key Value Stores
Building a Blockchain: Subroutines in the Virtual Machine
Building a Blockchain: Towards Beam Synchronization

It’s based in Ethereum, so it supports smart contracts. I’m using the same bytecodes, to keep compability with the ecosystem (like Solidity compilers and wallets).

Today, I want to describe my current implementation of how to execute an smart contract in the VirtualMachine.java class. …

Photo by Esther Jiao on Unsplash

Some months ago, I wrote about Command Line Tools for RSK Node; now those tools are included in the latest RSKJ release (under the package with name co.rsk.tools.cli).

Using a local testnet database, I exported 5000 blocks with the command:

java -cp <rsk.jar> co.rsk.cli.tools.ExportBlocks 718000 722999 --testnet > testnetblocks.txt

These days, I wrote new commands in JavaScript to analyze that info, specially to obtain the blocks mined by each miner account.

Counting the Blocks

Using count.js, I executed:

node count testnetblocks.txt

The output was:

no blocks 5000
no transactions 250849
average no transactions per block 50.1698
no uncles 6461
average no uncles per block 1.2922
no uncles same…

Suppose that you have an online web site, social network, or game. Your users connect with your server(s) using a mobile, web or desktop client application. Each user has a nickname, and should provide credentials to initiate a session with your server.

Now, you want to give them tokens, as they complete tasks, activities, games, receive likes, or provide content to your system. That tokens resides in an Ethereum-like blockchain. I want to describe a workflow that allow your users to participate in the blockchain.

Blockchain Sign Up

A user must sign up to participate in the blockchain activities. He/she has a nickname…

I’m very enthusiastic about my personal open source project BlockchainJ, a blockchain written in Java using TDD. To me, it’s very interesting (and a lot of fun) to design, write and explore ideas and code using the Test-Driven Development workflow. I think that you can understand any problem if you write a solution to it. And to write a blockchain is a not trivial project, but also one that can be achieved. Every day, I wrote few lines of test and production code, to complete the task. Now, I can run many nodes, communicate them, mine blocks, execute transfer transactions…

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