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?
- How to start setting up a smart contract development environment?
- Smart Contract Language
- Setting up the Development Environment
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
- Successful payment for the goods by the buyer.
- Goods provided in the right condition to the buyer by the supplier.
- Goods delivered before the due date agreed upon at the time of purchase.
- Conditions for return of goods agreed upon in the purchase order.
These are a few of the simple conditions in the simplest of a purchase order.
- These conditions can be converted into digital format i.e. digitally facilitated.
- Actions like creating a purchase order, fulfillment of the order are exposed as a function in the program, these actions are called transactions.
- 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.
- 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.
- As these transactions are verified and enforced by the network, once confirmed the transactions cannot be reverted.
A smart contract can be summarized as
- A business contract built in the form of a program
- Which resides on the Blockchain network, the network provides the computation required to execute the program.
- 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:
- What is required to build a smart contract?
- 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:
- Ethereum bytecode
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.
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.
- No installation required, completely online
- Get started without any challenges, quick for prototyping and validating Smart Contract
- Provides a local Ethereum virtual network
- As the progression goes from building Smart Contract, to consuming the smart contract in DApp (Distributed Application) Remix IDE has serious limitations.
An alternative to using Remix IDE is to set up a local machine for developing Smart Contracts.
Toolset required for smart contract development is as follows:
The latest version of the node can be downloaded here.
Using NVM (Node Version Manager)
- Download installer from here
- Download and run the installer, this should install the nvm
- Open up a windows terminal and run “nvm –version”
- This should return the current version on nvm.
- 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 “
- Once the nvm is installed run the following command.
- Run the following command “nvm list”. This will list down the node version installed locally
- To list down the node version available for download please run the following command
- 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
- 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 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
Ganache (Single node local Ethereum network)
- The setup file for ganache can be downloaded here
- Select the installation package based on the operating system.
- Run the installer, once the installation is completed following screen should appear
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.
Port and network id can be customized, post customization, please click on the restart button on the top left corner.
Ganache installation is running and can be interacted with using the above-mentioned RPC endpoint.
- Flexibility in building up enterprise-grade applications.
- Ease of selection of tools to build up Distributed Application (DApp)
- 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.