Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Free lesson

EOAs and smart accounts: what goes wrong

After this lesson: I can explain what goes wrong with an ordinary account that a smart account can fix.

60 min lesson2 commandsAccount abstraction lab: smart accounts, ERC-4337, paymasters and EIP-7702 on a local chain

Why one key is not enough

Account abstraction turns an Ethereum account into a program with rules you choose. It fixes what goes wrong with an ordinary account: one key, no way back if it is lost, and gas paid by the same account.

This module builds smart accounts on a local test chain of your own. Nothing in it is real money, and no coin prices or trading come into it.

By the end of this lesson

Note

I can explain what goes wrong with an ordinary account that a smart account can fix.

Key words

WordWhat it meansExample
EOAan externally owned account, controlled by one private key
Smart accountan account that is a contract with its own rules
Private keythe secret number that signs for an account
Gasthe fee a transaction pays for the work it causes
Signera key that may approve what an account does
Thresholdhow many signers must approve2 of 3

The cells students fill in are left blank in this preview.

An ordinary account is one key

An externally owned account, or EOA, is an address worked out from one private key. Whoever holds that key can sign any transaction from it.

An EOA has no code. So nothing can check a rule before money moves: no second signer, no daily limit and no undo. It must also hold ETH to pay gas for every transaction it sends.

Look at an EOA and a smart account

Command
docker exec chain ./steps/accounts.sh

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Worked example: what the lab printed

AccountCodeWhat else it showed
Alex's EOA0x, none at all5 ETH, nonce 0
Alex's smart account2950 bytes of contract codeOwner is Alex's key, 1 ETH
The app's key0x, none at all0 ETH, so its transaction was refused

The cells students fill in are left blank in this preview.

Three things go wrong with one key

Lose the key and the account is locked for ever. Nobody can reset it.

Leak the key and anybody can empty the account. There is no limit to stop them.

Gas comes from the same account. A new user with no ETH cannot do anything, even when an app would happily pay for them.

A smart account checks its own rules

A smart account is a contract. Before it acts, it runs its own check, so the rules can be anything code can say.

It can ask for two of three signers. It can let a friend or a second device recover it. It can give a game a weak key that only spends a little. And someone else can pay its gas.

Try it: two of three signers

Code: python
signers = ["alex", "bea", "cal"]
threshold = 2
approvals = ["alex", "cal"]

count = 0
for name in approvals:
    if name in signers:
        count = count + 1
print("approvals:", count, "needed:", threshold)
print("allowed:", count >= threshold)
# Change approvals to ["alex"] and run it again.

A common mistake

Warning

Many people think a smart account is safer just because it is code. It is only as safe as its rules. A bug in its check can let anybody in, so use simple rules and audited accounts.

Where the rules live

Read the lab's smart account. validateUserOp is the check: it recovers who signed and says yes or no. execute is what the account does once the check passes.

addSession adds a limited key, and setOwner changes the owner key while the address stays the same. An EOA can never change its key.

List the smart account's functions

Command
docker exec chain grep -n function src/SmartAccount.sol

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

About this lab and its source: Account abstraction lab: smart accounts, ERC-4337, paymasters and EIP-7702 on a local chain

Teaching a class? Set this module for your students with a teacher guide, marked assignments and a lab for every student.