BC5: Ethereum in practice: accounts, transactions, gas and networks

Lesson 3 of 5 · reading 15–25 minutes; practice and project time is on the module page

Gas and fees

🎯You'll be able to

Work out a transaction's fee, set gas sensibly, and explain why fees change.

🏠The everyday picture

A taxi meter: the distance is the work (gas used), the rate per kilometre is the price (fee per gas), and in rush hour the rate goes up.

📘What it really is

📝A worked example

Input: a deposit uses 50,000 gas; base fee 20 gwei, tip 2 gwei (1 gwei is 10^9 wei). These figures are illustrative.

Steps:

  1. Fee per gas = 20 + 2 = 22 gwei.
  2. Fee = 50,000 × 22 gwei = 1,100,000 gwei = 0.0011 ether.
  3. If the network gets busy and the base fee doubles, the same deposit costs about twice as much.

Expected output: 0.0011 ether at these illustrative prices, and an understanding of why it changes.

🌍Where it's used

📝Case scenario

A contract looped over every member to pay interest. With 50 members it worked; with 2,000, the loop needed more gas than a block allows, and the function could no longer run at all. Letting each member claim their own interest fixed it.

🖱️Try it

A transfer uses 21,000 gas at a total of 30 gwei per gas. What's the fee in ether? Success: 0.00063 ether.

⚠️Common mistakes

🛠️For your project

Project 3's app estimates gas before each deposit, so a refused deposit is explained before anything is sent (test 7).

✅Quick check

What happens to the fee when a transaction runs out of gas?

Show the answer

It reverts, but the gas used is still paid.

Why does the base fee rise?

Show the answer

Because blocks are fuller than the target, so demand is high.

← PreviousTransactions, receipts and logs
ProLearners Assist