You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This guide describes how to create a system for gasless FXRP (FAsset) transfers on Flare.
18
-
Users sign payment requests off-chain with [EIP-712](https://eips.ethereum.org/EIPS/eip-712), and a relayer submits them on-chain and pays gas on their behalf.
18
+
This guide explains how to set up gasless FXRP (FAsset) transfers on Flare.
19
+
Users sign payment requests off-chain with [EIP-712](https://eips.ethereum.org/EIPS/eip-712) typed data, and a relayer submits them on-chain and pays gas on their behalf.
19
20
20
-
### EIP-3009 and EIP-712
21
+
### Standards explained
21
22
22
-
[EIP-3009](https://eips.ethereum.org/EIPS/eip-3009) (Transfer with Authorization) extends [ERC-20](https://eips.ethereum.org/EIPS/eip-20) with meta-transactions. The token holder signs an authorization off-chain, and a relayer executes the transfer on-chain and pays gas.
23
-
This guide uses a **custom [EIP-712](https://eips.ethereum.org/EIPS/eip-712) payment message** and a forwarder contract instead of EIP-3009 on the token itself.
23
+
[EIP-3009](https://eips.ethereum.org/EIPS/eip-3009) (Transfer with Authorization) extends [ERC-20](https://eips.ethereum.org/EIPS/eip-20) with meta-transactions.
24
+
The token holder signs an authorization off-chain, and a relayer executes the transfer on-chain and pays gas.
25
+
26
+
This guide uses a custom [EIP-712](https://eips.ethereum.org/EIPS/eip-712) payment message and a forwarder contract instead of EIP-3009 on the token itself.
24
27
The forwarder pulls FXRP from the user (after a one-time approval) and sends it to the recipient.
25
28
The relayer pays gas and can charge a fee in FXRP.
26
29
@@ -39,33 +42,34 @@ Add the following files to your project:
39
42
40
43
### Gasless Payment Forwarder Contract
41
44
42
-
Save as `contracts/GaslessPaymentForwarder.sol`:
45
+
Save as `contracts/GaslessPaymentForwarder.sol` to create the forwarder smart contract that will be used to execute gasless payments.
2. Define EIP-712 domain, payment request types, and other network configurations.
131
+
3. Define `RelayerConfig`, `PaymentRequest`, and `ExecuteResult` types.
132
+
4. Implement the `GaslessRelayer` class to interact with the forwarder contract.
133
+
5. Execute gasless payment: normalize and validate request, recover signer with EIP-712, validate request (balance, allowance, deadline), staticCall, then recheck nonce, estimate gas with buffer, call executePayment, wait for receipt, return result.
134
+
6. Validate request: check deadline against chain time, check sender FXRP balance and allowance, check fee meets minimum.
135
+
7. Get nonce for an address from the forwarder contract.
136
+
8. Get the minimum relayer fee from the forwarder contract.
137
+
9. Get FXRP token decimals from the forwarder and token contract.
138
+
10. Get the relayer FLR balance for gas.
139
+
11. Start Express server.
140
+
12. Main function to read environment variables, create a relayer, log FLR balance, and start the server.
141
+
13. Run the main function to start the relayer service.
142
+
104
143
</details>
105
144
106
145
### Deploy Script
107
146
108
-
Save as `scripts/deploy.ts` to deploy the [`GaslessPaymentForwarder`](/fxrp/token-interactions/gasless-fxrp-payments#gasless-payment-forwarder-contract) contract:
147
+
Save as `scripts/deploy.ts` to deploy the [`GaslessPaymentForwarder`](/fxrp/token-interactions/gasless-fxrp-payments#gasless-payment-forwarder-contract) contract.
109
148
110
149
<details>
111
150
<summary>View scripts/deploy.ts</summary>
@@ -114,11 +153,23 @@ Save as `scripts/deploy.ts` to deploy the [`GaslessPaymentForwarder`](/fxrp/toke
114
153
{DeployScript}
115
154
</CodeBlock>
116
155
156
+
**Code Breakdown**
157
+
158
+
1.Importnecessarylibraries.
159
+
2. Define default relayer fee constant in FXRP base units.
160
+
3. Get deployer signer and balance; log address and FLR balance.
161
+
4. Deploy `GaslessPaymentForwarder` contract with the relayer fee (FXRP comes from the Flare Contract Registry) and wait for deployment, and get the contract address.
162
+
5. Get FXRP token address and decimals from the forwarder.
0 commit comments