What if your money and contracts could work for you automatically, without you lifting a finger?
Accounts (EOA vs contract accounts) in Blockchain / Solidity - When to Use Which
Imagine you want to send money or instructions on a blockchain. You try to do it all by hand, managing keys and rules yourself, like writing checks and contracts on paper for every transaction.
Doing this manually is slow and risky. You might lose keys, make mistakes in contracts, or forget steps. It's like handling all your bank and legal work without any digital help--errors and delays happen often.
Blockchain accounts split into two types: Externally Owned Accounts (EOA) controlled by private keys, and Contract Accounts that run code automatically. This setup makes sending money and running programs safe, fast, and reliable without manual hassle.
Send transaction by manually signing and verifying keys every time.Use EOA to sign and Contract Account to run code automatically on blockchain.This lets you build secure, automated applications on blockchain that handle money and logic without constant manual control.
Think of a vending machine on blockchain: your EOA pays money, and the Contract Account automatically delivers the product without a person involved.
Manual blockchain operations are slow and error-prone.
EOA and Contract Accounts split control and automation clearly.
This makes blockchain apps secure, fast, and easy to use.
Practice
Solution
Step 1: Understand what an EOA is
An EOA is controlled by a private key and represents a user or person on the blockchain.Step 2: Identify EOA capabilities
EOAs can send transactions and initiate actions, unlike contract accounts which run code.Final Answer:
An account controlled by a private key, used by people to send transactions. -> Option DQuick Check:
EOA = user-controlled account [OK]
- Confusing EOAs with contract accounts
- Thinking EOAs run code automatically
- Believing EOAs cannot send transactions
Solution
Step 1: Check Solidity address syntax
Addresses must be hexadecimal starting with 0x and enclosed in proper type declaration.Step 2: Validate each option
The declaration 'address payable contractAddr = 0x1234567890abcdef1234567890abcdef12345678;' uses correct type and hex format. String assignments without type declaration are invalid, missing 0x prefix fails, and invalid hex characters like 'GHI' are not allowed.Final Answer:
address payable contractAddr = 0x1234567890abcdef1234567890abcdef12345678; -> Option AQuick Check:
Valid Solidity address syntax = address payable contractAddr = 0x1234567890abcdef1234567890abcdef12345678; [OK]
- Omitting 0x prefix
- Using invalid hex characters
- Assigning address as a plain string without type
address sender = msg.sender; bool isContract = sender.code.length > 0;
What does
isContract indicate?Solution
Step 1: Understand
This checks the length of the code at the sender's address; contracts have code, EOAs do not.msg.sender.code.lengthStep 2: Interpret the boolean value
If code length > 0, sender is a contract account; otherwise, it's an EOA.Final Answer:
True ifsenderis a contract account, false if EOA. -> Option BQuick Check:
Code length > 0 means contract [OK]
- Assuming
msg.senderis always EOA - Confusing code length meaning
- Thinking EOAs have code
function sendEther(address recipient) public {
recipient.transfer(1 ether);
}When calling this function with an EOA address, it fails with an error. What is the likely cause?
Solution
Step 1: Understand transfer() requirements
transfer() requires the recipient address to be payable to receive ether.Step 2: Analyze recipient type
If recipient is declared asaddress(notaddress payable), transfer will fail even if it's an EOA.Final Answer:
The recipient address is not payable, so transfer fails. -> Option AQuick Check:
Useaddress payablefor ether transfers [OK]
- Thinking EOAs can't receive ether
- Missing payable keyword on function
- Assuming transfer only works with contracts
Solution
Step 1: Check recipient code length to identify EOA
EOAs have no code, sorecipient.code.length == 0confirms EOA.Step 2: Use require to enforce condition and transfer ether
If recipient is EOA, convert to payable and transfer 1 ether safely.Final Answer:
require(recipient.code.length == 0, "Recipient must be EOA"); payable(recipient).transfer(1 ether); -> Option CQuick Check:
Code length 0 means EOA, then transfer [OK]
- Checking for code length > 0 to find EOAs
- Not converting address to payable before transfer
- Using balance check instead of code length
Ready to prove it?
Pass the test and this pattern moves unknown
