Allow your users to pay with ERC-20
Non-Sponsored calls, also known as Sync Fee Calls, are the simplest way to pay for relay services. However, they delegate all security (reentrancy/replay protection etc.) and payment logic to the target smart contract. You can use ERC-2771 to achieve out-of-the-box security and authentication. Relay costs are covered in either native or ERC-20 tokens and they are paid synchronously during the relay call.
For ERC-20 tokens that implement the permit function (EIP-2612), you can enable gasless transactions by allowing users to authorize token spending through off-chain signatures instead of requiring an on-chain approval transaction.
Implementation Steps
1. Deploy a GelatoRelayContext compatible contract
Import GelatoRelayContext in your target contract to inherit callWithSyncFee functionalities:
For ERC2771 Sync Fee Calls (Recommended)
Import GelatoRelayContextERC2771 in your target contract to inherit ERC2771 functionalities with callWithSyncFee:
2. Import GelatoRelaySDK into your front-end .js project
Or if you’re using the Viem library:
For ERC2771 Sync Fee Calls
When using ERC2771 methods, initialize GelatoRelay with the appropriate trustedForwarder. The possible configurations are:
Check the Supported Networks and contract addresses to identify the trustedForwarder associated with your method.
Example for Sepolia using callWithSyncFeeERC2771:
3. Generate a payload for your target contract
4. Send payload to Gelato
For ERC2771 Sync Fee Calls
Learn more about Implementation of Non ERC2771 SyncFee Calls and ERC2771 SyncFee Calls in our documentation.
Important Considerations for ERC-20 Permit
When implementing permit functionality, keep these points in mind:
- Token Compatibility: Not all ERC-20 tokens support permit - always check compatibility first
- Single Transaction Flow: Users can approve and execute in one transaction when permit is supported
- Signature Expiration: Permit signatures have deadlines - ensure adequate time for transaction execution
- Nonce Mechanism: Each permit signature can only be used once due to the nonce mechanism
- Security: Always validate permit parameters in your smart contract to prevent replay attacks