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)

Together: Remix (code) → MetaMask (sign & send) → Ganache (executes). No real money or internet RPC required.

1) Install MetaMask (browser extension)

  1. Open your browser (Chrome/Brave/Edge/Firefox). Go to metamask.io/download.
  2. Click Add to Chrome (or your browser’s store) → Add extension.
  3. MetaMask opens a new tab. Click Create a new wallet → set a strong password.
  4. Write down your Secret Recovery Phrase (12 words). Store it offline. Never share it.
  5. 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

  1. Go to trufflesuite.com/ganache.
  2. Download the installer for your OS: Windows .exe, macOS .dmg, or Linux AppImage.
  3. Install and launch Ganache → click Quickstart Ethereum.
  4. On the top bar, note:
    • RPC Server: e.g., http://127.0.0.1:7545
    • Network/Chain ID: e.g., 1337 or 5777
  5. 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

  1. Open MetaMask → click the network pill at the top → Add networkAdd a network manually.
  2. 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
  3. 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

  1. In Ganache, click the 🔑 key next to an account → copy the Private Key (starts with 0x, 64 hex chars).
  2. In MetaMask, click your avatar → Import account → choose Private key → paste → Import.
  3. 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)

  1. Copy the recipient address (e.g., your teaching account).
  2. Switch to the imported Ganache account with funds.
  3. Click Send → paste the address → set amount (e.g., 5 ETH) → NextConfirm.
  4. 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

  1. Open remix.ethereum.org.
  2. Create SimpleStorage.sol → paste code → Compile with 0.8.x.
  3. Go to Deploy & Run (plug icon) → Environment: Injected Provider – MetaMask → approve popup.
  4. Ensure the account shown has ETH on Localhost.
  5. Select SimpleStorage → click Deploy → confirm in MetaMask.
  6. 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)