Blockchain and Ethereum Certification Tr... (38 Blogs)
AWS Global Infrastructure

Setting Up A Smart Contract Development Environment

Last updated on Mar 30,2022 3.6K Views

Omkar S Hiremath
Tech Enthusiast in Blockchain, Hadoop, Python, Cyber-Security, Ethical Hacking. Interested in anything... Tech Enthusiast in Blockchain, Hadoop, Python, Cyber-Security, Ethical Hacking. Interested in anything and everything about Computers.
2 / 4 Blog from Smart Contracts

Most commonly heard term across any Blockchain discussion is “Smart Contract”, this has been dubbed as the most compelling feature of Blockchain. A Smart Contract is the backbone of any Ethereum Applications. And setting up a Smart Contract development environment is a very important thing for a Blockchain Developer.

In this Setting up a Smart Contract Development Environment blog, I will be covering the following topics:

What is a Smart Contract?

Well, doing a simple google search one ends up with multiple links. 

Wikipedia definition “A smart contract is a computer protocol intended to digitally facilitate, verify, or enforce the negotiation or performance of a contract.”

Nick Szabo defines a smart contract as a general-purpose computation that takes place on a Blockchain or distributed ledger.

A smart contract, in essence, is a contract built into the code. For example, Purchase order is a contract that exists between a buyer and a seller, keeping it in the simplest form. Certain conditions have to be fulfilled for the purchase order to be executed successfully. Few of the conditions

  1. Successful payment for the goods by the buyer.
  2. Goods provided in the right condition to the buyer by the supplier.
  3. Goods delivered before the due date agreed upon at the time of purchase.
  4. Conditions for return of goods agreed upon in the purchase order.

Purchase order- What are smart contracts - edureka

These are a few of the simple conditions in the simplest of a purchase order. 

  1. These conditions can be converted into digital format i.e. digitally facilitated.
  2. Actions like creating a purchase order, fulfillment of the order are exposed as a function in the program, these actions are called transactions.
  3. Transactions can only be executed by the designated actors (buyer, seller) hence the verification. For example, a buyer can place an order, a supplier can fulfill the order.
  4. All the transactions require computation i.e. they have to be executed by a processor. In the case of the Blockchain network, it is a distributed computing network or general purpose computing.
  5. As these transactions are verified and enforced by the network, once confirmed the transactions cannot be reverted. 

A smart contract can be summarized as

  1. A business contract built in the form of a program
  2. Which resides on the Blockchain network, the network provides the computation required to execute the program.
  3. To execute the function of the program, permissions are provided to the designated actors, which verifies.

This blog on Edureka, provides in-depth information about Smart Contracts.

The next big question which comes to mind is how to get started, what is required to build a smart contract. So let’s see how to get started.

How to start setting up a smart contract development environment?

In the previous section, we discussed what Smart Contracts are, in this section we are going to look at the following topics:

  1. What is required to build a smart contract?
  2. What are the different languages available for building smart contract?

The choice of the language, to build smart contract is dependent on the blockchain platform. For this blog series, the blockchain platform of choice is Ethereum. Ethereum is the blockchain platform which has been dubbed as “Planetary level computer or world computer”– a huge public network of many private computers that facilitate running of internet applications (DApp – Distributed Applications) without any third parties.

Smart Contract Language

A Smart Contract language (SCL) is a programming language that is either used to write a Smart Contract directly or is compiled to it. Smart Contract languages for Ethereum are:

  1. Solidity
  2. eWASM
  3. Vyper
  4. Ethereum bytecode

Smart contract languages - What are smart contracts - edureka

For this blog series, we are going to focus on Solidity as the smart contract development language. Solidity is the most popular smart contract language for Ethereum. So now we have chosen our language for smart contract development, let us see what is required to get started.

Setting up the development environment

