MetaTxGateway

The MetaTx Gateway enables gasless transactions and meta-transaction functionality for the IXFI Protocol. It allows users to execute transactions without holding native tokens for gas fees, improving accessibility and user experience.

Overview

The MetaTx Gateway provides:

  • Gasless Transactions: Execute transactions without native tokens

  • EIP-2771 Compliance: Standard meta-transaction support

  • Flexible Fee Models: Multiple payment options for transaction fees

  • Relayer Network: Decentralized network of transaction relayers

  • Batch Execution: Execute multiple transactions in a single meta-transaction

Smart Contract Interface

Core Functions

executeMetaTransaction

Execute a meta-transaction on behalf of a user.

function executeMetaTransaction(
    address user,
    address target,
    bytes calldata functionSignature,
    uint256 nonce,
    bytes calldata signature
) external returns (bool success, bytes memory returnData)

Parameters:

  • user: Address of the user initiating the transaction

  • target: Target contract address

  • functionSignature: Encoded function call data

  • nonce: User's current nonce for meta-transactions

  • signature: User's signature for the meta-transaction

Returns:

  • success: Whether the meta-transaction executed successfully

  • returnData: Return data from the target function call

Usage Example:

executeMetaTransactionWithCredits

Execute a meta-transaction using pre-paid gas credits.

Parameters:

  • user: User address

  • target: Target contract address

  • functionSignature: Encoded function call

  • nonce: User's nonce

  • maxGasPrice: Maximum gas price user agrees to pay

  • signature: User's signature

batchExecuteMetaTransactions

Execute multiple meta-transactions in a single call.

Parameters:

Usage Example:

Gas Credit Management

addGasCredits

Add gas credits for a user account.

Parameters:

  • user: User address to credit

  • amount: Amount of gas credits to add (in wei equivalent)

getGasCredits

Get the current gas credit balance for a user.

withdrawGasCredits

Allow users to withdraw unused gas credits.

sponsorGasCredits

Allow third parties to sponsor gas credits for users.

Relayer Management

registerRelayer

Register a new relayer in the network.

Parameters:

  • relayerAddress: Address of the relayer

  • stake: Amount of tokens to stake

  • endpoint: API endpoint for the relayer

updateRelayerStatus

Update relayer status (active/inactive).

slashRelayer

Slash a relayer's stake for misbehavior.

View Functions

getNonce

Get the current nonce for a user's meta-transactions.

isValidSignature

Verify if a meta-transaction signature is valid.

getRelayerInfo

Get information about a registered relayer.

Returns:

estimateMetaTxGas

Estimate gas cost for a meta-transaction.

JavaScript SDK Integration

MetaTxGateway Class

React Hook

Advanced Features

Custom Relayer Integration

Gas Credits Management System

Best Practices

Security Considerations

  1. Signature Validation: Always validate signatures before execution

  2. Nonce Management: Prevent replay attacks with proper nonce handling

  3. Gas Limit Checks: Prevent gas griefing attacks

  4. Rate Limiting: Implement rate limits for relayer endpoints

Performance Optimization

  1. Batch Transactions: Group multiple operations when possible

  2. Gas Price Optimization: Use dynamic gas pricing

  3. Caching: Cache gas estimates and nonce values

  4. Load Balancing: Distribute load across multiple relayers

User Experience

  1. Clear Error Messages: Provide actionable error feedback

  2. Progress Indicators: Show transaction status updates

  3. Fallback Options: Offer regular transactions as backup

  4. Cost Transparency: Display gas costs and credits clearly

Resources

Last updated