How to use GANACHE Truffle Suite to Deploy a Smart Contract in Solidity (Blockchain)? - GeeksforGeeks

11 May, 2022
Smart contracts are self-executing contracts. They were first proposed by Nick Szabo in the ’90s. They are set of rules and protocols which two parties agree upon and have to follow. One of the main features is that they are immutable once deployed on the blockchain. It is widely used in the Ethereum blockchain. The main language used for writing smart contracts is Solidity.
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 –
JavaScriptVM (https://www.geeksforgeeks.org/hello-world-smart-contract-in-remix-ide/)Injected Web3Web3 Provider
JavaScriptVM (https://www.geeksforgeeks.org/hello-world-smart-contract-in-remix-ide/)
Injected Web3
Web3 Provider
This article explains how to deploy your contract by using Ganache as a web3 provider.
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 program to demonstrate pragma solidity ^0.4.26;  // Creating a contractcontract 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 –
Now your contract is completely ready to function. Make sure the compiler version matches the version of your solidity code. This is the basic implementation of GANACHE with solidity. 
Blockchain
Solidity
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Storage vs Memory in Solidity
Ethereum Blockchain - Getting Free Test Ethers For Rinkeby Test Network
How to Become a Blockchain Developer?
How to connect ReactJS with MetaMask ?
Proof of Work (PoW) Consensus
Storage vs Memory in Solidity
Solidity - Inheritance
Mathematical Operations in Solidity
How to Install Solidity in Windows?
Introduction to Solidity