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

Free lesson

ERC-4337 or EIP-7702: which to use

After this lesson: I can choose between an ordinary account, a smart account and a delegation for a given need.

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

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

WordWhat it means
Key rotationreplacing an account's key with a new one
Recoverygetting control back after losing a key
Batchingseveral actions in one transaction
Overheadextra gas paid for extra features
Trade-offwhat 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

Command
docker exec chain ./steps/compare.sh

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

Worked example: what the lab printed

WayPaymentsGas
EOA sends ETH121000
Smart account, UserOperation1117159 for the bundle
EOA with an EIP-7702 delegation2 in one transaction52876, 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

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

Shown 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

NeedOrdinary accountSmart account (ERC-4337)Delegation (EIP-7702)
Keep my existing addressYesNo, a new addressYes
Survive a lost keyNoYes, with recoveryNo
Batch several actionsNoYesYes
Gas paid by somebody elseNoYes, a paymasterYes, with the right delegate
Cheapest single paymentYesNoClose

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

Code: python
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?

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.