Build your First Smart Contract: Introduction to Ethereum Blockchain Programming

After covering an extensive series of articles on Blockchain Programming using the Proof-of-Work Consensus Mechanism that is used in the Bitcoin’s Blockchain, it’s time to up your game. If you are someone who is mad all day about programming on the blockchain. This series of articles will give you the pump by building your very first Smart Contract on the Ethereum Blockchain. 

We will try to break down the topic in the simplest terms ever, gathering the information from various sources on how to build your Smart Contract from scratch to deploying your Smart Contract on the testnet/mainnet. A guide that even Dexter can follow from his Laboratory!

Some things to know before you start building and deploy your first Smart Contract

Ethereum Virtual Machine. So you can write more powerful programs than on top of Bitcoin. It refers to the blockchain, what executes smart contracts, everything.

Node. Using this to mean you can run a node and through it read and write to the Ethereum blockchain, i.e., use the Ethereum Virtual Machine. A full node has to download the entire blockchain. Light nodes are possible but in the works.

Miner. A node on the network that mines, i.e., works to process blocks on the blockchain. You can see a partial list of live Ethereum miners here: stats.ethdev.com.

Proof of Work. Miners compete to do some math problem. The first one to solve the problem (the next block on the Blockchain) wins a reward: some ether. Every node then updates to that new block.

Every miner wants to win the next new block so are incentivized to keep up to date and have the one true blockchain everybody else has, so the network always achieves consensus.

Ether. Or ETH for short. It’s a real digital currency you can buy and use.

Gas. Running and storing things on Ethereum costs small amounts of ether. Keeps things efficient.

DApp. Decentralized App, what applications using smart contracts are called in the Ethereum community. The goal of a DApp is (well, should be) to have a nice UI to your smart contracts plus any extra niceties like IPFS (a neat way to store and serve stuff in a decentralized network, not made by Ethereum but a kindred spirit).

Also Read: Build your First Smart Contract: Deploying Smart Contract using Truffle
How to deploy the smart contract

Ethereum becomes popular because of smart contracts. People who start their first smart contract on the Ethereum network would be confused in various tools and languages. This is the tutorial to build the first smart contracts from the scratch. I would use solidity, testRPC, Truffle in this tuition.

Solidity is an object-oriented language for writing smart contracts on various blockchain platform. The article talks about how to setup solidity environment on Ubuntu and runs your first smart contract on test environment step by step.

Install TestRPC

When you developing your smart contracts, you would not want to deploy your dapp (decentralized app) on the live Ethereum network before adequate testing. Testrpc provides a testing and development Ethereum client. It uses ethereumjs to simulate full client behavior and process transactions instantly and it tells you immediately when your smart contracts run into errors.

Testrpc is distributed as a Node package via npm, and it requires at least Node.js v6.9.1, you can install nodejs and npm from their official website or use package manager:

sudo apt-get update
sudo apt-get upgrade
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install nodejs

Make sure you have installed node.js and npm. Use the npm to install testrpc:

sudo npm install -g ethereumjs-testrpc

If you success install, you can type

testrpc

to check you are can run test network normally. And it would show like this.

Smart Contract
If TestRPC installed successfully 

Install Ethereum protocol

There are three original implementations(Geth, Eth, Pyethapp) of the Ethereum protocols. You can use these clients to deploy your smart contracts to desired Ethereum network. These clients support transaction processing, networking, blocks and mining. Most of the people use Geth, and I would use Geth as an example.

You can install Geth from PPA:

sudo apt-get install software-properties-common
sudo add-apt-repository -y ppa:ethereum/ethereum
sudo apt-get update
sudo apt-get install ethereum

If you want to install another official client implements, you can get them from this website.

Also Read: Blockchain Programming Part 1: ‘Building A Blockchain’
Install Truffle

Truffle is a powerful development framework for Ethereum and supports Solidity as contract language and JavaScript and Solidity as automated test language. It provides built-in smart contract compilation, deployment, automated contract testing and interactive console for direct contract communication. It also accesses to hundreds of external package. You can install it via npm:

sudo npm install -g truffle

Photo by Jefferson Santos on Unsplash

Disclaimer: The opinions presented here are of the Authors. Readers should do their own due diligence before taking any actions related to the promoted company or any of its affiliates or services. CoinScenario.com is not responsible, directly or indirectly, for any damage or loss caused or alleged to be caused by or in connection with the use of or reliance on any content, goods or services mentioned in the press release.

Here is a list of Contributors on Coin Scenario. If you wish to submit a Press Release, please Click Here. If you wish to Advertise with us, please Click Here.

Spread the love
  • 7
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
    7
    Shares