Skip to content

lugondev/eip-7702

Repository files navigation

EIP-7702 Batch Transactions Demo

A modern demo implementing EIP-7702 for EOA account abstraction using wagmi/experimental useSendCalls:

πŸš€ Features

  • πŸš€ Zero Setup: No smart account deployment needed
  • 🦊 MetaMask Integration: Auto-prompts to upgrade EOA to smart account
  • ⚑ Atomic Execution: All transactions succeed or all fail
  • πŸ“¦ ERC-5792 Compliant: Using wallet_sendCalls standard
  • 🎯 Preset Templates: 8 ready-to-use templates for common use cases
  • β›½ Gas Estimation: Compare batch vs sequential gas costs
  • οΏ½ Transaction History: Auto-save and track all batch transactions
  • πŸ” Enhanced Result Viewer: Decode 50+ common function signatures
  • πŸ” Revoke Delegation: Reset account to normal EOA anytime

πŸ‘‰ Perfect for: Simple batch transactions, quick demos, minimal complexity

πŸ“š Documentation

πŸ“– In-App Documentation

  • /docs - Complete EIP-7702 specification, motivation, and technical details
  • /reference - Code examples, tutorials, and best practices
  • Demo - Live interactive demo with batch transactions

πŸ“ Project Guides

Main Features

🎯 Core Features

  • πŸ” Authorization Signing: Sign authorization to delegate EOA to smart contract
  • ⚑ Batch Transactions: Modern approach with useSendCalls - MetaMask automatically handles authorization
  • πŸ”‘ Session Keys: Manage session keys with expiration
  • πŸ“Š Monitoring: Track delegation status and activities

πŸ“š NEW Features (Phase 1 - October 2025)

  • πŸ” Revoke Delegation: Reset account to normal EOA - clear delegation anytime
    • UI component with status display in Info tab
    • Multiple revoke methods (Hook, Viem)
    • Complete documentation with examples
  • β›½ Gas Estimation: See gas costs before submitting - compare batch vs sequential
  • 🎯 Preset Templates: 8 ready-to-use templates for common use cases (DeFi, NFT, Transfers)
    • Multi-Token Transfer
    • DeFi Approve + Swap
    • NFT Batch Mint
    • Social Recovery Setup
    • Payment Batch
    • Test Templates (Simple & Self-transfers)

πŸ“š NEW Features (Phase 2 - October 2025)

  • πŸ“œ Transaction History: Auto-save all batch transactions with full details
    • Persistent localStorage storage (last 100 transactions)
    • Search and filter by status, date, or batch ID
    • Export/Import history as JSON
    • Statistics dashboard (total, confirmed, pending, failed)
    • Quick access to transaction details and receipts
  • πŸ” Enhanced Result Viewer: Detailed transaction decoder and analyzer
    • Function Decoder: Automatically decode 50+ common function signatures
      • ERC20: transfer, approve, transferFrom
      • ERC721/1155: safeTransferFrom, setApprovalForAll
      • Uniswap V2/V3: swap functions
      • WETH: deposit, withdraw
    • Transaction Details: Beautiful UI showing:
      • Decoded function names and arguments
      • Transaction type detection (Transfer, Swap, Approval, etc.)
      • Gas usage with color-coded warnings
      • Value transfers in ETH and wei
      • Raw data with copy-to-clipboard
    • Visual Timeline: Step-by-step execution flow
      • Transaction submitted timestamp
      • Confirmation with block number
      • Failed status with error messages
    • Share & Export: Share transaction details easily
    • Expandable Call Details: Click to view full details for each call
    • Etherscan Integration: Direct links to addresses and transactions

πŸ“š Documentation Features

  • πŸ“– Interactive Docs Page: Complete EIP-7702 specification with examples
  • πŸ’» Code Reference: Copy-paste ready code snippets for all use cases
  • 🎨 Visual Flow Diagrams: Step-by-step visualization of EIP-7702 and EIP-7710 processes
  • 🧭 Navigation Bar: Easy access to Demo, Docs, and Reference sections
  • βœ… Best Practices Guide: Production-ready recommendations and troubleshooting

Project Structure

