6. How to install Ganache Blockchain on Windows and deploy smart contract using it:
6. How to install Ganache Blockchain on Windows and deploy smart contract using it:
- This part shows how to deploy smart contract to Ganache blockchain using remix.
- Install Ganache on Windows. Download the installer from below link. http://truffleframework.com/ganache/
- Or install it from command line
npm install –g ganache -cli
- What is ganache?? When you develop application, that application will be held in application server. In case of ethereum, the Ethereum blockchain will hold the smart contract. The blockchain is acting as application server. Ganache is simulation blockchain that runs locally in the system and simulate the Ethereum blockchin for you. It comes as GUI or command line.
- When you run ganache, you will see this image. You see many ether addresses. Each ether address has some money on it.
- There will be 10 accounts by defaults.
- The block tab will show the transections blocks
- The transection tab will show the transactions. Any transection done by smart contract will be shown on this window.
- The log tab will show all logs.
- To connect to Ganache block chain through the Remix, return to our previous example. URL to open Remix IDE https://remix.ethereum.org. When we compile the solidity code, we get byte code that we can deploy in Ethereum blockchain.
- Start new contract student.sol. Below is smart contract code
pragma solidity >=0.4.22 <0.6.0;
contract student {
string name;
uint age;
function setStudentDetails(string _name, uint _age) public{
name=_name;
age=_age;
}
function getStudentDetails() public view returns(string, uint){
return (name, age);
}
}
- To connect to Ganache block chain, go to run and choose to run with the third option Web3 provider. Assign connecting to the GUI Ganache server port http://localhost:7545. If you use the command line Ganache, use the server port http://localhost:8545
- It will show the following after connecting to Ganache. I will show 10 accounts of the Ganache block chain and the amount of ethereum on these accounts.
- Click deploy to deploy the smart contract. We get the following transection log:
- When we go to ganache dashboard, we can see the transection details
- When we send the student details: name and age. New transection will be sent which requires mining. It will use some gas fees that will be given to miner.
- The transaction is shown in Ganache as smart contract call from certain address to other address