@gelatonetwork/relay-sdk
v3 or contracts from the package @gelatonetwork/relay-context
v2 please follow this migration guide to migrate to the new versions.callWithSyncFeeERC2771
, you need to pay Gelato’s fee collecting contract when your target function is called, otherwise your relay request will not execute. To carry out this payment, your target contract needs to know the address of the fee collector so that you can transfer funds during the call. Furthermore, you need to know in what token to pay the fee in, and how much to pay the fee collector.
Gelato Relay appends this useful information to the end of the calldata, when using the callWithSyncFeeERC2771 SDK method. Gelato Relay’s Context contracts give you helper functions which you can use via inheritance in your target contract allowing you to decode information from the relay calldata, giving you access to:
uint256 _getFee()
: a value denoting how much fee to pay.address _getFeeToken()
: the address of the token the fee is paid in.address _getFeeCollector()
: the address to which to send your payment.address _getMsgSender()
: the address of the off-chain signer.onlyGelatoRelay
: a modifier which will only allow Gelato Relay to call this function._isGelatoRelay(address _forwarder)
: a function which returns true if the address matches Gelato Relay’s address._getFeeCollector()
: a function to retrieve the fee collector address._getFee()
: a function to retrieve the fee that Gelato will charge._getFeeToken()
: a function to retrieve the address of the token used for fee payment._getMsgSender()
: a function to retrieve the off-chain signer address._getMsgData()
: a function to access the original msg.data without appended information._transferRelayFee()
: a function which transfers the fee amount to Gelato, with no cap._transferRelayFeeCapped(uint256 _maxFee)
: a function which transfers the fee amount to Gelato which a set cap from the argument maxFee in wei. This helps limit fees on function calls in case of gas volatility or just for general budgeting.onlyGelatoRelay
: a modifier which will only allow Gelato Relay to call this function._isGelatoRelay(address _forwarder)
: a function which returns true if the address matches Gelato Relay’s address._getFeeCollector()
: a function to retrieve the fee collector address._getMsgSender()
: a function to retrieve the off-chain signer address._getMsgData()
: a function to access the original msg.data without appended information.