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:
- 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.
- 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.
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:
- 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
- Click on the link Node.js.
- Select the type of installer, Windows or macOS.
- Install the file downloaded on the system.
- 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):
- Download Ganache setup.
- Install the setup and run Ganache in quickstart mode the following screen would appear.
- 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.
- 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.
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.
- 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-
Step 2: Generates the template of the smart contract by executing the command-
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.
pragma solidity >=0.4.22 <0.9.0;
function SayHello() view
returns (string memory)
Step 5: After typing the above code execute the command-
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.
This command used to deploy the Smart Contract and return the deployed Smart Contract address.
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses
are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!