eip-7702/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ app/                       # Next.js 15 App Router
β”‚   β”‚   β”œβ”€β”€ page.tsx              # Home/Demo page
β”‚   β”‚   β”œβ”€β”€ docs/                 # Documentation pages
β”‚   β”‚   β”‚   └── page.tsx          # EIP-7702 specification
β”‚   β”‚   β”œβ”€β”€ reference/            # Code reference pages
β”‚   β”‚   β”‚   └── page.tsx          # Examples & tutorials
β”‚   β”‚   β”œβ”€β”€ layout.tsx            # Root layout
β”‚   β”‚   └── globals.css           # Global styles
β”‚   β”œβ”€β”€ components/               # React components
β”‚   β”‚   β”œβ”€β”€ dashboard.tsx         # Main dashboard with 4 tabs
β”‚   β”‚   β”œβ”€β”€ batch-transaction-enhanced.tsx  # Batch transaction with templates
β”‚   β”‚   β”œβ”€β”€ batch-result-checker.tsx  # Check batch results
β”‚   β”‚   β”œβ”€β”€ transaction-history.tsx   # Transaction history viewer
β”‚   β”‚   β”œβ”€β”€ enhanced-result-viewer.tsx # Transaction decoder
β”‚   β”‚   β”œβ”€β”€ gas-estimation-display.tsx # Gas estimation
β”‚   β”‚   β”œβ”€β”€ compact-header-info.tsx   # Account info header
β”‚   β”‚   β”œβ”€β”€ delegation/           # Delegation components
β”‚   β”‚   β”‚   β”œβ”€β”€ revoke-delegation-button.tsx
β”‚   β”‚   β”‚   └── steps.tsx
β”‚   β”‚   β”œβ”€β”€ providers/            # Context providers
β”‚   β”‚   └── ui/                   # UI components (shadcn)
β”‚   β”œβ”€β”€ hooks/                    # Custom React hooks
β”‚   β”‚   β”œβ”€β”€ use-batch-calls.ts    # Batch transaction logic
β”‚   β”‚   β”œβ”€β”€ use-delegation-status.ts  # Check delegation status
β”‚   β”‚   β”œβ”€β”€ use-revoke-delegation.ts  # Revoke delegation
β”‚   β”‚   β”œβ”€β”€ use-gas-estimation.ts     # Gas estimation
β”‚   β”‚   └── use-transaction-history.ts # Transaction history
β”‚   β”œβ”€β”€ lib/                      # Utilities & config
β”‚   β”‚   β”œβ”€β”€ wagmi.ts             # Wagmi configuration
β”‚   β”‚   β”œβ”€β”€ utils.ts             # Helper functions
β”‚   β”‚   β”œβ”€β”€ batch-templates.ts   # Preset templates
β”‚   β”‚   β”œβ”€β”€ transaction-decoder.ts # Function decoder
β”‚   β”‚   β”œβ”€β”€ supported-chains.ts  # Chain configurations
β”‚   β”‚   └── abis/                # Contract ABIs
β”‚   └── types/                    # TypeScript types
└── README.md

System Requirements

  • Node.js >= 18.0.0
  • pnpm >= 8.0.0
  • Git

Quick Start

1. Install dependencies

# Clone repository
git clone <your-repo-url>
cd eip-7702

# Install dependencies
pnpm install

2. Setup environment

# Copy environment template
cp .env.local.example .env.local

# Get free Alchemy API key: https://www.alchemy.com/
# Update .env.local with your keys:
# NEXT_PUBLIC_SEPOLIA_RPC_URL=https://eth-sepolia.g.alchemy.com/v2/YOUR_KEY_HERE

# Contract addresses are pre-configured for Sepolia

3. Start application

# Start development server
pnpm dev

4. Test EIP-7702 Batch Transactions

  1. Open http://localhost:3000
  2. Connect MetaMask wallet
  3. Switch to Sepolia testnet
  4. Get test ETH from Sepolia Faucet
  5. Go to "Batch Transactions" tab
  6. Choose a template or create custom transactions
  7. Review gas estimation
  8. Click "Execute Batch"
  9. MetaMask prompts: "Upgrade to Smart Account?" β†’ Approve
  10. All transactions execute atomically! πŸŽ‰
  11. Check result in "Check Result" tab or on Etherscan

