Back to Top

How BlockChain and Ethereum works?


Recently I have done some R&D about BlockChain and Ethereum so I think it is time to write a new article about this topic. Some people say ethereum is hard to understand but I must say Blockchain and Ethereum is an interesting topic. Also, I will show you how you can use ethereum, how to create a smart contract in ethereum, deploy it.

To get started with Ethereum, require basic knowledge of blockchain and cryptocurrency. If you are completely new to BlockChain. I will tell you it is a concept of cryptocurrency such as bitcoin. The blockchain is kind of a globally unique book, or database, that keeps track of all the transactions in the network. The blockchain is a decentralized technology where all miners all over the world work at the same time and independently excavate the blocks that meet the requirements.

What is BlockChain?

The technology behind the blockchain is to move digital currency or coin from one individual to another. The main reason for blockchain concept is it is an open ledger. Open ledger is essentially a chain of transactions and that is the reason is called Blockchain. Open ledger is a chain of the transaction which is open and public.

To develop in Ethereum does not require you to understand all crypto economic computer sciences. You can go to Ethereum official site to check the official tutorial on tokens and crowdfunding contracts. The contract language Solidity also available in the official documentation.

What is Ethereum?

Ethereum is basically a decentralized platform that runs smart contracts. An application that runs exactly as programmed without any possibility of downtime, fraud, and third-party interference. The app runs on custom built blockchain has a global infrastructure. Ethereum was bootstrapped in August 2014 all around the world. It was developed by Ethereum foundation.Ethereum mining is currently expensive and price continues to rise.

It was developed for programmers to easily build cryptographic code. Ethereum uses solidity as a programming language to build ethereum based application.

What is Solidity?

Solidity is a high-level language which syntax is similar to JavaScript. It is designed to code for the ethereum virtual machine. Ether is the most important element in Ethereum. Ether (ETH) is a cryptocurrency of ethereum. It consumes a certain amount of ether when it executes programs and saves data. Gas is converted from the ether.

Basic Concept

I am going to interface with the simple smart contract on the ethereum blockchain and deploy it to the blockchain. The first thing you need to know about ethereum contract is you can open up any file and start writing a contract.

A smart contract is basically a program that runs on a blockchain. The rules and execution of the contract is an entirely automated process so all the funds or money controlled by the code with lower risk and no administration that’s why the cost is much lower.


Here is the example contract syntax.

contract Example{
    function Example(){

A contract is same like you are creating a class. Just change name class to contract and name of the contract then open and close brackets.

This is a basic template for how every contract is constructed. Then you need to create a constructor in the contract. The constructor is created like function and called when contract initiated and will have the same name as a contract.


Here is the example contract:

pragma solidity ^0.4.6;
contract sampleContract{
     function sampleContract(){
     function sum(int a, int b) pure public returns(string, int){
        int c = a + b;
        return (“summation of two value is:”, c);
     function multiply(int a,int b) pure public returns(string, int){
       int c = a * b;
       return (“multiplication of two value is:”,c);

I have used remix to create contract but you can use truffle to create your smart contract. A remix is a website which provides IDE to write your contract and you run your contract and you can directly execute and publish the code. A remix is good for learning and demonstration purpose but if you have a team of developers and project, you should use truffle as your development framework.

You can copy above contract and paste it into Remix to test. Let me explain the code.

Whenever you write a smart contract, you need to specify the version of solidity you are using. So that will be your first line of code. After that, you can start writing your contract.

In my contract, I have called two methods inside the contract sum and multiply. Also, I have created constructor method but not written any line of code.Constructor function needs to have the same name as the contract.It does nothing in my contract because it is empty but you can write if you want to execute code when you initiate contract execution.

I have performed addition and multiplication of two variables which are integers. You can define a variable as unsigned integer also if your number is positive integer only.

How to deploy Contract?

After setting up your smart contract or completing your code, open the terminal and first type in that is

> geth attach

Geth is the CLI which you going to use in an interface with ethereum blockchain. It is mainly used to connect geth and attach is to open up your node. After running geth attach, you need to first unlock your account and also set the default account. For that you can use below command:

eth.defaultAccount = eth.accounts[0];

Before running this command, make sure your account is set up. If not, run following command to setup your account.

geth account new

Once you run above command, it will ask for a passphrase which is the password for the new account.Once you enter the password, it will generate the address for you. You can set as many accounts as you want!

Now, let’s back to unlock account. Here is the command:

personal.unlockAccount(eth.accounts[0], ‘’);

You have to enter the password for the entered account. Once you account is unlocked, you will the true

Now, you can deploy your contract, let me show you syntax

mycontract = eth.contract('').at('

Here is my example code.

mycontract =  eth.contract('[{"constant":true,"inputs":[{"name":"a","type":"int256"},{"name":"b","type":"int256"}],"name":"multiply","outputs":[{"name":"","type":"string"},{"name":"","type":"int256"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[{"name":"a","type":"int256"},{"name":"b","type":"int256"}],"name":"sum","outputs":[{"name":"","type":"string"},{"name":"","type":"int256"}],"payable":false,"stateMutability":"pure","type":"function"},{"inputs":[],"payable":false,"stateMutability":"nonpayable","type":"constructor"}]').at('0xca35b7d915458ef540ade6068dfe2f44e8fa733c');

You just need to copy this code, change as per your abi and address. Paste the code into the terminal. This command requires the ethereum gas to perform the transaction. If gas is not available, you will get an error or it will send the code.

After that, you can use your variable or object to call methods. Here it is mycontract so I can call my methods using that.


This performs the operation or execute the function and return the output. You can go to etherscan and check your contract. You done with deployment of your first contract!.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Most Popular Posts

To prevent caching in web browser

Posted on 7 years ago


Steps To speed up Eclipse IDE

Posted on 7 years ago


HTML5 Canvas Element Tutorial

Posted on 4 years ago


Learn about Variables in LESS CSS

Posted on 4 years ago


Hello world

Updated 1 month ago

Nick Carter

In depth Understanding of Laravel Core

Updated 3 months ago


ECMAScript 6 New Features – 2

Updated 1 year ago


The Reader’s Poll – June 2015

Posted on 4 years ago


The Reader’s Poll – August 2014

Posted on 5 years ago


The Reader’s Poll – June 2014

Posted on 5 years ago


The Readers’ Poll – May 2014

Posted on 5 years ago


The Readers’ Poll – August 2013

Posted on 6 years ago