DEV Community

Fofie Fopa Elisabeth
Fofie Fopa Elisabeth

Posted on

Ethereum Basics (Chapter 2)

Introduction

We've all heard about Ethereum, but do we know what it is? Ethereum isn’t just a cryptocurrency: it’s a programmable, decentralized world computer. In this guide, we’ll walk through the essentials from Chapter 2 of the
Ethereum Book, using real-world analogies and simple examples so you can:

  • Understand ether and its denominations
  • Choose and set up an Ethereum wallet
  • Interact with test networks
  • Write, compile, deploy, and call your first Solidity contract

1. Ether Currency Units

Just like you wouldn’t pay for a coffee in cents when you think in dollars, Ethereum has its own units:wei is the smallest unit (like a cent).
gwei (gigawei) is commonly used for gas prices—think of it as the “dollar” you see when you pay transaction fees.
1 ETH = 1 × 10¹⁸ wei, just like $1 000 = 1 × 10³ dollars in some contexts.
Real-World Example: If a transaction costs 20 gwei per gas and uses 21 000 gas, you pay
20 gwei × 21 000 = 420 000 gwei = 0.00042 ETH (about $0.75 if ETH≈$1 800).

2. Choosing and Setting Up an Ethereum Wallet

A wallet is your gateway and password manager for Ethereum:
What a wallet does:

  • Stores your private key (think of it like the PIN to your bank account).
  • Creates and broadcasts transactions on your behalf. Types of wallets:
  • Browser extension (e.g MetaMask)
  • Mobile/Desktop apps (e.g Jaxx, MyEtherWallet)
  • Hardware wallets (like a USB stick, for high security) Security Tips:
  • Never share your private key or mnemonic words!
  • Back up your mnemonic on paper in a secure place (like a safe).
  • Always test with small amounts before sending large sums. Analogy: Think of your wallet’s private key as the PIN to an ATM card. If someone knows it and has your card, they can withdraw your money.

3. Exploring Test Networks (Testnets)

Before using real ETH (which costs real money), you can practice on testnets, which are free and risk-free:
Test ETH has zero real-world value but behaves identically.
Use faucets (websites that dispense test ETH) to fund your test wallet.
Tip: Always confirm you’re on the correct network in your wallet (e.g., MetaMask). Sending real ETH to a testnet address will lose your funds.

4. Installing and Using MetaMask

MetaMask is the most popular browser extension wallet:
Install:
In Chrome/Firefox, go to the web store → search “MetaMask” → verify publisher and ID → “Add to Browser.”
Create a Wallet:
Set a strong password.
Back up the 12-word mnemonic on paper (don’t store it digitally!).
Switch Networks:
Click the network dropdown (defaults to “Main Ethereum Network”).
Select “Ropsten Test Network” to practice without real funds.

5. Getting and Sending Test Ether

Request Test ETH:
In MetaMask (on Ropsten), click Deposit → Ropsten Faucet.
On the faucet page, click Request 1 ETH.
Watch your balance update in MetaMask after the transaction is mined.
Send Test ETH:
Click Send, enter a recipient address, amount (e.g., 0.1 ETH), and confirm.
Remember to leave extra ETH for gas fees (≈0.000063 ETH for a simple transfer at 3 gwei).
Real-World Example: Trying to send all your 1 ETH will fail because you need ETH left over for gas—similar to needing change for a $20 bill to pay a $19.75 taxi fare.

6. Writing Your First Solidity Contract: Faucet.sol

`A “faucet” contract hands out small amounts of ETH on demand:
// SPDX-License-Identifier: CC-BY-SA-4.0
pragma solidity ^0.6.0;

contract Faucet {
// Accept any incoming ETH:
receive() external payable {}

// Allow withdrawal up to 0.1 ETH:
function withdraw(uint withdraw_amount) public {
    require(withdraw_amount <= 0.1 ether, "Max 0.1 ETH");
    msg.sender.transfer(withdraw_amount);
}
Enter fullscreen mode Exit fullscreen mode

}`

  • receive() external payable {} lets the contract accept ETH (like putting money into a bank).
  • withdraw(...) checks the requested amount with require, then sends ETH back. Analogy: It’s like a vending machine that only dispenses up to $0.10 per request.

7. Compiling and Deploying with Remix

Remix is an in-browser IDE for Solidity:

  • Open Remix: Go to https://remix.ethereum.org.
  • New File: Click the “+” icon, name it Faucet.sol, and paste the code above.
  • Compile: Select compiler version 0.6.0, then hit Compile Faucet.sol.
  • Deploy to Ropsten: In the Run tab, choose Injected Web3 (connects to MetaMask). Confirm MetaMask is set to Ropsten. Click Deploy, approve the gas fee in MetaMask, and wait ~30 seconds for mining. You’ll see a new contract instance appear in Remix, complete with its address.

8. Interacting with Your Contract

Fund the Contract:
In MetaMask, send 1 ETH to the contract’s address (this invokes receive()).
Withdraw Funds:
Back in Remix’s Run tab, find your deployed Faucet instance.
Enter 100000000000000000 (0.1 ETH in wei) in the withdraw field.
Click withdraw, confirm in MetaMask, and watch the ETH return to your account.
Verify on Etherscan:
Copy the contract address and paste into ropsten.etherscan.io.
Switch to Internal Txns to see the contract’s outbound transfer to you.

Top comments (0)