账户与状态
外部账户与合约
账户与状态 是 CoddyKit 上的免费 Web3 & DApp Development Fundamentals 课时。 这是第 4 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 Web3 & DApp Development Fundamentals 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 Web3 & DApp Development Fundamentals 课程共包含 4 节课。
本课时的部分内容尚未翻译,以英文显示。
What Is the World State?
Ethereum's world state is the complete snapshot of all accounts and their data at a given moment.
Every transaction transforms this state from one valid version to the next. Accounts are the building blocks of that state.
Two Types of Accounts
Ethereum has exactly two account types:
- Externally Owned Accounts (EOAs) — controlled by private keys (users)
- Contract Accounts — controlled by their code
Both share the same 20-byte address format.
Externally Owned Accounts
An EOA is controlled by a private key. It can initiate transactions: send ETH or call contracts.
EOAs have no code of their own — they are simply key-controlled accounts that humans (or bots) operate.
EOA {
address: 0xAbc...123
balance: 4.2 ETH
nonce: 17
code: none
}Contract Accounts
A contract account holds code (bytecode) and storage. It has no private key and cannot start a transaction on its own.
It only acts when called by an EOA or another contract, running its code in response.
Contract {
address: 0xDef...456
balance: 10 ETH
code: 0x6080604052...
storage: { slot0: ..., slot1: ... }
}The Four Account Fields
Every account stores four fields:
- nonce — transaction count (EOA) or contracts created (contract)
- balance — ETH held, in wei
- storageRoot — hash of the account's storage
- codeHash — hash of the account's code
EOA vs Contract Differences
The key distinction:
- Only EOAs can initiate transactions
- Only contracts have code and significant storage
- An EOA's codeHash is empty; a contract's is not
How State Changes
State changes only through transactions. A transaction can move ETH, deploy a contract, or call a contract that updates its storage.
After each block, the world state advances to a new, agreed-upon version.
The State Trie
All accounts are stored in a giant Merkle Patricia Trie. Its root hash — the state root — is recorded in each block header.
This single hash commits to the entire world state, just as a Merkle root commits to all transactions.
block header includes:
stateRoot -> all accounts
txRoot -> all transactions
receiptRoot -> all receiptsAccount Creation
An EOA effectively exists the moment a key pair is generated — no on-chain step is needed until it transacts.
A contract account is created when a deployment transaction runs constructor code and stores the resulting bytecode.
Smart Contract Interaction
To interact with a contract, an EOA sends a transaction specifying the contract address and the function data.
The EVM looks up the contract's code by its codeHash and executes it, possibly updating storage.
Putting It Together
Ethereum's state is a collection of accounts. EOAs are key-controlled and initiate transactions; contracts hold code and storage and react to calls.
The state root in each block commits to all of it.
Quick Check
Test your accounts knowledge.
Recap: Accounts and State
You learned that:
- Ethereum has EOAs (key-controlled) and contract accounts (code-controlled)
- Only EOAs can initiate transactions
- Each account has a nonce, balance, storageRoot, and codeHash
- The state root commits to all accounts
You have completed the Web3 fundamentals track.
常见问题解答
「账户与状态」课时是免费的吗?
是的 — 「账户与状态」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 Web3 & DApp Development Fundamentals 课程的其余内容,请升级到 CoddyKit PRO。 Web3 & DApp Development Fundamentals 课程共包含 4 节课。
「账户与状态」这节课中我会学到什么?
外部账户与合约 你通过在浏览器中直接运行的动手代码来练习 Web3 & DApp Development Fundamentals,全天候 AI 导师会在你学习这节课的过程中回答你的问题。
学习 Web3 & DApp Development Fundamentals 需要有经验吗?
无需任何先前经验。CoddyKit 上的 Web3 & DApp Development Fundamentals 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 4 节课,共 4 节。
「账户与状态」课时需要多长时间?
大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。
我能在这节 Web3 & DApp Development Fundamentals 课中编写并运行代码吗?
能。每节 Web3 & DApp Development Fundamentals 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。