Blockchain & Solidity Program Lab Manual
ISBN 9788119221646

Highlights

Notes

  

Prog. 11: The use of GANACHE Truffle Suite to Deploy a Smart Contract in Solidity (Blockchain)

IDE

To write and execute solidity codes, the most common IDE used is an online IDE known as REMIX. You can either open it online on https://remix.ethereum.org/ or install it in your system from https://github.com/ethereum/remix-ide. You can also use Mist (the Ethereum Dapp browser).

After you write the code and compile it you can deploy it in 3 ways –

This article explains how to deploy your contract by using Ganache as a web3 provider. Ganache

Ganache is a personalized blockchain for Ethereum development. It can be used to run tests, execute commands, and inspect states while controlling how the chain operates. It is provided by Truffle Suite and can be downloaded

from https://www.trufflesuite.com/ganache

Step 1: Open Remix IDE in your browser. After opening click on “ + ” and write the filename as follows –

Step 2: Write the following sample code for testing and compile by clicking on the Compile button as shown –

Solidity

// Solidity pr

// Solidity program to demonstrate pragma solidity ^0.4.26;

// Creating a contract contract shreyansh_05

{

// Defining a function

function get_output() public pure returns (string)

{

return (“Hi, your contract ran successfully”);

}

}

Step 3: After compilation open GANACHE on your desktop which you have downloaded from the link given above. The screen will look like below. Click on QUICKSTART Ethereum

Step 4: Now you will get 10 default accounts for your blockchain at a local RPC server HTTP://127.0.0.1:7545 as below-

Step 5: Go back to the browser and move to Deploy section just below the compilation and select Web3 Provider in place JavascriptVM as shown below-

Step 6: Enter the server HTTP://127.0.0.1:7545 as Web3 Provider. The screen will look like below –

Step 7: Now your contract is ready to be deployed. Click on the Deploy button and the deployed contract will look as follows-

Step 8: Expand the deployed contract as below and get the output using the get_output() function-

Step 9: Now, to verify whether your transaction (process) was reflected on the server or not, open GANACHE and move to TRANSACTIONS. Here you will get the details as below –