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
The token holder signs an authorization off-chain, and a relayer executes the transfer on-chain and pays gas.
25
25
26
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.
27
-
The forwarder pulls FXRP from the user (after a one-time approval) and sends it to the recipient.
28
-
The relayer pays gas and can charge a fee in FXRP.
27
+
The forwarder pulls FXRP from the user (after a one-time approval) and sends it to the provided recipient.
28
+
The relayer pays gas on behalf of the user.
29
+
30
+
## Architecture
31
+
32
+
The architecture of the gasless FXRP payments system is as follows:
33
+
34
+
```mermaid
35
+
sequenceDiagram
36
+
participant User
37
+
participant Relayer
38
+
participant GaslessPaymentForwarder
39
+
participant FXRP
40
+
41
+
User->>User: 1. Sign payment (EIP-712)<br/>off-chain, no gas
Create a new [Hardhat](https://hardhat.org/) project or use the [Flare Hardhat Starter](/network/guides/hardhat-foundry-starter-kit) kit.
52
+
To follow this guide, create a new [Hardhat](https://hardhat.org/) project or use the [Flare Hardhat Starter](/network/guides/hardhat-foundry-starter-kit) kit.
33
53
34
-
Install needed dependencies:
54
+
You will need to install the following dependencies:
35
55
36
56
```bash
37
57
npm install ethers viem express cors dotenv
@@ -53,21 +73,18 @@ Save as `contracts/GaslessPaymentForwarder.sol` to create the forwarder smart co
53
73
54
74
**How the contract works**
55
75
56
-
1. Define libraries and state.
57
-
2. Define events.
58
-
3. Defines errors.
59
-
4. Implements the contract constructor that sets the EIP-712 domain, owner, and initial relayer fee.
60
-
5. Implements the `fxrp` function that returns the FXRP token from the Flare registry.
61
-
6. Defines the `executePayment` function that executes a gasless payment.
62
-
7. Hashes the request (type hash + from, to, amount, fee, nonce, deadline) and gets the [EIP-712](https://eips.ethereum.org/EIPS/eip-712) digest.
63
-
8. Recovers the signer from the signature with ECDSA.
64
-
9. Requires the signer of the payment request.
65
-
10. Requires a sufficient allowance for the total amount (amount + fee).
66
-
11. Transfers the amount from the sender to the recipient.
67
-
12. Transfers fee from sender to relayer (msg.sender); emits `PaymentExecuted`.
68
-
13. Defines the view functions to get the nonce, domain separator, and payment request hash.
69
-
14. Defines the function to set the relater authorization.
70
-
15. Define the function to set the relayer fee.
76
+
1. Define libraries and state (nonces, authorizedRelayers).
@@ -155,15 +172,12 @@ Save as `scripts/deploy.ts` to deploy the [`GaslessPaymentForwarder`](/fxrp/toke
155
172
156
173
**Code Breakdown**
157
174
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