Skip to content

Jay-Sojitra/EIP7702_demo

Repository files navigation

EIP-7702 Batch Transaction Demo

This project demonstrates the use of EIP-7702 (Account Delegation for EOAs) with a BatchCallAndSponsor contract to perform multiple transactions in a single operation.

Setup Options

You can use this demo in two ways:

  1. Connect to Sepolia testnet using the existing deployed contract
  2. Deploy locally to Anvil (recommended for testing EIP-7702)

Option 1: Using Sepolia Testnet

  1. Make sure you have MetaMask installed and configured with Sepolia testnet
  2. Get Sepolia ETH from a faucet like https://sepoliafaucet.com/
  3. Run the application and connect your wallet
  4. Enter recipient addresses and amounts
  5. Send the batch transaction

Note: Even on Sepolia, you might encounter errors with EIP-7702 as it's a new standard that might not be fully supported yet.

Option 2: Deploying to Anvil (Local Development)

Anvil is Foundry's local Ethereum node that you can use for development and testing. Follow these steps to deploy the contract locally:

Prerequisites

  1. Install Foundry (includes Anvil):

    curl -L https://foundry.paradigm.xyz | bash
    foundryup
    
  2. Clone this repository and navigate to the project directory

Start Anvil with EIP-7702 support

Start Anvil with a higher fork block number to ensure EIP-7702 compatibility:

anvil --fork-url https://rpc.sepolia.org --fork-block-number 5000000 --chain-id 11155111

Alternatively, you can specify a custom chain ID:

anvil --fork-url https://rpc.sepolia.org --fork-block-number 5000000 --chain-id 31337

Deploy the Contract

  1. Create a new deployment script:
mkdir -p script
echo 'pragma solidity ^0.8.20;

import "forge-std/Script.sol";
import "../BatchCallAndSponsor.sol";

contract DeployBatchCall is Script {
    function run() external {
        uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
        vm.startBroadcast(deployerPrivateKey);
        
        BatchCallAndSponsor batchCall = new BatchCallAndSponsor();
        console.log("BatchCallAndSponsor deployed at:", address(batchCall));
        
        vm.stopBroadcast();
    }
}' > script/Deploy.s.sol
  1. Create a .env file with your private key or use one of Anvil's default accounts:
echo 'PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80' > .env
  1. Deploy the contract:
source .env
forge script script/Deploy.s.sol --rpc-url http://localhost:8545 --broadcast
  1. Update the CONTRACT_ADDRESS in src/app/page.tsx with the newly deployed contract address

  2. Start the web application:

npm run dev

Connecting MetaMask to Anvil

  1. Open MetaMask and add a new network:

    • Network Name: Anvil
    • RPC URL: http://localhost:8545
    • Chain ID: 31337 (or the chain ID you specified when starting Anvil)
    • Currency Symbol: ETH
  2. Import one of Anvil's default accounts:

    • In MetaMask, click on "Import Account"
    • Enter the private key: 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
    • This account has 10000 ETH on the Anvil network

Troubleshooting

If you encounter the error "External transactions to internal accounts cannot include data" even with Anvil, it means the EIP-7702 support isn't working properly. Try the following:

  1. Update Foundry to the latest version: foundryup
  2. Make sure you're using a high enough fork block number
  3. Check that your contract implementation follows EIP-7702 specifications

About EIP-7702

EIP-7702 (Account Delegation for EOAs) is a new Ethereum standard that allows Externally Owned Accounts (EOAs) to execute code through a smart contract without changing their identity. This enables EOAs to perform complex operations like batching multiple transactions into one, applying access control, and handling complex logic while maintaining their original address.

The implementation in this demo includes:

  1. A BatchCallAndSponsor contract that handles batch execution
  2. A transaction format that follows EIP-7702 specifications:
    • Transaction is sent to the sender's own address
    • Contract address is specified in EIP-7702 metadata
    • Batch instructions are encoded in the transaction data

For more information, see the EIP-7702 specification.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published