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

Free lesson

EIP-7702: delegating an ordinary account to code

After this lesson: I can tell a safe EIP-7702 delegation from a dangerous one.

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

Smart features for the account you already have

EIP-7702 lets an ordinary account, an EOA, point at contract code and run it as its own. It came to Ethereum with the Pectra upgrade in 2025, so an existing address can batch payments or have its gas sponsored.

One signature sets it up, and one signature on the wrong page can give your account away.

By the end of this lesson

Note

I can tell a safe EIP-7702 delegation from a dangerous one.

Key words

WordWhat it meansExample
Delegationan EOA pointing at code that runs as the EOA
Authorisationthe signed permission that sets a delegation
Delegatethe contract an EOA points at
Designatorthe code an EOA is given0xef0100 then an address
Phishingtricking somebody into signing something harmful

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

How a delegation is set

The EOA signs an authorisation: a chain id, the delegate's address and its own nonce. A new kind of transaction, type 4, carries a list of them, and anybody may send it.

Once it lands, the EOA's code becomes 0xef0100 followed by the delegate's address. Calls to the EOA now run the delegate's code with the EOA's own address and balance, until the EOA delegates somewhere else.

Delegate, batch two payments, then undo it

Command
docker exec chain ./steps/delegate.sh

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

Worked example: what the lab printed

MomentSam's code
Before0x
After the delegation0xef0100 followed by BatchDelegate's address
Mallory calls executeBatchrefused: only the account itself
After delegating to the zero address0x

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

A careful delegate checks who is calling

Read the two delegates. BatchDelegate's executeBatch starts with one line: the caller must be the account itself. So only Sam, sending to his own address, can move his money.

OpenDelegate's execute has no such line. Once an account delegates to it, anybody can call it and move that account's money.

Find the caller check in the delegates

Command
docker exec chain grep -n "function\|msg.sender" src/Delegates.sol

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

Signing the wrong delegation

A fake page offers a reward and asks Sam to sign. What he signs is a delegation to OpenDelegate. Mallory sends it herself, paying the gas, and then calls execute on Sam's account.

In the lab Sam went from 5 ETH to 1 ETH in two transactions. He never sent anything, and his key never left him.

Watch a signed delegation empty an account

Command
docker exec chain ./steps/phishing.sh

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

A common mistake

Warning

Many people think signing is harmless when no money is sent. A delegation is a signature that hands the account's code to somebody else. Sign one only for code you trust, shown by your own wallet.

What a wallet should warn about

Warn on a delegate that is not on a short list of reviewed contracts. Warn on chain id 0, which makes one signature valid on every chain.

Remember that the EOA's key still controls everything, delegation or not. Storage stays behind when you switch delegates, and a delegate with an initialise function can be set up by somebody else first.

Try it: read a delegation from code

Code: python
code = "0xef01005fc8d32690cc91d4c39d9d3abcbd16989f875707"

prefix = code[:8]
rest = code[8:]
print("prefix:", prefix)
print("delegate: 0x" + rest)
print("hex digits after the prefix:", len(rest))
# Change code to "0x" and run it again. What should a wallet say?

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.