That's it! No manual authorization needed - MetaMask handles everything!

5. View Transaction History

  1. Go to "Transaction History" tab
  2. View all past batch transactions
  3. Search and filter by status or date
  4. Click on any transaction to see decoded details
  5. Export/Import history as JSON

6. Check Account Info & Revoke Delegation

  1. Go to "Info" tab
  2. View current delegation status
  3. See delegated contract address (if delegated)
  4. Click "Revoke Delegation" to reset to normal EOA
  5. Confirm transaction in MetaMask
  6. Account reverted to normal EOA! πŸŽ‰

Alternative Methods:

  • Use hook: const { revokeDelegation } = useRevokeDelegation()
  • MetaMask UI: Account Details β†’ Switch to EOA
  • See full guide: .docs/revoke-delegation-guide.md

Smart Contracts

🌟 EIP7702StatelessDelegator (Recommended)

Address: 0x63c0c19a282a1b52b07dd5a65b58948a07dae32b (Sepolia)

Contract used in real EIP-7702 transactions on Sepolia:

  • Stateless Design: No contract storage, lower gas costs
  • Simple & Efficient: Single execute function with Execution struct
  • Battle-tested: Used in production transactions
  • ERC-7579 Compatible: Follows Module standard
struct Execution {
    address target;
    uint256 value;
    bytes callData;
}

function execute(Execution calldata _execution) external payable;

Frontend Features

Tech Stack

  • Next.js 15 with App Router
  • React 19 with Server Components
  • Viem 2.37.12 for EIP-7702 support
  • Wagmi 2.x for wallet management
  • Tailwind CSS + Radix UI for styling
  • shadcn/ui for component library

Supported Networks

  • βœ… Ethereum Mainnet (Chain ID: 1)
  • βœ… BNB Smart Chain (Chain ID: 56)
  • βœ… BNB Smart Chain Testnet (Chain ID: 97)
  • βœ… Mega Testnet (Chain ID: 10008)
  • βœ… Base Mainnet (Chain ID: 8453)
  • βœ… Arbitrum One (Chain ID: 42161)
  • βœ… Sepolia Testnet (Chain ID: 11155111)

Wallet Connection

  • 🦊 MetaMask Only - Optimized for MetaMask wallet
  • No WalletConnect or other connectors
  • MetaMask automatically handles EIP-7702 authorization

Main Pages

Main Components

  • Dashboard: Main interface with 4 tabs (Batch Transactions, Check Result, Transaction History, Info)
  • BatchTransactionEnhanced:
    • Create multiple transaction calls
    • 8 preset templates for common use cases
    • Gas estimation before execution
    • Auto sign authorization + encode + send
    • Atomic execution (all or nothing)
    • Uses useSendCalls hook (ERC-5792)
  • BatchResultChecker: Check status and results of batch transactions
  • TransactionHistory:
    • View all past transactions
    • Search and filter capabilities
    • Export/Import as JSON
    • Statistics dashboard
  • EnhancedResultViewer:
    • Decode 50+ common function signatures
    • Transaction details with gas usage
    • Visual timeline of execution
    • Etherscan integration
  • RevokeDelegationButton: Component for revoking delegation
    • Status display with delegated address
    • Revoke button with loading states
    • Success/Error messages
    • Etherscan links
  • CompactHeaderInfo: Display address, balance, network info
  • WalletConnect: MetaMask connection with network detection

Hooks

  • useBatchCalls: Main hook for batch transactions
    • Uses wagmi's useSendCalls (ERC-5792)
    • Automatic authorization handling
    • Transaction status tracking
  • useRevokeDelegation: Revoke delegation logic
    • Multiple revoke methods (Viem, Contract)
    • Delegation status checking
    • Error handling with helpful messages
    • Transaction tracking
  • useDelegationStatus: Check delegation state
    • Check if account is delegated
    • Get delegated contract address
    • Auto-refresh capabilities
  • useGasEstimation: Estimate gas costs
    • Compare batch vs sequential execution
    • Calculate gas savings
    • Display estimated costs
  • useTransactionHistory: Manage transaction history
    • Auto-save transactions to localStorage
    • Search and filter capabilities
    • Export/Import as JSON

