How to use GANACHE Truffle Suite to Deploy a Smart Contract in Solidity (Blockchain)?
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 –
- 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 –
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 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.