ICE 2 – Ganache + MetaMask (Localhost)
This is a complete, start‑from‑zero walkthrough. You’ll install Ganache (local blockchain), add the MetaMask browser wallet, connect them, move test ETH, then deploy SimpleStorage from Remix. Use this page during lab.
0) What & Why (quick theory)
- Ganache – a private Ethereum blockchain on your computer. Gives you 10 funded accounts with fake ETH so you can test safely.
- MetaMask – a browser wallet (Chrome/Brave/Firefox/Edge extension). Holds accounts/keys and sends transactions.
- Remix – in‑browser Solidity IDE to compile and deploy contracts.
Together: Remix (code) → MetaMask (sign & send) → Ganache (executes). No real money or internet RPC required.
1) Install MetaMask (browser extension)
- Open your browser (Chrome/Brave/Edge/Firefox). Go to metamask.io/download.
- Click Add to Chrome (or your browser’s store) → Add extension.
- MetaMask opens a new tab. Click Create a new wallet → set a strong password.
- Write down your Secret Recovery Phrase (12 words). Store it offline. Never share it.
- You now have Account 1 on the default network (Ethereum Mainnet) with 0 ETH.
[screenshot placeholder: Chrome Web Store → “Add to Chrome”]
2) Download & Install Ganache
- Go to trufflesuite.com/ganache.
- Download the installer for your OS: Windows .exe, macOS .dmg, or Linux AppImage.
- Install and launch Ganache → click Quickstart Ethereum.
- On the top bar, note:
- RPC Server: e.g., http://127.0.0.1:7545
- Network/Chain ID: e.g., 1337 or 5777
- Scroll the accounts list. Each has ~100 ETH and a 🔑 key icon to reveal its private key.
[screenshot placeholder: Ganache Quickstart with RPC/IDs highlighted]
CLI alternative (optional)
# Install once
npm i -g ganache
# Run on port 7545 with chainId 1337
ganache --port 7545 --chain.chainId 1337 --wallet.totalAccounts 10
Heads‑up: Restarting Ganache resets the chain; deployed contracts disappear. Just deploy again.
3) Add Ganache as a Custom Network in MetaMask
- Open MetaMask → click the network pill at the top → Add network → Add a network manually.
- Enter values that match your Ganache window:
- Network name: Ganache Localhost
- New RPC URL: http://127.0.0.1:7545
- Chain ID: 1337 or 5777
- Currency symbol: ETH
- Save → switch to this network (label will show Localhost 8545/7545 depending on version).
Chain‑ID warning? Go to Settings → Networks, edit/delete any old “Localhost 8545”, then add fresh with the correct Chain ID from Ganache.
4) Import a funded Ganache account into MetaMask
- In Ganache, click the 🔑 key next to an account → copy the Private Key (starts with 0x, 64 hex chars).
- In MetaMask, click your avatar → Import account → choose Private key → paste → Import.
- You’ll see ~100 ETH on your Ganache network for that imported account.
Security: These keys are for local testing only. Never reuse on public networks (Mainnet/Sepolia/etc.).
[screenshot placeholder: MetaMask Import Account dialog]
5) Send ETH between accounts (localhost)
- Copy the recipient address (e.g., your teaching account).
- Switch to the imported Ganache account with funds.
- Click Send → paste the address → set amount (e.g., 5 ETH) → Next → Confirm.
- Transactions confirm in ~1s; balances update.
Verify in Ganache
Open the Transactions tab in Ganache; you’ll see the transfer with from/to, value, and gas.
6) Connect Remix → MetaMask → Ganache
- Open remix.ethereum.org.
- Create SimpleStorage.sol → paste code → Compile with 0.8.x.
- Go to Deploy & Run (plug icon) → Environment: Injected Provider – MetaMask → approve popup.
- Ensure the account shown has ETH on Localhost.
- Select SimpleStorage → click Deploy → confirm in MetaMask.
- Use the UI to call get() (expect 0) → set(123) → confirm → get() (now 123).
Gas estimation failed: usually means 0 ETH on the selected account, wrong network, or missing constructor args. Fund the account and try again.
Reference: SimpleStorage
pragma solidity ^0.8.0;
contract SimpleStorage {
uint256 storedData;
function set(uint256 x) public { storedData = x; }
function get() public view returns (uint256) { return storedData; }
}
FAQ / Troubleshooting
- I can’t find Import account: Click the circle avatar → Import account → Private key.
- MetaMask says Chain ID mismatch: Edit/delete old Localhost network in Settings → Networks, then add fresh with Ganache’s Chain ID.
- Remix still uses Remix VM: Change Environment to Injected Provider – MetaMask.
- No Deployed Contracts after refresh: Ganache chain reset; deploy again.
Submission (what to turn in)
- Screenshot: MetaMask on Ganache Localhost showing a funded account
- Screenshot: Remix with Injected Provider – MetaMask selected
- Screenshot: Deployed Contracts panel after
set(123)
and a get()
result of 123
- Short reflection: What’s the role of each tool? Why is Ganache ETH not real? What is Chain ID?