Skip to main content
Agora’s gasless transaction system enables users to delegate voting power and cast votes without paying gas fees. A relay service sponsors transactions by accepting EIP-712 signatures and submitting them on-chain.

Overview

The relay system supports two primary operations:
  • Gasless Delegation - Delegate tokens without gas via delegateBySig
  • Gasless Voting - Cast votes without gas via castVoteBySig
Both use the same pattern: users sign messages off-chain, and a sponsored wallet submits the signature on-chain.

Architecture

Configuration

Environment Setup

Configure the gas sponsor wallet:
The GAS_SPONSOR_PK private key must be kept secure. It should have sufficient ETH to sponsor transactions but shouldn’t hold excessive funds. Monitor balance regularly.

Relay Status

Check the sponsor wallet status:
The estimated gas cost per transaction is ~0.001108297 ETH.

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:
Include API key in request headers:
See API Authentication for details.

Input Validation

Validate relay requests with Zod schemas:
The API validates:
  • 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:
Simulation catches errors before spending gas:
  • 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

  1. Alert threshold - Trigger alert at < 0.1 ETH
  2. Refill amount - Top up to 1 ETH when low
  3. Automated refills - Set up auto-transfer from treasury
  4. 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

Private Key Storage: Never commit GAS_SPONSOR_PK to version control. Use secure secrets management (AWS Secrets Manager, HashiCorp Vault, etc.).

Best Practices

  1. Rate limiting - Limit relay requests per user (e.g., 10/hour)
  2. Signature validation - Always verify signatures before submission
  3. Balance alerts - Monitor sponsor wallet and alert on low balance
  4. Separate wallets - Use different sponsor wallets for production/staging
  5. Transaction limits - Set maximum gas price willing to pay
  6. Allowlists - Consider restricting relay to verified users

Rate Limiting Example

Alternative: Paymaster

For more advanced use cases, consider ERC-4337 paymasters:
Paymasters offer:
  • 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 *BySig methods

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