Building Your Very first Blockchain App with Eris – SitePoint

Building Your Very first Blockchain App with Eris

A few months ago I was at the Berlin Blockchain awards, and it emerges that ‘blockchain’ is the fresh buzzword that startups and tech-folk like to throw into everything, without downright understanding the concepts behind it.

Whether you believe that blockchain is just a fresh buzzword for the industry or a truly revolutionary technology, developers are often uncertain of how they can use the blockchain concept in their applications. Eris Industries’ solution might make this a bit lighter.

Eris Industries packages blockchain and brainy contract concepts to make them more usable and apply them to your project. The best projects for this sort of technology are ideas that need a form of decentralized trust and security.

In this article, I will create a demo application that is a library of names of privileged users for a hypothetical situation. In the final section of the tutorial, the application will let you switch a name in the list and check the values.

Installation and Setup

Installing Eris is confusing, the instructions on their homepage didn’t work for me, and I ended up following the steps in their more in-depth instructions instead. For me, on my Mac, I installed Docker Toolbox (Docker is a requirement) and then installed Eris with Homebrew.

Once installed, setup Eris with the following directive which will create configuration files and download the (large) Docker pics required:

Note: It isn’t clear in the Eris documentation, but it’s best to run the rest of the directives in this tutorial within the Docker context. This mainly applies to Mac and Windows, find more details here.

Granting Access

Embark an Eris keys service for authentication with:

This directive starts a service based on the keys service definition, these definitions are found inwards the

/.eris/services folder. Eris creates some by default for pre-defined application types (e.g. Tor, ipfs, and bigchaindb), but you can also create your own.

Now create some keys to permit particular users access to the service and application:

Save the key for later use, substituting the key value with the key you just generated:

And use the following directive to check what keys are available across your host machine and containers:

If you want to read more about keys with Eris, then I recommend their key tutorial.

Creating a Blockchain

Next, create a blockchain with a name ( library_chain ) and a type ( simplechain ):

If you dig inwards the hidden

/.eris folder you will see the files generated from this guideline. Inwards

/.eris/chains/library_chain are a series of files:

  • genesis.json: Tells eris how to instantiate a particular blockchain, providing the “genesis” state of the blockchain.
  • accounts.csv and validators.csv: You can use two files later to create a fresh genesis.json if it gets lost.
  • addresses.csv: Has the addresses and the “names” of the knots.

Now you’re ready to instantiate the Blockchain:

Check that the chain exists and is running:

Contracts

A ‘wise contract’ is a popular blockchain-related term for “an agreement that the blockchain will analyze transactions you send it”. As a plain Eris related example, you will create a contract that set s a value and then get s it back again. Embark by creating a folder for the application and moving into it:

Create a library.sol file inwards this folder, and add the following to it:

This file should be reasonably self-explanatory, it defines a string variable and the relevant set and get functions.

Next create an epm.yaml file that is read by the Eris package manager, looking for jobs within it to run:

Next, you need to tell Eris to look at these two files, generate the other files it needs and then:

  1. Deploy a contract.
  2. Send it transactions.
  3. Query results from the contract.
  4. Assert results.

Very first, get the address of where you want to deploy the contract:

And inwards the application folder (

/.eris/apps/library) invoke the Eris package manager upon the files you created and deploy the contract to the blockchain:

This instruction will find the jobs you announced, deploy them and then come back the assertion made, which in this case, is that the book title is a string.

Making an Application

Now it’s time to write some code that interacts with the blockchain and performs deeds upon it. This is still a plain example that permits users to set a fresh value for the book in the blockchain, and to then check the current value.

The example will use Knot.js, so very first create a package.json file in the

/.eris/apps/library folder with the following contents:

Next, create an app.js file, and add the following:

This very first code block creates requirements and then some Eris specific variables for the abi (a ‘translator’ inbetween the blockchain and the application), the accounts mentioned earlier, the IP address of the chain (in my case, a boot2docker ip) and initiates a manager and contract for the chain.

A duo of specifics aside, most of the rest of the code is more familiar JavaScript territory, creating a Knot server, listening for requests and writing and reading data to the blockchain as adequate:

Note: You may need to set the value of NODE_PORT to a suitable value.

Curl the application and PUT a value:

Now if you GET the application, you will see the value has switched:

Look at the output from the curl directive and the Knot.js application to get a slightly clearer idea of what is happening behind the scenes.

‘Conclusion’

On very first impressions it may seem that it is sophisticated to get began with a basic application using Eris. But unless you encountered any problems, these setup steps shouldn’t actually take too long and then you’ll be ready to commence using a blockchain in your applications.

Actually coding an application that uses a blockchain is a big and complicated topic and I have scarcely touched the surface. For next steps, I recommend you make sure you have a bonafide use case for a blockchain in your application and then read the tutorials on the Eris website.

It’s going to be a bumpy and at times confusing journey but I would love to hear your practices, thoughts and questions.

Building Your Very first Blockchain App with Eris – SitePoint

