EIP-7702 · Final · Core · 2024-05-07
EIP-7702: Set Code for EOAs
Lets an ordinary wallet address (EOA) point to smart-contract code, so existing accounts gain batching, gas sponsorship and custom authentication without moving funds to a new address.
What problem does it solve?
ERC-4337 gives smart-contract wallets great features, but only for new accounts. Hundreds of millions of existing wallets are EOAs: a bare key with no code. To benefit from account abstraction, users had to create a new smart account and migrate every asset and approval to it.
EIP-7702 (live since the Pectra upgrade, May 2025) lets an EOA keep its address and key while delegating its behaviour to a contract. The same address can now batch calls (approve + swap in one click), have gas paid by someone else, use passkeys or session keys, and set spending rules.
How it works
- A new transaction type
0x04(set-code transaction) carries anauthorization_list. Each entry is a tuple[chain_id, address, nonce, y_parity, r, s], signed by the EOA that wants to delegate. - When the transaction is processed, each authorizing account's code is set to a delegation indicator: the 23 bytes
0xef0100 ‖ address. From then on, any call to the EOA executes the code ataddressin the EOA's context (its storage, its balance,msg.senderchecks pass as the EOA). - The delegation is persistent until replaced. Signing a new authorization to a different address changes it; delegating to
address(0)removes it. chain_id = 0means the authorization is valid on every chain. The nonce is the EOA's own transaction nonce, which prevents replay.- The transaction sender can be a different account from the authorizer, so a relayer or ERC-4337 bundler can pay gas for a fresh EOA that holds no ETH.
- The EOA's private key still has full control: it can always send plain transactions and change the delegation.
Sample code
A tiny delegate contract that lets the EOA execute several calls at once (illustrative; real wallets add replay protection and signature checks):
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
contract BatchExecutor {
struct Call { address to; uint256 value; bytes data; }
// When delegated, `address(this)` is the EOA, so the EOA itself must be the caller.
function execute(Call[] calldata calls) external payable {
require(msg.sender == address(this), "not self");
for (uint256 i; i < calls.length; i++) {
(bool ok, bytes memory ret) = calls[i].to.call{value: calls[i].value}(calls[i].data);
require(ok, string(ret));
}
}
}
Delegating an EOA and using it in the same transaction (viem):
import { createWalletClient, http, encodeFunctionData, parseEther } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { sepolia } from "viem/chains";
const eoa = privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`);
const client = createWalletClient({ account: eoa, chain: sepolia, transport: http() });
// 1. Sign the authorization: "my address should run BatchExecutor's code".
const authorization = await client.signAuthorization({
contractAddress: BATCH_EXECUTOR_ADDRESS,
executor: "self", // the EOA itself sends the tx (nonce is bumped accordingly)
});
// 2. Send a type-4 transaction to *our own address*, calling the delegated code.
const hash = await client.sendTransaction({
authorizationList: [authorization],
to: eoa.address,
data: encodeFunctionData({
abi: batchExecutorAbi,
functionName: "execute",
args: [[
{ to: USDC, value: 0n, data: approveCalldata },
{ to: ROUTER, value: 0n, data: swapCalldata },
]],
}),
});
Checking whether an address is delegated:
const code = await publicClient.getCode({ address: eoa.address });
// "0xef0100" + 20-byte address => delegated to that contract
// undefined / "0x" => plain EOA
Things to know
- Never sign an authorization for a contract you do not trust. The delegate runs with full control of the account; a malicious delegate can drain it. Wallets whitelist audited delegates for this reason.
- Delegated code shares the EOA's storage across delegations. Switching from one wallet implementation to another needs careful storage layout (see ERC-7201 namespaced storage).
tx.origin == msg.sendercan no longer be used to prove "the caller is not a contract": an EOA can now have code.- The delegation indicator is not regular bytecode.
EXTCODESIZEreturns 23 andEXTCODECOPYreturns the indicator, not the delegate's code. - ERC-4337 bundlers accept 7702 accounts (
factory = 0x7702), so a delegated EOA can also send UserOperations with a paymaster.