Two tools for one problem
ERC-4337 smart accounts and EIP-7702 delegations both give an account more than one key can. They suit different jobs: one is a new account with rules, the other is new code for an address you already have.
Choosing well means knowing what each costs and what each cannot do.
By the end of this lesson
Note
I can choose between an ordinary account, a smart account and a delegation for a given need.
Key words
| Word | What it means |
|---|---|
| Key rotation | replacing an account's key with a new one |
| Recovery | getting control back after losing a key |
| Batching | several actions in one transaction |
| Overhead | extra gas paid for extra features |
| Trade-off | what you give up to gain something else |
The cells students fill in are left blank in this preview.
The same payment, three ways
The lab pays the shop the same way three times and prints the gas. A plain EOA payment is the cheapest. A UserOperation adds the EntryPoint's checks and the bundler's transaction.
An EIP-7702 delegation sat between them, and it made two payments, not one, in one transaction.
Compare the gas, then change a key
docker exec chain ./steps/compare.shShown here, not run. Press Start lab to type it into your own lab’s terminal.
Worked example: what the lab printed
| Way | Payments | Gas |
|---|---|---|
| EOA sends ETH | 1 | 21000 |
| Smart account, UserOperation | 1 | 117159 for the bundle |
| EOA with an EIP-7702 delegation | 2 in one transaction | 52876, delegation included |
The cells students fill in are left blank in this preview.
Only a smart account can change its key
At the end of the Run, Alex's smart account handed its owner role to Nia's key through a UserOperation. Its address stayed the same.
An EOA with a delegation cannot do that. Its original key keeps full control whatever code it points at. So if that key is lost or leaked, a delegation does not save the account.
Find who may change the owner
docker exec chain grep -n -A1 "function setOwner" src/SmartAccount.solShown here, not run. Press Start lab to type it into your own lab’s terminal.
A common mistake
Warning
Many people think an EIP-7702 delegation turns an EOA into a full smart account. It adds code, but the old key still rules. When a lost or leaked key is the worry, move to a smart account.
Side by side
| Need | Ordinary account | Smart account (ERC-4337) | Delegation (EIP-7702) |
|---|---|---|---|
| Keep my existing address | Yes | No, a new address | Yes |
| Survive a lost key | No | Yes, with recovery | No |
| Batch several actions | No | Yes | Yes |
| Gas paid by somebody else | No | Yes, a paymaster | Yes, with the right delegate |
| Cheapest single payment | Yes | No | Close |
The cells students fill in are left blank in this preview.
They can work together
The two are not rivals. An EOA can delegate to code that is itself an ERC-4337 account, so the old address sends UserOperations and uses paymasters. EntryPoint version 0.8 supports this.
A simple rule of thumb: worried about keys, use a smart account. Want new features on an old address, delegate carefully. Need neither, keep it simple.
Try it: how much extra gas
plain = 21000
userop = 117159
extra = userop - plain
print("extra gas:", extra)
print("times the plain payment:", userop / plain)
# The delegation paid twice for 52876. What is that per payment?