MetaTxGateway API

Summary of public/external functions, events and common errors for the MetaTxGateway contract version v1.0.0.

Contract metadata

  • Name: MetaTxGateway

  • Upgrade pattern: UUPS (owner-authorized)

  • Pausable: yes (pauseWithReason / unpause)

Important structs

  • MetaTransaction

    • to: address

    • value: uint256

    • data: bytes

    • nonce: uint256

    • deadline: uint256

    • signature: bytes

Initialization

  • initialize() external

    • Initialize the upgradeable contract (owner set via initializer).

Relayer management

  • setRelayerAuthorization(address relayer, bool authorized) external onlyOwner

    • Authorize / deauthorize relayer addresses.

  • isRelayerAuthorized(address relayer) external view returns (bool)

    • Check relayer status.

Pause / resume

  • pauseWithReason(string calldata reason) external onlyOwner

    • Pause contract and store a human-readable reason.

  • unpause() external onlyOwner

    • Unpause contract.

Core execution

  • executeMetaTransactions( MetaTransaction[] calldata transactions ) external payable

    • Executes a batch of meta-transactions with signature verification.

    • Validations:

      • Signature verified via EIP‑712 using domain (name: "MetaTxGateway", version: "2.0.0").

      • Nonce must equal nonces[from].

      • Deadline must not be expired.

      • If msg.value > 0, msg.value must equal sum(metaTx.value).

    • Behavior:

      • Each metaTx is executed with try/catch; failures do not revert the entire batch.

      • Tracks value used; refunds unused native tokens to from.

      • Increments nonces[from] on success path.

    • Returns an array of booleans indicating per-transaction success.

Helpers & view functions

  • calculateRequiredValue(MetaTransaction[] calldata metaTxs) external pure returns (uint256 totalValue)

    • Sum of metaTx.value.

  • getNonce(address user) external view returns (uint256 currentNonce)

    • Returns current nonce for user.

  • name() external pure returns (string memory)

    • Returns "MetaTxGateway"

  • version() external pure returns (string memory)

    • Returns "2.0.0"

  • domainSeparator() external view returns (bytes32)

    • Returns EIP‑712 domain separator used to compute digest.

  • UPGRADE_INTERFACE_VERSION() external pure returns (string memory)

    • Returns "5.0.0"

Events

  • event MetaTransactionExecuted(address indexed user, address indexed to, bool success, bytes returnData)

  • event NativeTokenUsed(address indexed user, uint256 amount)

  • event Upgraded(address indexed implementation)

  • event RelayerAuthorized(address indexed relayer, bool authorized)

  • event PausedWithReason(string reason)

  • event TokenRescued(address indexed token, address indexed to, uint256 amount)

Common error strings (revert reasons)

  • "Invalid relayer address"

  • "Unauthorized relayer"

  • "Transaction expired"

  • "Invalid nonce"

  • "Invalid signature"

  • "Empty batch Txs"

  • "Incorrect native token amount"

  • "Refund failed"

  • "Only self-calls allowed"

  • "Already paused"

  • "Not paused"

  • "Invalid address"

Notes & integration tips

  • Frontends should use _signTypedData with domain version "2.0.0" and the MetaTransactions type (array of MetaTransaction).

  • Always call calculateRequiredValue(metaTxs) to compute exact msg.value for relayer transaction.

  • Relayers must be authorized by owner to call executeMetaTransactions.

  • Monitor NativeTokenUsed events for refunds and accounting. nonce: 1, deadline: 1640995200, signature: "0x..." } ];

// With native token value const tx = await gateway.executeMetaTransactions(transactions, { value: ethers.parseEther("0.1") });

// Without native token value const tx = await gateway.executeMetaTransactions(transactions);

Parameters:

  • newImplementation: Address of the new implementation contract

Access Control: Owner only

Events Emitted:

  • Upgraded(address indexed implementation)

Example Usage:

Read Functions

getNonce

Returns the current nonce for a user address.

Parameters:

  • user: User address to query

Returns: Current nonce value (starts at 0)

Example Usage:

name

Returns the contract name used in EIP-712 domain separator.

Returns: "MetaTxGateway"

Usage in EIP-712:

version

Returns the contract version used in EIP-712 domain separator.

Returns: "2.0.0"

Usage: Used for EIP-712 signature domain separation between contract versions.

domainSeparator

Returns the EIP-712 domain separator hash.

Returns: Computed domain separator hash

Example Usage:

UPGRADE_INTERFACE_VERSION

Returns the UUPS upgrade interface version.

Returns: "5.0.0"

Usage: Internal compatibility checking for UUPS upgrades.

Events

MetaTransactionExecuted

Emitted for each executed meta-transaction in a batch.

Parameters:

  • user: Address of the transaction signer

  • to: Target contract address

  • success: Whether the transaction succeeded

  • returnData: Return data from the target call

Example Listening:

NativeTokenUsed

Emitted when native tokens (ETH/BNB) are included in meta-transactions.

Parameters:

  • user: User whose tokens were used

  • amount: Amount of native tokens in wei

Example Listening:

Upgraded

Emitted when the contract implementation is upgraded.

Parameters:

  • implementation: Address of the new implementation contract

Error Reference

Custom Errors

InvalidSignature()

  • Cause: EIP-712 signature verification failed

  • Solutions: Check domain parameters, signature format, signer address

ExpiredDeadline()

  • Cause: Transaction deadline has passed

  • Solutions: Create new transaction with fresh deadline

InvalidNonce()

  • Cause: Nonce doesn't match expected value

  • Solutions: Fetch current nonce and use correct value

ExecutionFailed()

  • Cause: Target transaction reverted

  • Solutions: Check target contract state, parameters, and permissions

Standard Errors

Revert Messages

  • "Address: low-level call failed" - Target contract call failed

  • "Address: insufficient balance" - Not enough ETH for value transfer

  • "Ownable: caller is not the owner" - Access control violation

EIP-712 Signature Specification

Domain

Types

Message Format

Signing Process

Integration Examples

Basic Meta-Transaction

Batch Transaction

Transaction with Native Tokens

Gas Optimization

Efficient Batch Sizes

Gas Estimation

Security Considerations

Signature Validation

Always validate signatures client-side before submission:

Deadline Management

Set appropriate deadlines to prevent stale transactions:

Nonce Management

Implement proper nonce tracking:

Testing Utilities

Mock Setup

Migration Guide

From v1.0.0 to v1.0.0

Key Changes:

  1. Domain version updated to "2.0.0"

  2. Added native token support

  3. Enhanced error messages

Migration Steps:

Support

For technical support or questions about the MetaTxGateway API:

Last updated