Overview
The relay system supports two primary operations:- Gasless Delegation - Delegate tokens without gas via
delegateBySig - Gasless Voting - Cast votes without gas via
castVoteBySig
Architecture
Configuration
Environment Setup
Configure the gas sponsor wallet:Relay Status
Check the sponsor wallet status:Gasless Delegation
API Endpoint
Implementation
Signature Preparation
Gasless Voting
API Endpoint
Implementation
Vote Signature Preparation
Client-Side Integration
Signing Delegation
Generate EIP-712 signature for delegation:Submitting to Relay
Hook Implementation
Authentication
Relay endpoints require API authentication:Input Validation
Validate relay requests with Zod schemas:- Signature format (hex string with 0x prefix)
- Proposal ID exists
- Support value is valid (0, 1, or 2)
- Signature hasn’t been used (nonce check)
- Signature hasn’t expired
Transaction Simulation
Before submitting, simulate the transaction:- Invalid signatures
- Expired signatures
- Insufficient voting power
- Contract state issues
Nonce Management
Nonces prevent signature replay attacks:Each successful delegation increments the user’s nonce, invalidating any pending signatures with old nonces.
Error Handling
Handle common relay errors:Monitoring & Maintenance
Balance Monitoring
Monitor sponsor wallet balance:Refilling Strategy
- Alert threshold - Trigger alert at < 0.1 ETH
- Refill amount - Top up to 1 ETH when low
- Automated refills - Set up auto-transfer from treasury
- Multiple sponsors - Use multiple wallets for high-volume periods
Transaction Tracking
Log relay transactions for monitoring:Gas Optimization
Batch Operations
For multiple delegations, consider batching:Gas Price Strategy
Optimize gas price for cost efficiency:Security Considerations
Best Practices
- Rate limiting - Limit relay requests per user (e.g., 10/hour)
- Signature validation - Always verify signatures before submission
- Balance alerts - Monitor sponsor wallet and alert on low balance
- Separate wallets - Use different sponsor wallets for production/staging
- Transaction limits - Set maximum gas price willing to pay
- Allowlists - Consider restricting relay to verified users
Rate Limiting Example
Alternative: Paymaster
For more advanced use cases, consider ERC-4337 paymasters:- Sponsored transactions without holding private keys
- Gas estimation before submission
- Batch transactions natively
- Policy enforcement (spending limits, allowlists)
Troubleshooting
Transaction fails silently
- Check sponsor wallet has ETH
- Verify signature is valid and not expired
- Ensure nonce is current
- Check contract supports
*BySigmethods
Nonce mismatch
- Fetch latest nonce before signing
- Don’t reuse signatures
- Handle pending transactions properly
Signature rejected
- Verify EIP-712 domain matches token contract
- Check signature format (v, r, s values)
- Ensure signer owns tokens being delegated
Related Resources
- Governance Tokens - Delegation mechanics
- Attestations - Gasless attestation submission
- API Authentication - Securing relay endpoints
- EIP-712 - Typed structured data hashing