Open In App

Setting Up Smart Contract Development Environment

Last Updated : 04 Apr, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

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:

  • NodeJS: It is a free, open-source server environment that runs on various platforms by using JavaScript on the server.
  • Truffle Suite: It is a first-rate development environment, testing framework, and asset pipeline for blockchains using the Ethereum Virtual Machine (EVM), aiming to make life as a developer easier.
  • Ganache: It is an Ethereum development tool that is a part of the Truffle Suite and when looking for Ethereum dapps testing tools it is the best tool that fulfills the developer’s requirement.
  • Visual Studio Code: It is the most powerful IDE provided by Microsoft with various development options.

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.

Install Nodejs

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 Truffle

Install Ganache (Single node local Ethereum network):

  • Download Ganache setup.
  • Install the setup and run Ganache in quickstart mode the following screen would appear.

Install Ganache

  • The above screenshot shows some accounts with a 100 ether balance. which are already created by Ganache and 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.

Customize ganache test

  • 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 the case of the setting as seen in the above screen the RPC endpoint will be http://127.0.0.1:7545.
  • Ganache installation is running and can be interacted with using the above-mentioned RPC endpoint.

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.

  • After installing VS code install Solidity extension from the extension section.

Install Solidity

  • After installing the solidity extension on your VS code you are ready to build your first smart contract.

Building first smart contract:

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

mkdir hello-world

cd hello-world

mkdir and cd command

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

truffle init

truffle init

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

truffle create contract HelloWorld

truffle create contract command

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

Solidity




// 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-

Output

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.



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads