Fabric Samples made easier with Hurley the Development Environment Manager

Walter Montes
Jan 31 · 5 min read

In case you didn’t know there are a lot of great chaincode examples here from the very own Hyperledger Fabric team. These help us understand better how to build correct Fabric code and also get tips and tricks that the docs may not include.

There are really simple and basic examples like fabcar and a bit more complex like the commercial-paper.

Something that is not great is how all of these examples manage the development environment differently. Maybe because these were created by different teams or in different points in time. It may be confusing.

A development environment is usually something that is better if it is mutation-resistant. So immutable setups like the one that Hurley provides is a simple and straight forward way to deal with it without much hustle.

Hurley is part of the Convector Suite but independent from Convector Smart Contracts. Precisely in this example, I will show how to use it with non-Convector smart contracts.

You want to start today and just run hurl new to create your dev env and go ahead and focus on the code. You don’t really want to debug or read how to install, instantiate, and upgrade each sample you’d like to use as inspiration.

I want to show you how easy you can start with Hurley here.

These are all the chaincode samples in the fabric-samples repo.

There are go and node chaincodes, but most of them are really simple and easy to read. Though, maybe not as great as I think that Convector Smart Contracts are 😁.

So let’s get to it. We will need first to start our dev env, and then install the chaincode, and make a few invoke tasks.

Install Hurley

You will also need NPM and Docker CE.

If you had a previous version of Hurley, upgrade first.

Start your environment

This will create a development blockchain with 2 organizations and one channel, plus one user per organization.

More details for more complex scenarios here.

Installing and testing examples

chaincode_example02 (click to see the code)

This is a simple example of how to create units accounting. The example doesn’t prevent transferrals that exceed what one user has, but it’s an easy way to understand go easily.

First get to the right folder inside the fabric-samples folder.

We need to first install the chaincode. It requires 4 properties, 2 users and their units, passed as params:

Check if the user received the initial units:

Let’s make an invoke to transfer units:

Now let’s see if the transfer actually happened.

That’s it! 🙂 As you can see it’s really simple to install and invoke your chaincode.

If you’d like to test the node version of the code, go back to the root folder of this example cd .. and run:

And you can repeat previous steps but referencing this new chaincode.

marbels02 (click to see the code)

This is a more complex example, and you can still do all sorts of things with Hurley to interact with this smart contract.

First, install it.

Here are a lot of invokes you can try, from simple transactions to simple and complex queries.

sacc

Another example is the SimpleAsset chaincode.

Go to the chaincode folder and install the chaincode.

Then you can add and query assets.

fabcar (click to see the code)

Last but not least, the fabcar example I’ve seen really used by devs.

It has a self-generation function to create some mock data:

Query all the items:

And transfer one car to another person:

And confirm transferral:


I hope this post has helped you and to see you around in the Convector Suite community on Discord and Twitter.


WorldSibu

A unified development platform to create and deploy enterprise smart contract systems.

Walter Montes

Written by

CEO @WorldSibu — https://worldsibu.tech/forma

WorldSibu

WorldSibu

A unified development platform to create and deploy enterprise smart contract systems.