2️⃣callWithSyncFee
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
andfeeCollector
.
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 amountfeeToken
: the token to be transferredfeeCollector
: 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 thefee
,feeToken
, andfeeCollector
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 thefee
andfeeToken
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.
Setting maxFee
for Your Transaction
maxFee
for Your TransactionSetting 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.
Return Object: RelayResponse
taskId
: your unique relay task ID which can be used for tracking your request.
Optional Parameters
See Optional Parameters.
Sending a Request
Request Body
chainId
: the chain ID of the chain where thetarget
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 requiredtarget
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 thefeeCollector
address, thefeeToken
address, and the uint256fee
to the calldata. This requires the target contract to inherit the GelatoRelayContext contract.If set to
false
, Gelato Relay will only append thefeeCollector
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.
Example Code GelatoRelayContext
1. Deploy a GelatoRelayContext compatible contract
2. Import GelatoRelaySDK into your front-end .js project
3. Send the payload to Gelato
Last updated