Building Your Very first Blockchain App with Eris

A few months ago I was at the Berlin Blockchain awards, and it emerges that ‘blockchain’ is the fresh buzzword that startups and tech-folk like to throw into everything, without fully understanding the concepts behind it.

Whether you believe that blockchain is just a fresh buzzword for the industry or a truly revolutionary technology, developers are often uncertain of how they can use the blockchain concept in their applications. Eris Industries’ solution might make this a bit lighter.

Eris Industries packages blockchain and brainy contract concepts to make them more usable and apply them to your project. The best projects for this sort of technology are ideas that need a form of decentralized trust and security.

In this article, I will create a demo application that is a library of names of privileged users for a hypothetical situation. In the final section of the tutorial, the application will let you switch a name in the list and check the values.

Installation and Setup

Installing Eris is confusing, the instructions on their homepage didn’t work for me, and I ended up following the steps in their more in-depth instructions instead. For me, on my Mac, I installed Docker Toolbox (Docker is a requirement) and then installed Eris with Homebrew.

Once installed, setup Eris with the following directive which will create configuration files and download the (large) Docker pictures required:

Note: It isn’t clear in the Eris documentation, but it’s best to run the rest of the instructions in this tutorial within the Docker context. This mainly applies to Mac and Windows, find more details here.

Granting Access

Embark an Eris keys service for authentication with:

This guideline starts a service based on the keys service definition, these definitions are found inwards the

/.eris/services folder. Eris creates some by default for pre-defined application types (e.g. Tor, ipfs, and bigchaindb), but you can also create your own.

Now create some keys to permit particular users access to the service and application:

Save the key for later use, substituting the key value with the key you just generated:

And use the following guideline to check what keys are available across your host machine and containers:

If you want to read more about keys with Eris, then I recommend their key tutorial.

Creating a Blockchain

Next, create a blockchain with a name ( library_chain ) and a type ( simplechain ):

If you dig inwards the hidden

/.eris folder you will see the files generated from this guideline. Inwards

/.eris/chains/library_chain are a series of files:

  • genesis.json: Tells eris how to instantiate a particular blockchain, providing the “genesis” state of the blockchain.
  • accounts.csv and validators.csv: You can use two files later to create a fresh genesis.json if it gets lost.
  • addresses.csv: Has the addresses and the “names” of the knots.

Now you’re ready to instantiate the Blockchain:

Check that the chain exists and is running:

Contracts

A ‘brainy contract’ is a popular blockchain-related term for “an agreement that the blockchain will analyze transactions you send it”. As a ordinary Eris related example, you will create a contract that set s a value and then get s it back again. Commence by creating a folder for the application and moving into it:

Create a library.sol file inwards this folder, and add the following to it:

This file should be reasonably self-explanatory, it defines a string variable and the relevant set and get functions.

Next create an epm.yaml file that is read by the Eris package manager, looking for jobs within it to run:

Next, you need to tell Eris to look at these two files, generate the other files it needs and then:

  1. Deploy a contract.
  2. Send it transactions.
  3. Query results from the contract.
  4. Assert results.

Very first, get the address of where you want to deploy the contract:

And inwards the application folder (

/.eris/apps/library) invoke the Eris package manager upon the files you created and deploy the contract to the blockchain:

This guideline will find the jobs you announced, deploy them and then comeback the assertion made, which in this case, is that the book title is a string.

Making an Application

Now it’s time to write some code that interacts with the blockchain and performs deeds upon it. This is still a ordinary example that permits users to set a fresh value for the book in the blockchain, and to then check the current value.

The example will use Knot.js, so very first create a package.json file in the

/.eris/apps/library folder with the following contents:

Next, create an app.js file, and add the following:

This very first code block creates requirements and then some Eris specific variables for the abi (a ‘translator’ inbetween the blockchain and the application), the accounts mentioned earlier, the IP address of the chain (in my case, a boot2docker ip) and initiates a manager and contract for the chain.

A duo of specifics aside, most of the rest of the code is more familiar JavaScript territory, creating a Knot server, listening for requests and writing and reading data to the blockchain as adequate:

Note: You may need to set the value of NODE_PORT to a suitable value.

Curl the application and PUT a value:

Now if you GET the application, you will see the value has switched:

Look at the output from the curl guideline and the Knot.js application to get a slightly clearer idea of what is happening behind the scenes.

‘Conclusion’

On very first impressions it may seem that it is sophisticated to get began with a basic application using Eris. But unless you encountered any problems, these setup steps shouldn’t actually take too long and then you’ll be ready to begin using a blockchain in your applications.

Actually coding an application that uses a blockchain is a big and complicated topic and I have hardly touched the surface. For next steps, I recommend you make sure you have a bonafide use case for a blockchain in your application and then read the tutorials on the Eris website.

It’s going to be a bumpy and at times confusing journey but I would love to hear your practices, thoughts and questions.

Related video:

Leave a Reply

Your email address will not be published. Required fields are marked *

*