Skip to content

peter-pratt/eip7702-gasless-tx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

EIP-7702 Gasless Transactions

This repository is forked from the QuickNode EIP-7702 Guide Examples and contains implementations for account abstraction using EIP-7702.

🎯 Overview

EIP-7702 introduces account abstraction by allowing Externally Owned Accounts (EOAs) to temporarily delegate their execution to smart contract code. This repository has this functionality through the BatchCallAndSponsor contract, which enables:

  • Gasless transactions sponsored by third parties
  • Batch execution of multiple calls in a single transaction
  • Signature-based authorization for enhanced security
  • Replay protection through nonce management

πŸ“‹ Prerequisites

  • Foundry toolkit
  • Node.js (for environment variable management)
  • Access to EIP-7702 compatible networks

πŸš€ Quick Start

1. Clone and Setup

git clone <this-repo>
cd gasless-transactions
forge install

$curl -L https://foundry.paradigm.xyz | bash
$ foundryup

#if needed
$ git rm --cached foundry
$ rm -rf .git/modules/foundry
$ cat .gitmodules

$ forge install foundry-rs/forge-std
$ forge install OpenZeppelin/openzeppelin-contracts

$ ls -la lib/
#

$ forge build

2. Environment Configuration

cp env.template .env
# Edit .env with your private keys and RPC URLs

3. Deploy Contract

# Deploy to Sepolia testnet
sh deploy network --sepolia

# Deploy to Base mainnet
sh deploy network --base

# Deploy to local network
sh deploy network --localhost

4. Submit Transactions

4.1 On Terminal

# Terminal 1 if needed inside the foundry folder
cd foundry 
run : ./target/release/anvil --hardfork prague --chain-id 31337

# Terminal 2
cd ..
source .env
# run step 3 Deploy Contract or run below script.
forge script script/DeployBatchCallAndSponsor.s.sol:DeployBatchCallAndSponsor --rpc-url $SEPOLIA_RPC_URL --private-key $PRIVATE_KEY --broadcast --verify --etherscan-api-key $ETHERSCAN_API_KEY -vvvv
forge build
forge script script/SendSponsoredEIP7702Transaction.s.sol:SendSponsoredEIP7702Transaction --rpc-url $SEPOLIA_RPC_URL --private-key $PRIVATE_KEY --broadcast -vvvv
forge script script/CheckDelegationStatus.s.sol:CheckDelegationStatus --rpc-url $SEPOLIA_RPC_URL -vvv
forge script script/RemoveDelegation.s.sol:RemoveDelegation --rpc-url $SEPOLIA_RPC_URL -vvv --broadcast

4.2 From UI

# Terminal 1 if needed inside the foundry folder
cd foundry 
run : ./target/release/anvil --hardfork prague --chain-id 31337

# Terminal 2
cd backend
run : npm start

# Terminal 2
cd ui
run : python3 -m http.server 3000
# ui is accessible on port localhost:3000

πŸ—οΈ Contract Architecture

BatchCallAndSponsor Contract

The main contract (src/BatchCallAndSponsor.sol) provides two execution methods:

  1. Signature-based execution: Any sponsor can submit batched calls with valid signatures
  2. Direct execution: The account itself can execute calls without signatures

Key Features:

  • βœ… Nonce-based replay protection
  • βœ… ECDSA signature verification
  • βœ… Batch call execution
  • βœ… Comprehensive event logging

🌐 Supported Networks

The deployment script supports the following networks:

Network Chain ID Key
Ethereum Mainnet 1 mainnet
Sepolia Testnet 11155111 sepolia
Polygon Mainnet 137 polygon
Base Mainnet 8453 base
BSC Mainnet 56 bsc
Localhost (Anvil) 31337 localhost

πŸ“ Project Structure

gasless-transactions/
β”œβ”€β”€ src/
β”‚   └── BatchCallAndSponsor.sol      # Main EIP-7702 contract
β”œβ”€β”€ script/
β”‚   β”œβ”€β”€ DeployBatchCallAndSponsor.s.sol  # Deployment script
β”‚   └── addressBook/                 # Per-chain contract addresses
β”‚       β”œβ”€β”€ 1.json                   # Ethereum Mainnet addresses
β”‚       β”œβ”€β”€ 11155111.json            # Sepolia Testnet addresses
β”‚       β”œβ”€β”€ 137.json                 # Polygon Mainnet addresses
β”‚       β”œβ”€β”€ 8453.json                # Base Mainnet addresses
β”‚       └── 56.json                  # BSC Mainnet addresses
β”œβ”€β”€ test/                            # Test files
β”œβ”€β”€ deploy                           # Network deployment script
β”œβ”€β”€ env.template                     # Environment variables template
└── foundry.toml                     # Foundry configuration

πŸ”§ Development Commands

Build & Test

forge build                    # Compile contracts
forge test                     # Run tests
forge test -vvv               # Run tests with verbose output

Static Analysis with Slither

# Run Slither with custom configuration
slither . --config-file .slither.config.json

# Run Slither with default settings
slither .

# Get help with Slither commands
slither --help

# Run Slither and save output to file
slither . --config-file .slither.config.json --json reports/slither-report.json

Note: The project includes a .slither.config.json file that excludes library dependencies and low-severity findings for cleaner output. Reports are automatically saved to reports/slither-report.json.

Deployment

sh deploy network --sepolia   # Deploy to Sepolia
sh deploy network --polygon   # Deploy to Polygon
sh deploy network --base      # Deploy to Base

Address Management

The project uses a per-chain addressBook system where each network has its own JSON file containing deployed contract addresses:

# View addresses for specific networks
cat script/addressBook/1.json           # Ethereum Mainnet
cat script/addressBook/11155111.json    # Sepolia Testnet
cat script/addressBook/137.json         # Polygon Mainnet
cat script/addressBook/8453.json        # Base Mainnet
cat script/addressBook/56.json          # BSC Mainnet

🌟 Key Components

Environment Variables (.env)

PRIVATE_KEY=your_private_key_here
SEPOLIA_RPC_URL=https://eth-sepolia.alchemyapi.io/v2/YOUR_KEY
POLYGON_RPC_URL=https://polygon-mainnet.alchemyapi.io/v2/YOUR_KEY
BASE_RPC_URL=https://base-mainnet.alchemyapi.io/v2/YOUR_KEY
BSC_RPC_URL=https://bsc-dataseed.binance.org

Deployment Features

  • βœ… Automatic network detection based on chain ID
  • βœ… Per-chain address book management with separate JSON files
  • βœ… Environment variable loading from .env
  • βœ… Cross-platform compatibility
  • βœ… Automatic address book updates after deployment

πŸ“š References

⚠️ Disclaimer

This is an internal development repository for educational and testing purposes. The contracts are experimental and should not be used in production without thorough security audits.

πŸ“„ License

MIT License - see LICENSE file for details.

About

A Foundry-based smart contract project that enables gasless batch transactions using EIP-7702 account abstraction. EOAs can temporarily delegate execution to smart contract code, allowing third-party sponsors to pay gas fees for users.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors