Bird
Raised Fist0
Blockchain / Solidityprogramming~20 mins

Ethereum networks (mainnet, testnet) in Blockchain / Solidity - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Ethereum Network Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Difference between Ethereum Mainnet and Testnet

Which statement correctly describes the difference between Ethereum Mainnet and Testnet?

AMainnet is the live Ethereum network where real transactions occur; Testnet is a separate network used for testing with no real value.
BMainnet is used only for testing smart contracts; Testnet is the live network for real transactions.
CMainnet and Testnet are identical networks but use different cryptocurrencies.
DTestnet is the main network for Ethereum, while Mainnet is deprecated.
Attempts:
2 left
💡 Hint

Think about where real money is involved versus where developers try out code safely.

❓ Predict Output
intermediate
2:00remaining
Identify the network from chain ID

What is the output of the following code snippet that checks the Ethereum network by chain ID?

Blockchain / Solidity
chain_id = 5
network = "Mainnet" if chain_id == 1 else "Goerli Testnet" if chain_id == 5 else "Unknown"
print(network)
AUnknown
BMainnet
CGoerli Testnet
DError
Attempts:
2 left
💡 Hint

Chain ID 1 is Mainnet; 5 is a popular testnet.

❓ Predict Output
advanced
2:00remaining
Output of transaction cost calculation on testnet

What is the output of this Python code that calculates the total cost of a transaction on a testnet?

Blockchain / Solidity
gas_price_gwei = 20
gas_used = 21000
total_cost_eth = (gas_price_gwei * gas_used) / 1_000_000_000
print(f"Total cost in ETH: {total_cost_eth}")
ATotal cost in ETH: 0.42
BTotal cost in ETH: 0.00042
CTotal cost in ETH: 420000000
DTotal cost in ETH: 0.0000021
Attempts:
2 left
💡 Hint

Remember 1 Gwei = 10⁻⁹ ETH. Multiply gas price by gas used, then convert.

🔧 Debug
advanced
2:00remaining
Identify the error in network selection code

What error does the following code raise when trying to select the Ethereum network?

def select_network(chain_id):
    if chain_id == 1:
        return "Mainnet"
    elif chain_id == 3:
        return "Ropsten Testnet"
    else:
        return "Unknown"

print(select_network(1))
ATypeError because chain_id is not an integer
BNo error, prints 'Mainnet'
CNameError because select_network is not defined
DSyntaxError due to assignment in if condition
Attempts:
2 left
💡 Hint

Check the if statement condition syntax carefully.

🚀 Application
expert
2:00remaining
Determine the number of unique Ethereum testnets in a list

Given the list of network names below, how many unique Ethereum testnets are included?

networks = ["Mainnet", "Goerli", "Ropsten", "Kovan", "Mainnet", "Goerli", "Rinkeby"]
A4
B3
C5
D6
Attempts:
2 left
💡 Hint

Count only testnets, ignore Mainnet duplicates.

Practice

(1/5)
1. Which Ethereum network should you use to test your smart contracts without risking real money?
easy
A. Private network
B. Mainnet
C. Testnet
D. Production network

Solution

  1. Step 1: Understand the purpose of testnets

    Testnets are designed for testing and development without real value at risk.
  2. Step 2: Compare with mainnet

    Mainnet is the live network where real transactions and value exist, so testing there risks real money.
  3. Final Answer:

    Testnet -> Option C
  4. Quick Check:

    Testnet = Safe testing network [OK]
Hint: Testnets are for safe practice, mainnet is for real use [OK]
Common Mistakes:
  • Confusing mainnet with testnet
  • Thinking private network is the default test environment
  • Assuming production network is safe for testing
2. Which of the following is the correct way to specify the Ethereum mainnet network ID in your configuration?
easy
A. "networkId": 1
B. "networkId": 3
C. "networkId": 42
D. "networkId": 4

Solution

  1. Step 1: Recall Ethereum network IDs

    Mainnet uses network ID 1, testnets have other IDs like 3 (Ropsten), 4 (Rinkeby), 42 (Kovan).
  2. Step 2: Match the ID to mainnet

    Network ID 1 corresponds to the Ethereum mainnet.
  3. Final Answer:

    "networkId": 1 -> Option A
  4. Quick Check:

    Mainnet networkId = 1 [OK]
Hint: Mainnet always uses network ID 1 [OK]
Common Mistakes:
  • Using testnet IDs for mainnet
  • Confusing networkId with chainId
  • Assuming networkId 0 is valid
3. Given the following code snippet to connect to an Ethereum network, what network will it connect to?
const provider = new ethers.providers.JsonRpcProvider("https://rinkeby.infura.io/v3/YOUR_PROJECT_ID");
const network = await provider.getNetwork();
console.log(network.name);
medium
A. "mainnet"
B. "rinkeby"
C. "ropsten"
D. "kovan"

Solution

  1. Step 1: Identify the RPC URL

    The URL contains "rinkeby.infura.io", indicating the Rinkeby testnet.
  2. Step 2: Understand provider.getNetwork()

    This method returns the network info based on the RPC URL, so it will return "rinkeby".
  3. Final Answer:

    "rinkeby" -> Option B
  4. Quick Check:

    RPC URL domain = rinkeby [OK]
Hint: Check the RPC URL domain for network name [OK]
Common Mistakes:
  • Assuming default is mainnet
  • Confusing testnet names
  • Ignoring the URL and guessing
4. You wrote this code to deploy a contract on Ropsten testnet but get an error:
const provider = new ethers.providers.JsonRpcProvider("https://mainnet.infura.io/v3/YOUR_PROJECT_ID");
const signer = provider.getSigner();
// deploy contract code here
What is the main issue?
medium
A. Incorrect contract deployment syntax
B. Provider does not support getSigner()
C. Using mainnet RPC URL instead of Ropsten testnet URL
D. Missing private key for signer

Solution

  1. Step 1: Examine the signer line

    JsonRpcProvider.getSigner() fails because public RPC providers like Infura do not expose signing accounts or private keys.
  2. Step 2: Correct approach for deployment

    Create a wallet signer: const wallet = new ethers.Wallet('0x-your-private-key', provider); const signer = wallet.connect(provider);
  3. Final Answer:

    Missing private key for signer -> Option D
  4. Quick Check:

    Use Wallet(privateKey, provider) for signing [OK]
Hint: Use ethers.Wallet(privateKey, provider) for signing deployments [OK]
Common Mistakes:
  • Using provider.getSigner() without wallet
  • Assuming getSigner() works without wallet
  • Overlooking private key requirement
5. You want to write a script that deploys a smart contract first on the Goerli testnet and then on the mainnet only if tests pass. Which approach correctly handles this?
hard
A. Deploy on Goerli testnet, run tests, then deploy on mainnet if tests pass
B. Deploy on mainnet first, then test on Goerli
C. Deploy simultaneously on both networks
D. Deploy only on mainnet and skip testnet

Solution

  1. Step 1: Understand deployment best practices

    Testnets like Goerli are used to test contracts safely before mainnet deployment.
  2. Step 2: Apply conditional deployment logic

    Deploy on Goerli, run tests, and only deploy on mainnet if tests succeed to avoid costly errors.
  3. Final Answer:

    Deploy on Goerli testnet, run tests, then deploy on mainnet if tests pass -> Option A
  4. Quick Check:

    Test on testnet before mainnet deployment [OK]
Hint: Test on Goerli first, then deploy mainnet if tests pass [OK]
Common Mistakes:
  • Deploying on mainnet before testing
  • Skipping testnets entirely
  • Deploying on both networks at once
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard