How to Set up Ganche with Metamask?
Last Updated :
23 Sep, 2024
Ganache is a development tool in the Truffle Suite and is used for setting up a personal Ethereum Blockchain to deploy contracts, develop your applications, and run tests.
MetaMask is a software cryptocurrency wallet used to interact with the Ethereum blockchain.
Installing MetaMask:
1. Click on url and install the MetaMask extension. As of now, Metamask supports Chrome, Firefox, and other popular Chromium-based browsers(Brave, Edge).

2. Add the MetaMask extension to Google Chrome.

3. Then proceed to create a new wallet, accept terms and conditions and finish the installation process by setting up a password for your account.




4. Verify the installation by opening MetaMask from the toolbar.


Installing Ganache: Follow the steps below to install ganache.
1. Download the Executable Package File by visiting this link.

2. Alternatively, you can also install ganache-cli by executing the following command in the terminal. Omit sudo, if you are on a Windows platform and open the cmd in administrator mode.
sudo npm install -g ganache-cli
Import Ganache Account to Your Metamask Wallet:
Follow the steps below to import the ganache account to your MetaMask wallet.
Start the ganache blockchain and copy the private key of the desired account.
Ganache GUI
Ganache CLI



Add the local blockchain network in MetaMask by entering the RPC URL and Chain ID (Default Value: HTTP://127.0.0.1:8545 and 1337 respectively).


Create a new account by entering the copied private key.



MetaMask is now connected to the required node on the ganache blockchain successfully. Now, we will deploy a smart contract written in solidity and will use truffle to deploy it. This will consume some gas from our account and check whether the changes are reflected in our MetaMask wallet or not.
Steps to Deploy the Smart Contract
Installing truffle.
sudo npm install -g truffle
Verify the installation by executing.

Creating our smart contract.
mkdir folder_name
cd folder_name
truffle init
truffle create contract TestContract

Now, open the TestContract.sol in any code editor of your choice and update its content to-
Solidity
// Solidity program to implement
// the above approach
pragma solidity ^0.5.0;
contract TestContract
{
uint public counter = 0;
constructor() public
{
IncrementCounter();
}
function IncrementCounter() public
{
counter ++;
}
}
In the above code, we have created a smart contract TestContract that has a variable counter and a method IncrementCounter that increments the value of our variable by one.
Now, create a new file 2_deploy_contracts.js in the migration subfolder and import our smart contact.
JavaScript
// Javascript program to implement
// the above approach
var TestContract = artifacts.require("./TestContract.sol");
module.exports = function(deployer)
{
deployer.deploy(TestContract);
};
At last, compile the smart contract by executing :
truffle compile

Note: If experiencing any difficulties/errors in following the above steps, please have a look at the source code of the compiled contract.
Deploying the smart contract


After transaction.


Check the ethers left after the transaction.

Similar Reads
How to Install and Use Metamask on Google Chrome?
MetaMask is a type of cryptocurrency wallet that is used to interact with user interfaces of different web3 applications(For example, Mist browsers, DApps) and the regular web (For example, Google Chrome, Mozilla Firefox, websites). Its function is to inject a JavaScript library called web3.js into
3 min read
How to Build a Simple Web Server with Golang?
Golang is a procedural programming language ideal to build simple, reliable, and efficient software. Creating Web Servers Using Golang: Initialize a projectCreate a project folder with a .go file inside eg. server.go. Directory structure: The server.go file: [GFGTABS] Go package main import (
2 min read
How to Test Smart Contracts on the Ganache?
Smart contracts are self-executing pieces of code powered by blockchain technology which ensures transparency, immutability, and trust in a decentralized ecosystem. However smart contracts need thorough testing to ensure that they are flawless because once a smart contract is deployed in a main-net
6 min read
How to Use Google Maps Offline?
Quick Preview to Use Google Maps OfflineMaps! Open Offline Maps > Tap the Downloaded Map.The Downloaded Section will be present to use.Did you know that you can use Google Maps even without an internet connection? Yes, it's true! Navigating through places can be tough, especially when you don't h
3 min read
How to use MetaMask 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
3 min read
How to Install Heroku and Deploy a Static Website on Ubuntu?
Heroku is a cloud platform that provides a platform as a service(PAAS) to deploy either static or dynamic websites. Heroku is managed by Salesforce. Heroku allows CI/CD, code rollbacks, automatic deploys, Github integration, app metrics, and much more. Heroku allows building, running, and deploying
3 min read
How To Add My Website To Google Business
How to Connect My Website to Google My Business- Quick StepsLog in to your one.com control panel and go to Website Builder settings.If you want, make a listing.Connect your listing.You're done!Having your business listed on Google is super important. It helps people find you easily and makes your bu
6 min read
How to Install gRPC in Golang?
gRPC is RPC (Remote Protocol Communication) framework that was introduced by Google in the year 2015. The client-server communication is done with the help of procedure/functional calls. gRPC is very popular because its calls are easier to understand and mostly it doesn't require separate documentat
2 min read
How To Add My Business To Google Maps
Adding your business to Google Maps using Google My Business is a crucial step in enhancing your online presence and attracting more customers. Google My Business (GMB) is a free and easy-to-use tool that allows businesses to manage their online information across Google Search and Maps. Adding busi
9 min read
How to Setup Apache Web Server On Any Android Device?
In this article, we will learn how we can set up Apache Web Server On Any Android Device. For doing this we have to install the Termux app available on the play store. Termux is an Android terminal emulator and Linux environment application that works directly with no rooting or setup required. Term
2 min read