|
| 1 | +# EIP-7702 with Para + Alchemy Setup |
| 2 | + |
| 3 | +Gasless USDC transactions for Para wallets using EIP-7702 temporary account upgrades and Alchemy Account Kit. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +- **What**: EOA wallets (Para) get temporary smart account functionality for gas sponsorship |
| 8 | +- **How**: EIP-7702 authorization + Alchemy Gas Manager |
| 9 | +- **Benefit**: Zero gas fees for USDC transfers on Base |
| 10 | + |
| 11 | +## Architecture |
| 12 | + |
| 13 | +``` |
| 14 | +Para Wallet (EOA) |
| 15 | + ↓ |
| 16 | +Custom Signature Utilities (para-signature-utils.ts) |
| 17 | + ↓ |
| 18 | +EIP-7702 Authorization Signing |
| 19 | + ↓ |
| 20 | +Alchemy Modular Account V2 (mode: "7702") |
| 21 | + ↓ |
| 22 | +Alchemy Gas Manager (sponsored transaction) |
| 23 | + ↓ |
| 24 | +Base Network (confirmed transaction) |
| 25 | +``` |
| 26 | + |
| 27 | +## Key Files |
| 28 | + |
| 29 | +### 1. Signature Utilities |
| 30 | +**`src/lib/para-signature-utils.ts`** |
| 31 | +- Custom signing methods that bypass Ethereum Signed Message prefix |
| 32 | +- Uses viem's `hashAuthorization`, `hashMessage`, `hashTypedData` |
| 33 | +- Properly formats v-values (0/1 for EIP-7702, 27/28 for standard) |
| 34 | + |
| 35 | +### 2. Configuration |
| 36 | +**`src/config/eip7702.ts`** |
| 37 | +```typescript |
| 38 | +export const EIP7702_CONFIG = { |
| 39 | + ENABLED: process.env.NEXT_PUBLIC_ENABLE_EIP7702 === 'true', |
| 40 | + ALCHEMY_RPC_URL: process.env.NEXT_PUBLIC_ALCHEMY_RPC_URL, |
| 41 | + ALCHEMY_GAS_POLICY_ID: process.env.NEXT_PUBLIC_ALCHEMY_GAS_POLICY_ID, |
| 42 | + USDC_CONTRACT: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913', |
| 43 | + USDC_DECIMALS: 6, |
| 44 | + CHAIN_ID: 8453, // Base |
| 45 | +}; |
| 46 | +``` |
| 47 | + |
| 48 | +### 3. Transaction Hook |
| 49 | +**`src/hooks/useParaEIP7702Transaction.ts`** |
| 50 | +- Creates extended viem account with custom signing methods |
| 51 | +- Overrides: `signAuthorization`, `signMessage`, `signTypedData` |
| 52 | +- Uses Alchemy's `createModularAccountV2Client` with `mode: "7702"` |
| 53 | + |
| 54 | +### 4. Router |
| 55 | +**`src/hooks/useTransactionRouter.ts`** |
| 56 | +- Switches between legacy (backend relayer) and EIP-7702 (Alchemy) systems |
| 57 | +- Based on `NEXT_PUBLIC_ENABLE_EIP7702` feature flag |
| 58 | + |
| 59 | +## Environment Variables |
| 60 | + |
| 61 | +```bash |
| 62 | +# Enable EIP-7702 |
| 63 | +NEXT_PUBLIC_ENABLE_EIP7702=true |
| 64 | + |
| 65 | +# Alchemy Configuration |
| 66 | +NEXT_PUBLIC_ALCHEMY_RPC_URL=https://base-mainnet.g.alchemy.com/v2/YOUR_API_KEY |
| 67 | +NEXT_PUBLIC_ALCHEMY_GAS_POLICY_ID=your-gas-policy-id |
| 68 | +``` |
| 69 | + |
| 70 | +## Alchemy Setup |
| 71 | + |
| 72 | +1. **Create Account**: https://dashboard.alchemy.com |
| 73 | +2. **Create App**: Base Mainnet |
| 74 | +3. **Configure Gas Manager**: |
| 75 | + - Go to Gas Manager |
| 76 | + - Create Policy |
| 77 | + - Set spending limits |
| 78 | + - Configure allowlist (optional) |
| 79 | +4. **Copy Credentials**: |
| 80 | + - RPC URL from app dashboard |
| 81 | + - Policy ID from Gas Manager |
| 82 | + |
| 83 | +## How It Works |
| 84 | + |
| 85 | +### Legacy System (Before) |
| 86 | +```typescript |
| 87 | +User signs EIP-712 → Backend relayer → Pays gas → USDC transfer |
| 88 | +``` |
| 89 | + |
| 90 | +### EIP-7702 System (Now) |
| 91 | +```typescript |
| 92 | +User signs EIP-7702 auth → Temporary account upgrade → |
| 93 | +Alchemy sponsors gas → USDC transfer → Account reverts to EOA |
| 94 | +``` |
| 95 | + |
| 96 | +## Technical Details |
| 97 | + |
| 98 | +### Why Custom Signature Utilities? |
| 99 | + |
| 100 | +Para's standard signing methods add Ethereum Signed Message prefix: |
| 101 | +```typescript |
| 102 | +keccak256("\x19Ethereum Signed Message:\n32" + message) |
| 103 | +``` |
| 104 | + |
| 105 | +EIP-7702 requires raw signatures: |
| 106 | +```typescript |
| 107 | +keccak256(message) // No prefix! |
| 108 | +``` |
| 109 | + |
| 110 | +Our custom utilities: |
| 111 | +1. Hash the data with viem's proper hash functions |
| 112 | +2. Sign the hash directly with Para's `signMessage` |
| 113 | +3. Adjust v-values correctly for each context |
| 114 | + |
| 115 | +### Signature v-value Handling |
| 116 | + |
| 117 | +- **Standard Ethereum**: v = 27 or 28 |
| 118 | +- **EIP-7702**: yParity = 0 or 1 |
| 119 | + |
| 120 | +Our utilities automatically convert based on context. |
| 121 | + |
| 122 | +## Testing |
| 123 | + |
| 124 | +1. Set environment variables |
| 125 | +2. Enable feature flag: `NEXT_PUBLIC_ENABLE_EIP7702=true` |
| 126 | +3. Trigger USDC payment with Para wallet |
| 127 | +4. Check console logs for EIP-7702 flow |
| 128 | +5. Verify gas sponsorship in Alchemy dashboard |
| 129 | + |
| 130 | +## Fallback Behavior |
| 131 | + |
| 132 | +If EIP-7702 is disabled or misconfigured, automatically falls back to legacy backend relayer system. |
| 133 | + |
| 134 | +## Dependencies |
| 135 | + |
| 136 | +```json |
| 137 | +{ |
| 138 | + "@account-kit/smart-contracts": "^4.70.0", |
| 139 | + "@account-kit/infra": "^4.70.0", |
| 140 | + "@aa-sdk/core": "^4.70.0", |
| 141 | + "@getpara/react-sdk": "^2.0.0-alpha.63" |
| 142 | +} |
| 143 | +``` |
| 144 | + |
| 145 | +## Console Logs (Success) |
| 146 | + |
| 147 | +``` |
| 148 | +🔄 [EIP-7702] Starting EIP-7702 transaction with Alchemy Account Kit |
| 149 | +🔄 [EIP-7702] Signing EIP-7702 authorization with Para custom utilities... |
| 150 | +✅ [EIP-7702] Authorization signed successfully! |
| 151 | +🔄 [EIP-7702] Signing message with Para custom utilities... |
| 152 | +✅ [EIP-7702] Message signed successfully |
| 153 | +✅ [EIP-7702] UserOperation submitted |
| 154 | +✅ [EIP-7702] Transaction confirmed |
| 155 | +``` |
| 156 | + |
| 157 | +## Troubleshooting |
| 158 | + |
| 159 | +### "User operation cost exceeds specified spend limit" |
| 160 | +**Solution**: Increase spending limit in Alchemy Gas Manager policy |
| 161 | + |
| 162 | +### "Invalid account signature" |
| 163 | +**Solution**: Verify all signing methods are using custom utilities |
| 164 | + |
| 165 | +### "Invalid 7702 Auth signature" |
| 166 | +**Solution**: Check RLP encoding and v-value formatting |
| 167 | + |
| 168 | +## References |
| 169 | + |
| 170 | +- [EIP-7702 Specification](https://eips.ethereum.org/EIPS/eip-7702) |
| 171 | +- [Alchemy Account Kit](https://accountkit.alchemy.com/) |
| 172 | +- [Para EIP-7702 Guide](https://docs.para.gg/v2/react/guides/account-abstraction/eip7702-alchemy) |
| 173 | + |
0 commit comments