CallWithSyncFee
Permissionless transactions with on-chain payments
Last updated
Permissionless transactions with on-chain payments
Last updated
After reading this page:
You'll know how to use the callWithSyncFee
SDK method, using the 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
.
Please proceed to our page and read it thoroughly before advancing with your implementation. It is crucial to understand all potential security risks and measures to mitigate them.
The callWithSyncFee
method uses the payment method.
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 :
By inheriting the 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 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 .
maxFee
for Your Transactionoptions
: RelayRequestOptions
is an optional object.
gasLimit
: the gas limit of the relay call. This effectively sets an upper price limit for the relay call.
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.
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.
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.
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 contract provides a convenient way to set the maxFee
easily.
If you are utilizing the contract, the recommended way to pass the maxFee
is by calculating the fee with , which is accessible in the . The getEstimatedFee()
method is provided to facilitate this calculation.
request
: this is the used to send a request.
apiKey
: this is an optional API key that links your request to your Gelato Relay account. As this pertains to the 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.
taskId
: your unique relay task ID which can be used for .
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 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 .
feeToken
: the address of the token that is to be used for payment. Please visit for the full list of supported payment tokens per network.