In physics, we have often heard static friction is greater than dynamic friction. Getting started with smart contract requires setting up of development environment, which is the prerequisite. In this blog, we will look at the steps required to set up the development environment and what are the options available. Similarly, knowing about the development environment for Smart Contract development is a greater hurdle than actual development. There are a plethora of choices available, which overwhelm anyone new to building a Smart Contract. Simplifying the environment set up is the first step towards dwelling deeper into the blockchain world. In order to set up the environment for developing a Smart Contract, two choices are available.

  1. Remix Online IDE
  2. Local Set Up

Remix IDE

The first choice is to use online remix IDE (integrated development environment) to build and test the smart contract. This is a quick, easy and recommended way for beginners.

Pros

  • No installation required, completely online
  • Get started without any challenges, quick for prototyping and validating Smart Contract
  • Provides a local Ethereum virtual network

Cons

  • As the progression goes from building Smart Contract, to consuming the smart contract in DApp (Distributed Application) Remix IDE has serious limitations.

Local Setup

An alternative to using Remix IDE is to set up a local machine for developing Smart Contracts.

Local set up - What are smart contracts - edureka

Toolset required for smart contract development is as follows:

Node

The latest version of the node can be downloaded here.

Using NVM (Node Version Manager)

Windows Installation
    • Download installer from here 
  • Download and run the installer, this should install the nvm
  • Open up a windows terminal and run “nvm –version”

nvm --version

  • This should return the current version on nvm.
Mac Installation
  • Run the following script, this should automatically install nvm on the machine.

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.0/install.sh | bash

  • In order to validate the installation run the following command “nvm --version
Post-Installation
  • Once the nvm is installed run the following command.
  • Run the following command “nvm list”. This will list down the node version installed locally

nvm list

  • To list down the node version available for download please run the following command

nvm ls-remote 

  • In order to install a specific version of node run the following command “nvm install <node-version” e.g. “nvm install 10.15.0” this will install node version 10.15.0.

nvm install 10.15.0

  • Check the current version of the node being used by following command

node --version

  • For further details on nvm or node, please look at details here.

Visual Studio Code

Visual Studio Code has been one of the best IDE provided by Microsoft for solidity smart contract development. Visual Studio code can be downloaded from here.

Truffle Suite

Truffle suite provides an excellent framework for Smart Contract. Installation of truffle is done via npm (node package manager), which is installed with node. In order to install truffle, open up the terminal window or command prompt window. In the terminal window run the following command,

npm install -g truffle

(g flag in the command stands for global)

Post installation of truffle is completed, run the following command to verify the version installed

truffle --version

Ganache (Single node local Ethereum network)

  1. The setup file for ganache can be downloaded here
  2. Select the installation package based on the operating system.
  3. Run the installer, once the installation is completed following screen should appear

Ganache sreen - What are smart contracts - edureka

In order to customize the ganache test Ethereum node running, please click on the gear icon on the right corner of the ganache tool, the following screen should be visible. 

ganache test Ethereum node running - What are smart contracts - edureka

Port and network id can be customized, post customization, please click on the restart button on the top left corner.

This will reinitialize the node and RPC location will be http://[host-name]:[port]. In case of the setting as seen in the above screen the RPC endpoint will be http://127.0.0.1:7000

Ganache installation is running and can be interacted with using the above-mentioned RPC endpoint.

Pros

  • Flexibility in building up enterprise-grade applications.
  • Ease of selection of tools to build up Distributed Application (DApp)

Cons

  • Environment set up is tedious and takes time.

The first step in any journey is to understand what path to take and what toolset are available. Now we are aware of what smart contracts are, what is required to build a smart contract. The option of language available and toolset available to build them. This is the first blog in a series which will focus on solidity and smart contract development. In the next blog, we are going to build our first smart contract and start looking into the basics of solidity.

Got a question for us? Please post it on Edureka Community and we will get back to you.

If you wish to learn Blockchain and build a career in Blockchain Technologies, then check out our Blockchain Certification Training which comes with instructor-led live training and real-life project experience. This training will help you understand what is Blockchain in an exhaustive manner and help you achieve mastery over the subject.

Comments
0 Comments

Join the discussion

Browse Categories

Subscribe to our Newsletter, and get personalized recommendations.