This project demonstrates the use of EIP-7702 (Account Delegation for EOAs) with a BatchCallAndSponsor contract to perform multiple transactions in a single operation.
You can use this demo in two ways:
- Connect to Sepolia testnet using the existing deployed contract
- Deploy locally to Anvil (recommended for testing EIP-7702)
- Make sure you have MetaMask installed and configured with Sepolia testnet
- Get Sepolia ETH from a faucet like https://sepoliafaucet.com/
- Run the application and connect your wallet
- Enter recipient addresses and amounts
- 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.
Anvil is Foundry's local Ethereum node that you can use for development and testing. Follow these steps to deploy the contract locally:
-
Install Foundry (includes Anvil):
curl -L https://foundry.paradigm.xyz | bash foundryup -
Clone this repository and navigate to the project directory
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
- 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- Create a .env file with your private key or use one of Anvil's default accounts:
echo 'PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80' > .env
- Deploy the contract:
source .env
forge script script/Deploy.s.sol --rpc-url http://localhost:8545 --broadcast-
Update the CONTRACT_ADDRESS in src/app/page.tsx with the newly deployed contract address
-
Start the web application:
npm run dev-
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
-
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
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:
- Update Foundry to the latest version:
foundryup - Make sure you're using a high enough fork block number
- Check that your contract implementation follows EIP-7702 specifications
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:
- A BatchCallAndSponsor contract that handles batch execution
- 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.