The tech-stack to win the worlds biggest blockchain hackathon of 2018!

We’ll walk you through the stack we used for our winning application

Jeroen De Prest
wearetheledger
5 min readApr 13, 2018

--

This article is a continuation on one of our previous articles showing the demo of the application we used to win the worlds biggest blockchain hackathon of 2018.

The frontend: ReactJs & Auth0

It is a basic React frontend with Auth0 integration to handle our authentication. It looks like three different frontends but it is only one project. We used roles which are added to the user in Auth0 to distinguish between different users and then render different views in react.

Auth0 is a free to use service to manage the authentication in your application. We have used this on quite a few projects. It allows us to integrate social media logins quite easily and we don’t have to worry about storing the users in separate database.

The backend: NestJs & Typescript

The backend was created from a base boilerplate that we have built at TheLedger. This boilerplate is written in TypeScript and is using the NestJs framework. We have two main services: an API service and a chain service to connect to the Hyperledger Fabric network. The Stellar service was added for this prototype to connect to the Stellar testnet. We used this to integrate escrow smart contracts on Stellar for this prototype.

The API service handles all the API calls from the frontend. This service is using swagger decorators to easily identify API routes. This service is then integrated with Auth0 to make sure all the calls are legitimate. When calls are made, we automatically identify the user and create certificates for them to interact with the network.

The chain service interacts with the Hyperledger Fabric network. We abstracted a lot of the redundant code so that we can quickly add chaincode functions and create queries or invokes wherever necessary.

The backend still has quite a few more tricks up its sleeve. For example, we added an Amazon AWS SQS queue integration for invokes between the API service and the chain service. We do this for concurrency reasons, which are discussed in this article. We also have a Pusher integration in this boilerplate to push notification to the frontend but both of these features were not used in our hackathon prototype to save time. We did, however, include Stellar integration which isn’t in the basic boilerplate.

The Blockchains: Hyperledger Fabric & Stellar

Now we can get to the core of the application, the actual blockchain networks. For this project, we used two different blockchain networks. The first is, of course, Hyperledger Fabric (HLF). We have done quite a few projects with HLF. Note that we are using “native” HLF 1.1.0 and not Hyperledger Composer. We first looked at Composer quite early in its lifecycle and deemed it not ready yet for projects. We have seen that Composer has made pretty big improvements and although a prototype like this would be a great fit for Composer, we still prefer to use Fabric “natively” for now until we look into Composer further. To make it easier for ourselves we also created a boilerplate to set up a Fabric network. This boilerplate also has one of our other libraries implemented by default to help us write nodejs chaincode faster.

Our chaincode for the Fabric network was written in TypeScript. We used to write all our chaincode in Golang but we eventually switched to Nodejs/Typescript because we can have a better package structure and we are also all a bit more comfortable in using JavaScript-based languages. Golang can be a bit finicky to work with when you are not used to it. This doesn’t mean we won’t work with Golang anymore.

Contract Structure

This is how our chaincode structure looks like at the end of the hackathon. We split the chaincode in different directories depending on the subject. In the main folder, we still have the seeding files, the main chaincode file, and the index file. These seeding files aren’t really in a good place here, it would be better to move them to the correct directory.

Maybe a quick explanation of how this structure works. The index file is the file that holds the chaincode and then adds all the functions to this chaincode.

const mainchaincode:any = new MainChaincode();mainchaincode.queryAllSubsidies = queryAllSubsidies;shim.start(mainchaincode);

This was the chaincode side of things but how about the network side of things. Well, the network we used isn’t really that fancy. Our boilerplate is based on the fabric-samples from hyperledger from which we removed almost everything except for the basic-network. This means we are using a network with one CA, one Org with one Peer, one Orderer, and one CLI. This is a pretty basic network but it works, it’s stable and we don’t need anything fancy for our prototype.

Stellar Integration

We chose for the Stellar network because it’s one of the fastest and cheapest payment networks. Stellar is responsible for transferring money from the house to the contractor and from the government to the house as a subsidy. In addition, we’ve created code to create an escrow smart contract between the house and contractor. Once a job has finished, the payment will be released from the escrow to the contractor.

That’s it!

--

--

Jeroen De Prest
wearetheledger

“The Blockchain Giant”, Full stack Blockchain Developer @ TheLedger