Overview
Permissionless transactions with on-chain payments
After reading this page:
- You’ll know how to use the callWithSyncFee SDK method, using the syncFee payment method.
- You’ll see some code which will help you send a relay request within minutes.
- You’ll learn how to pay for transactions using the provided values for fee, feeToken and feeCollector.
Important: Please proceed to our Security Considerations page and read it thoroughly before advancing with your implementation. It is crucial to understand all potential security risks and measures to mitigate them.
Overview
The callWithSyncFee method uses the syncFee payment method.
Paying for Transactions
When using callWithSyncFee relay method the target contract assumes responsibility for transferring the fee to Gelato’s fee collector during transaction execution. For this, the target contract needs to know:
- fee: the transfer amount
- feeToken: the token to be transferred
- feeCollector: the destination address for the fee
Fortunately, Gelato provides some useful tools within the Relay Context Contracts:
- By inheriting the GelatoRelayContext contract in your target contract, you have the ability to transfer the fee through one of two straightforward methods: _transferRelayFee() or _transferRelayFeeCapped(uint256 maxFee). In either case, the inherited contract takes care of decoding the fee, feeToken, and feeCollector behind the scenes.
- The Gelato Relay backend simplifies the process by automatically calculating the fee for you, using Gelato’s Fee Oracle to perform the calculations in the background.
- Alternatively, you may choose to inherit the GelatoRelayFeeCollector contract. With this approach, Gelato only decodes the feeCollector. You must provide the fee and feeToken on-chain, either by hardcoding them (which is not recommended) or embedding them within the payload to be executed. The suggested way to handle this is to calculate the fee with Gelato’s Fee Oracle.
If, during the transaction simulation in our backend, the feeCollector does not receive the fee, the request will return the error “Insufficient Fees”, and the transaction will not be broadcasted on-chain.
Setting maxFee for Your Transaction
Setting a maximum fee, or maxFee, for your transactions is strongly advised. This practice enables you to ensure that transaction costs remain below a specific limit. The method _transferRelayFeeCapped(uint256 maxFee) in the GelatoRelayContext contract provides a convenient way to set the maxFee easily.
If you are utilizing the GelatoRelayFeeCollector contract, the recommended way to pass the maxFee is by calculating the fee with Gelato’s Fee Oracle, which is accessible in the relay-sdk. The getEstimatedFee() method is provided to facilitate this calculation.
SDK method: callWithSyncFee
Arguments
request
: this is the request body used to send a request.options
: RelayRequestOptions is an optional object.apiKey
: this is an optional API key that links your request to your Gelato Relay account. As this pertains to the syncFee payment method, transaction costs won’t be deducted from your 1Balance account. By using the API key, you can benefit from increased rate limits of your Gelato Relay account.
Return Object: RelayResponse
taskId
: your unique relay task ID which can be used for tracking your request.
Optional Parameters
gasLimit
: the gas limit of the relay call. This effectively sets an upper price limit for the relay call.
Note: If you are using your own custom gas limit, please add a 150k gas buffer on top of the expected gas usage for the transaction. This is for the Gelato Relay execution overhead, and adding this buffer reduces your chance of the task cancelling before it is executed on-chain.
Note: If your contract has any hardcoded requirements about gas usage, please always explicitly pass the gasLimit to the SDK/API, as Gelato will not know what hardcoded gas expectations your contract has. Otherwise, your relay requests might not be executable.
retries
: the number of retries that Gelato should attempt before discarding this relay call. This can be useful if the state of the target contract is not fully known and such reverts can not be definitively avoided.
Sending a Request
Request Body
chainId
: the chain ID of the chain where the target smart contract is deployed.target
: the address of the target smart contract.data
: encoded payload data (usually a function selector plus the required arguments) used to call the required target address.isRelayContext
: an optional boolean (default: true) denoting what data you would prefer appended to the end of the calldata.- If set to true (default), Gelato Relay will append the feeCollector address, the feeToken address, and the uint256 fee to the calldata. This requires the target contract to inherit the GelatoRelayContext contract.
- If set to false, Gelato Relay will only append the feeCollector address to the calldata. In this case the contract to be inherit by the target contract is the GelatoRelayFeeCollector.
feeToken
: the address of the token that is to be used for payment. Please visit SyncFee Payment Tokens for the full list of supported payment tokens per network.