0
0
Blockchain / Solidityprogramming~15 mins

Accounts (EOA vs contract accounts) in Blockchain / Solidity - Hands-On Comparison

Choose your learning style9 modes available
Understanding Accounts: EOA vs Contract Accounts
📖 Scenario: Imagine you are learning about blockchain accounts. There are two main types: Externally Owned Accounts (EOA), which are controlled by people, and Contract Accounts, which are controlled by code (smart contracts).We will create a simple program to represent these accounts and check their types.
🎯 Goal: You will build a small program that stores a list of accounts with their types and then filters out only the EOAs.
📋 What You'll Learn
Create a dictionary called accounts with account addresses as keys and their types ('EOA' or 'Contract') as values.
Create a variable called filter_type and set it to the string 'EOA'.
Use a dictionary comprehension to create a new dictionary called eoa_accounts that contains only the accounts of type 'EOA'.
Print the eoa_accounts dictionary.
💡 Why This Matters
🌍 Real World
Blockchain developers often need to distinguish between EOAs and contract accounts to manage transactions and smart contract interactions correctly.
💼 Career
Understanding account types is essential for blockchain engineers, smart contract developers, and security analysts working with Ethereum or similar platforms.
Progress0 / 4 steps
1
Create the accounts dictionary
Create a dictionary called accounts with these exact entries: '0xabc123': 'EOA', '0xdef456': 'Contract', '0xghi789': 'EOA', '0xjkl012': 'Contract'.
Blockchain / Solidity
Need a hint?

Use curly braces {} to create a dictionary with the exact keys and values.

2
Set the filter type
Create a variable called filter_type and set it to the string 'EOA'.
Blockchain / Solidity
Need a hint?

Assign the string 'EOA' to the variable named filter_type.

3
Filter EOAs using dictionary comprehension
Use a dictionary comprehension to create a new dictionary called eoa_accounts that contains only the accounts from accounts where the value equals filter_type. Use for address, acc_type in accounts.items() in your comprehension.
Blockchain / Solidity
Need a hint?

Use {key: value for key, value in dict.items() if condition} to filter the dictionary.

4
Print the filtered EOAs
Write print(eoa_accounts) to display the dictionary of EOAs.
Blockchain / Solidity
Need a hint?

Use the print function to show the eoa_accounts dictionary.