Open In App

Setting Up Smart Contract Development Environment

A development environment is an environment in which all the resources and tools are available which are used to develop a program or software product. Here, an attempt to create a development environment that is a collection of the processes and tools that are used to develop smart contracts.

There are mainly two choices available to set up the environment for developing smart contracts:



  1. Online IDE: This is a quick, easy, and beginner-friendly online IDE used to develop smart contracts. Online IDE setup is not recommended when we go deep into the development of smart contracts because of their limitations.
  2. Local Set-Up: All the tools and packages are installed on the local machine that is used to build smart contracts.

This article focuses on discussing how to set up the local development environment for executing smart contracts.

Smart Contract

A Smart Contract is a business contract built in the form of a program, which is deployed on the blockchain network, and the computation required for the execution of a program is provided by the blockchain network. The objectives of smart contracts are the reduction of the need in trusted intermediates, arbitrations, and enforcement costs, fraud losses, as well as the reduction of malicious and accidental exceptions.



Tools required for local environment setup:

The following tools are required to set up the local environment for the smart contract:

Follow the steps below to install the required tools

Install NodeJS:

Node.js is a free, open-source server environment that runs on various platforms(Windows, Linux, Mac OS, etc) and uses javascript on the server. As an asynchronous event-driven javascript runtime, Node.js is designed to build scalable network applications.

  1. Click on the link Node.js.
  2. Select the type of installer, Windows or macOS.
  3. Install the file downloaded on the system.
  4. Verify the installation by executing “node -v” and “npm -v” in the command prompt.

When Node.js is installed on the system npm(Node package manager) is also installed which is used to install various packages using command prompt. We can 

Install Truffle Suite:

Truffle Suite is a world-class development environment, testing framework, and asset pipeline for blockchains using the Ethereum Virtual Machine (EVM), aiming to make life as a developer easier.

To install TRUFLLE SUITE we use npm command in the command prompt-

npm install truffle -g

Install Ganache (Single node local Ethereum network):

Install 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.

Install Solidity:

Solidity is an object-oriented, high-level language for implementing smart contracts. Smart contracts are programs that govern the behavior of accounts within the Ethereum state. Solidity is statically typed, supports inheritance, libraries, and complex user-defined types among other features. With Solidity, you can create contracts for uses such as voting, crowdfunding, blind auctions, and multi-signature wallets. When deploying contracts, you should use the latest released version of Solidity.

Building first smart contract:

Step 1: Open command prompt terminal in VS code and type command-

mkdir hello-world

cd hello-world

Step 2: Generates the template of the smart contract by executing the command-

truffle init

Step 3: Now, Create HelloWorld.sol file by executing the command-

truffle create contract HelloWorld

Step 4: Now copy or type the below code to your code editor.




// Solidity program to create
// Hello World program
pragma solidity >=0.4.22 <0.9.0;
 
contract HelloWorld
{
  string message;
  constructor() public
  {
    message = "Hello World!";
  }
 
  function SayHello() view public returns (string memory)
  {
    return message;
  }
}

Step 5: After typing the above code execute the command-

truffle compile

This command will compile your solidity program and a new folder is created named “build” and the following output will be displayed-

Step 6: After compiling the Smart Contract execute the below command to deploy the Smart Contract.

truffle migrate 

This command used to deploy the Smart Contract and return the deployed Smart Contract  address.


Article Tags :