Key Features

βœ… Complete EIP-7702 Flow:

  1. Sign authorization β†’ 2. Encode call data β†’ 3. Send type 0x04 tx β†’ 4. Verify on Etherscan

βœ… Error Handling: Comprehensive error messages and recovery flows

βœ… Network Detection: Auto-detect wrong network and prompt switch

βœ… Loading States: Visual feedback for async operations

βœ… Transaction Tracking: Links to Etherscan for all transactions

Development Commands

# Install all dependencies
pnpm install

# Development server
pnpm dev

# Build for production
pnpm build

# Start production server
pnpm start

# Lint code
pnpm lint

# Type check
pnpm type-check

# Clean build artifacts
pnpm clean

Deployment

Deploy to Vercel (Recommended)

Option 1: Deploy via Vercel Dashboard (Easiest)

  1. Push your code to GitHub/GitLab/Bitbucket
  2. Go to vercel.com
  3. Click "Import Project"
  4. Select your repository
  5. Configure environment variables:
    • NEXT_PUBLIC_SEPOLIA_RPC_URL
    • NEXT_PUBLIC_PIMLICO_API_KEY (optional, for EIP-7710)
  6. Click "Deploy"
  7. Done! Your app is live πŸŽ‰

Option 2: Deploy via Vercel CLI

# Install Vercel CLI globally (if not installed)
pnpm add -g vercel

# Login to Vercel
vercel login

# Build and deploy to production
pnpm build
vercel --prod

# Or deploy preview (for testing)
vercel

Environment Variables Setup on Vercel

Go to your project settings β†’ Environment Variables and add:

NEXT_PUBLIC_SEPOLIA_RPC_URL=https://eth-sepolia.g.alchemy.com/v2/YOUR_KEY
NEXT_PUBLIC_PIMLICO_API_KEY=your_pimlico_api_key

Note: Environment variables with NEXT_PUBLIC_ prefix are exposed to the browser.

Deploy to Other Platforms

Netlify

pnpm build
# Deploy .next folder

Self-hosted (VPS/AWS/DigitalOcean)

# Build application
pnpm build

# Start production server
pnpm start

# Or use PM2 for process management
pm2 start pnpm --name "eip-7702" -- start

Production Considerations

  1. Ensure all environment variables are set
  2. Test thoroughly on Sepolia testnet first
  3. Monitor gas costs and transaction success rates
  4. Set up error tracking (e.g., Sentry)
  5. Configure proper CORS and security headers

Security Considerations

Frontend Security

  • βœ… Transaction confirmation UIs
  • βœ… Input sanitization and validation
  • βœ… Secure signature handling
  • βœ… Clear user prompts for all actions
  • βœ… Network validation before transactions

Troubleshooting

Common Issues

  1. MetaMask not prompting for authorization

    • Ensure you're on a supported network (Sepolia recommended)
    • Update MetaMask to latest version
    • Try refreshing the page and reconnecting wallet
  2. Batch transaction fails

    • Check gas limits and balances
    • Verify all transaction calls are valid
    • Review error messages in Check Result tab
  3. Cannot revoke delegation

    • Ensure account is actually delegated (check Info tab)
    • Try different revoke methods (see revoke guide)
    • Check network connection and gas balance
  4. Gas estimation showing N/A

    • Some networks may not support gas estimation
    • Transaction will still work, just estimate manually
    • Check console for detailed errors

Debug Tips

# Check build issues
pnpm build

# View detailed error logs
pnpm dev
# Then check browser console (F12)

# Clear Next.js cache
rm -rf .next
pnpm dev

Contributing

  1. Fork repository
  2. Create feature branch
  3. Follow code standards in .copilot.instructions.md
  4. Test your changes thoroughly
  5. Submit pull request with clear description

License

MIT License - see LICENSE file for more details.

Resources

About

A comprehensive demo implementing two modern approaches for EOA account abstraction

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages