How to Integrate EIP-7702: Adding Smart Account Features to EOAs
Ethereum’s traditional model uses Externally Owned Accounts (EOAs) that are simple.
Table of Contents
- Step 1: Initialize a Foundry Project & Set EVM Version
- Step 2: Write a Delegate Contract in Solidity
- Step 3: Write Foundry Tests with Delegation Cheatcodes
- Step 4: Deploy
- Step 5: Send Delegation via CLI with
cast
Why EIP-7702 Was Proposed?
Ethereum’s traditional model uses Externally Owned Accounts (EOAs) that are simple. they're tied to a private key and can only execute basic operations like signing transactions. This limits how users and developers can interact with the blockchain complex features like batch transactions, gas sponsorship, or spending limits require full smart contract wallets, which introduce friction and fragmentation.
EIP-7702, introduced as part of the Pectra upgrade, aims to bridge this gap. It allows EOAs to temporarily behave like smart contract accounts for a single transaction, enabling advanced features without requiring users to migrate to new wallets or smart contract accounts.
This proposal addresses key developer and UX pain points:
- Enables transaction batching (e.g., approval + swap in one go), reducing gas and complexity .
- Supports gas sponsorship, allowing third parties to pay fees making onboarding smoother and enabling metatransactions.
- Allows privilege de-escalation, such as sub-keys limited to certain permissions (like spending caps) improving usability without compromising control.
- Offers features like social recovery, alternative authentication, and token-based gas payments enhancing UX and flexibility.
- Aligns with the broader vision of account abstraction while preserving EOA identity and compatibility.
EIP-7702 gives EOAs smart account capabilities without sacrificing simplicity or compatibility.
What Is EIP-7702 & Why It Matters
EIP-7702 introduces a new transaction type 0x04 setcodethat enables an EOA to include smart contract-like execution logic (via a "delegation designator") only for that transaction. After it's processed, the EOA reverts to its standard behavior
This change preserves the EOA's address, private key, and UX while adding:
- Batch operations
- Gas-free or sponsored interactions
- Custom policy logic (like spending limits or social recovery fallback)
- Broader compatibility with ERC-4337 and account abstraction plans.
EIP-7702 Integration Steps
Step 1: Initialize a Foundry Project & Set EVM Version
01forge init eip7702-foundry02cd eip7702-foundryIn your foundry.toml, specify an EVM version supporting the necessary features:
01[default]02evm_version = "prague"This makes Foundry’s cheatcodes like signDelegation and attachDelegation available.
Step 2: Write a Delegate Contract in Solidity
Create src/SimpleDelegate.sol:
01// SPDX-License-Identifier: MIT02pragma solidity ^0.8.17;03 04contract SimpleDelegate {05 struct Call { bytes data; address to; uint256 value; }06 event Executed(address indexed to, uint256 value, bytes data);07 08 function execute(Call[] memory calls) external payable {09 for (uint i = 0; i < calls.length; i++) {10 (bool success, bytes memory result) =11 calls[i].to.call{value: calls[i].value}(calls[i].data);12 require(success, string(result));13 emit Executed(calls[i].to, calls[i].value, calls[i].data);14 }15 }16 17 receive() external payable {}18}This contract enables batching of arbitrary calls ideal for EIP-7702 delegation.
Step 3: Write Foundry Tests with Delegation Cheatcodes
Create test/SimpleDelegate.t.sol:
01// SPDX-License-Identifier: MIT02pragma solidity ^0.8.17;03 04import "forge-std/Test.sol";05import "../src/SimpleDelegate.sol";06 07contract EIP7702Test is Test {08 SimpleDelegate public delegate;09 10 function setUp() public {11 delegate = new SimpleDelegate();12 }13 14 function testBatchCallWithDelegation() public {15 // Sign delegation and attach in one shot16 vm.signAndAttachDelegation(address(delegate), vm.envUint("PRIVATE_KEY"));17 18 // Execute batched transaction via delegate19 SimpleDelegate.Call[] memory calls = new SimpleDelegate.Call[](1);20 calls[0] = SimpleDelegate.Call({21 to: address(this),22 value: 0,23 data: abi.encodeWithSignature("dummyFunc()")24 02 delegation25 delegate.execute{value: 0}(calls);26 // Add appropriate assertions/events here27 }28 29 function dummyFunc() public {}30}This illustrates signing and attaching the delegation in one step using Foundry’s built-in cheatcodes.
Step 4: Deploy
Run your tests with:
01forge test -vvFoundry will deploy the delegate contract, apply the signed delegation to your EOA, and allow execution of batch logic as if the EOA were a contract all within the test environment.
Step 5: Send Delegation via CLI with cast
You can also use Foundry’s cast send command to broadcast an actual EIP-7702 transaction:
01cast send 0xYourEOAAddress --auth 0xSignedAuthorization --rpc-url http://localhost:8545--authaccepts a hex-encoded signed authorization (chainId, delegate address, nonce, signature parts).
Pair this with deployme and a prepared authorization list to complete delegation on a real or forked network.
When to Choose EIP-7702 vs ERC-4337
Use EIP-7702 when:
- Maintaining the same EOA address across chains matters.
- You need lightweight upgrades with minimal upfront gas.
- Backward compatibility and simpler UX are priorities. ([Alchemy][7])
Use ERC-4337 when:
- You require full programmability and customizability in account logic.
Combining Both: Use EIP-7702 for address continuity, and ERC-4337 for deep abstraction capabilities.
Tool Support
- Hardhat + GitHub Example: Check out the
woogie96/eip7702-examplerepo, a full Hardhat project demonstrating batch delegation logic Luganodes | Hassle-Free Staking. - MetaMask Delegation Toolkit: Offers developer flow to upgrade EOAs into smart accounts with minimal friction ethereum.org.
- Wallet UX Templates & dApp Interfaces: Enhanced payment flows for example, paying gas with USDC or other tokens are already being rolled out by wallets like MetaMask and platforms supporting ERC-5792/6900 standards Bitpowr, Metana
TL;DR
- Deploy delegate smart contract
- Sign delegation authorization
- Send
0x04setcode transaction via your preferred tooling - Use the EOA for smart account behavior
- Revoke delegation when needed
About Us
At SC Audit Studio, we specialize in protocols security assessments. Our team of experts is dedicated to ensuring the safety and reliability of your projects. Partner with us to enhance your project's security and gain peace of mind.
Reach out to us for queries and security assessments!