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
| Word | What it means | Example |
|---|---|---|
| EOA | an externally owned account, controlled by one private key | |
| Smart account | an account that is a contract with its own rules | |
| Private key | the secret number that signs for an account | |
| Gas | the fee a transaction pays for the work it causes | |
| Signer | a key that may approve what an account does | |
| Threshold | how many signers must approve | 2 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
docker exec chain ./steps/accounts.shShown here, not run. Press Start lab to type it into your own lab’s terminal.
Worked example: what the lab printed
| Account | Code | What else it showed |
|---|---|---|
| Alex's EOA | 0x, none at all | 5 ETH, nonce 0 |
| Alex's smart account | 2950 bytes of contract code | Owner is Alex's key, 1 ETH |
| The app's key | 0x, none at all | 0 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
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
docker exec chain grep -n function src/SmartAccount.solShown here, not run. Press Start lab to type it into your own lab’s terminal.