Develop, Deploy and Test Your First

Dr Kosala Yapa Bandara National University of Ireland – Galway.

John O’Donoghue Reform Delivery Office Department of Public Expenditure and Reform

1

Tutorial 1: Develop, Deploy and Test Your First Blockchain Smart Contract

Dr. Kosala Yapa and John O’Donoghue Department of Public Expenditure and Reform

The purpose of this document is to give an easy to follow introduction in how to develop, deploy and test your first blockchain smart contract. While there are many tools and platforms associated with the development of different , this tutorial uses REMIX IDE, and Solidity technologies. This tutorial uses the Firefox browser but Chrome is also effective.

For those who need an accessible introduction to blockchain itself before they attempt to develop one, please read “An Introductory Guide to Blockchain for Public Servants” on the link Blockchain Resources. The link also gives access to other blockchain material.

Essentially blockchain is an immutable and distributed information storage technology. Information is stored in hexadecimal form contained in blocks that are chained to each other. Information that is saved to the chain cannot be deleted, and all participating nodes store the same copy of the chain and perform the exact same transactions as each other on their copy of the chain.

The blockchain you will manipulate below will simply store a sequence of names that you enter into it. You will also write code that will allow you to read the most recent entry you made to the blockchain.

Step 1: Frist of all open Remix IDE https://remix.ethereum.org/

Click on Settings at the lower left and select the Theme you like. I preferred Light(light). Then close all unnecessary windows and you will get the RIMIX IDE as follows:

2

Step 2: Selecting Solidity compiler

Click the following icon at the very left column.

Now you can select the compiler version and set up the auto compile option.

Step 3: Setting up the environment

JavaScript VM is a sandbox blockchain implemented with JavaScript in the browser to emulate a real blockchain. Here you click on the following icon at the very left column.

Then select JavaScript VM environment as follows:

3

You can select an account registered on the blockchain and gas limit of a transaction. Here you can go for default account and gas limit.

Step 4: Writing your first smart contract

Now write your first solidity program to store names and retrieve names.

Click on the files icon on the left of the screen and then click + sign next to the browser, and you will get the following window.

Now you can provide a name for the solidity program and click ok to save it (I gave names.sol).

Now you can start writing your first smart contract in solidity.

In the first line, you should provide the version (or a range of versions) of solidity compiler that you can compile your contract. Then you can start writing your contract following solidity syntax.

4

For information on how to save your code, read this link. A simple way to save your code is to copy/paste it from the window depicted into a text file with the file descriptor .sol. You can then upload your saved code at a later date using the small folder icon (3rd icon to the right of “browser”) in the figure above.

This contract was correctly auto compiled, and you can see the icon at the left-hand side column.

Note: You need to learn solidity syntax to write smart contracts.

Step 5: Deploying your smart contract on JavaScript VM sandbox blockchain.

Click on this icon on your left-hand side column. Then you will get the following window.

5

Now, from the box above Deploy, you can select the contract you need to deploy and hit the Deploy button.

This will deploy the “names.sol” smart contract on the blockchain. The deployment details (log files) can be found below the contract as follows:

Now you can find the deployed contract on your left-hand side. Click button just below Deployed Contracts and you will see the deployed contract as follows.

6

Step 6: Testing your smart contract

Let us say that you need to store your name on the blockchain. You can just type your name and hit the write button. If you need to read what you have stored, you can click the read button.

When you write and read, check transaction logs on your right-hand side as follows.

When you click the read button, you can read your name stored on the blockchain as follows.

If you are to store a list of names and read all names you store, need a special data structure in solidity which is called mapping. Our next tutorials will cover advanced stuff.

7