@gasfree-kit/ton-gasless 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +192 -152
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,152 +1,192 @@
|
|
|
1
|
-
# @gasfree-kit/ton-gasless
|
|
2
|
-
|
|
3
|
-
Gasless USDT transfers on TON through a sponsored relay.
|
|
4
|
-
|
|
5
|
-
With this package, the user only needs USDT. The relay pays the TON gas and charges a small fee back in USDT.
|
|
6
|
-
|
|
7
|
-
## What This Package Does
|
|
8
|
-
|
|
9
|
-
- creates a WDK-backed TON wallet
|
|
10
|
-
- quotes the relay fee in USDT
|
|
11
|
-
- checks that balance covers transfer amount plus fee
|
|
12
|
-
- submits the gasless transfer
|
|
13
|
-
- returns a transfer context you can log or persist
|
|
14
|
-
|
|
15
|
-
## Transfer Diagram
|
|
16
|
-
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
###
|
|
110
|
-
|
|
111
|
-
```ts
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
1
|
+
# @gasfree-kit/ton-gasless
|
|
2
|
+
|
|
3
|
+
Gasless USDT transfers on TON through a sponsored relay.
|
|
4
|
+
|
|
5
|
+
With this package, the user only needs USDT. The relay pays the TON gas and charges a small fee back in USDT.
|
|
6
|
+
|
|
7
|
+
## What This Package Does
|
|
8
|
+
|
|
9
|
+
- creates a WDK-backed TON wallet
|
|
10
|
+
- quotes the relay fee in USDT
|
|
11
|
+
- checks that balance covers transfer amount plus fee
|
|
12
|
+
- submits the gasless transfer
|
|
13
|
+
- returns a transfer context you can log or persist
|
|
14
|
+
|
|
15
|
+
## Transfer Diagram
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
┌──────────────────────────┐
|
|
19
|
+
│ Your app │
|
|
20
|
+
└────────────┬─────────────┘
|
|
21
|
+
│
|
|
22
|
+
v
|
|
23
|
+
┌──────────────────────────┐
|
|
24
|
+
│ @gasfree-kit/ton-gasless │
|
|
25
|
+
└──────┬─────────────┬─────┘
|
|
26
|
+
│ │
|
|
27
|
+
v v
|
|
28
|
+
┌────────────┐ ┌───────────────┐
|
|
29
|
+
│ WDK TON │ │ Relay fee │
|
|
30
|
+
│ wallet │ │ quote (USDT) │
|
|
31
|
+
└──────┬─────┘ └───────┬───────┘
|
|
32
|
+
│ │
|
|
33
|
+
└───────┬───────┘
|
|
34
|
+
│
|
|
35
|
+
v
|
|
36
|
+
┌──────────────────────────┐
|
|
37
|
+
│ Sponsored relay │
|
|
38
|
+
├──────────────────────────┤
|
|
39
|
+
│ • Pays TON gas │
|
|
40
|
+
│ • Deducts USDT fee │
|
|
41
|
+
└────────────┬─────────────┘
|
|
42
|
+
│
|
|
43
|
+
v
|
|
44
|
+
┌──────────────────────────┐
|
|
45
|
+
│ TON blockchain │
|
|
46
|
+
└──────────────────────────┘
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
```mermaid
|
|
50
|
+
flowchart TD
|
|
51
|
+
A["Your app"] --> B["@gasfree-kit/ton-gasless"]
|
|
52
|
+
B --> C["WDK TON wallet"]
|
|
53
|
+
B --> D["Relay fee quote"]
|
|
54
|
+
C --> E["Sponsored relay"]
|
|
55
|
+
D --> E
|
|
56
|
+
E -->|pays TON gas| F["TON blockchain"]
|
|
57
|
+
E -->|deducts fee| G["USDT commission"]
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Installation
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
npm install @gasfree-kit/ton-gasless
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Peer dependencies:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
npm install @tetherto/wdk-wallet-ton-gasless tonweb
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Configuration
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
import type { TonGaslessClientConfig } from '@gasfree-kit/ton-gasless';
|
|
76
|
+
|
|
77
|
+
const config: TonGaslessClientConfig = {
|
|
78
|
+
tonCenterUrl: 'https://toncenter.com/api/v2',
|
|
79
|
+
tonCenterApiKey: 'your-toncenter-api-key',
|
|
80
|
+
tonApiUrl: 'https://tonapi.io',
|
|
81
|
+
tonApiSecretKey: 'your-tonapi-secret-key',
|
|
82
|
+
// Optional:
|
|
83
|
+
// transferMaxFee: 1_000_000,
|
|
84
|
+
// usdtAddress: 'EQCxE6mUtQJKFnGfaROTKOt1lZbDiiX1kCixRv7Nw2Id_sDs',
|
|
85
|
+
};
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Config fields
|
|
89
|
+
|
|
90
|
+
| Field | Purpose |
|
|
91
|
+
| ----------------- | -------------------------------------------------- |
|
|
92
|
+
| `tonCenterUrl` | TON Center endpoint used by the wallet client |
|
|
93
|
+
| `tonCenterApiKey` | TON Center API key |
|
|
94
|
+
| `tonApiUrl` | TON API endpoint |
|
|
95
|
+
| `tonApiSecretKey` | TON API secret key |
|
|
96
|
+
| `transferMaxFee` | Maximum fee limit in base units, capped by the SDK |
|
|
97
|
+
| `usdtAddress` | Optional override for the TON USDT root |
|
|
98
|
+
|
|
99
|
+
## Quick Start
|
|
100
|
+
|
|
101
|
+
### 1. Generate a seed phrase
|
|
102
|
+
|
|
103
|
+
```ts
|
|
104
|
+
import { generateSeedPhrase } from '@gasfree-kit/core';
|
|
105
|
+
|
|
106
|
+
const seedPhrase = await generateSeedPhrase();
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### 2. Set up a wallet
|
|
110
|
+
|
|
111
|
+
```ts
|
|
112
|
+
import { setupTonGaslessWallet } from '@gasfree-kit/ton-gasless';
|
|
113
|
+
|
|
114
|
+
const { wallet, account, address } = await setupTonGaslessWallet(seedPhrase, config);
|
|
115
|
+
|
|
116
|
+
console.log(address);
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
If you need a specific derivation path:
|
|
120
|
+
|
|
121
|
+
```ts
|
|
122
|
+
const walletResult = await setupTonGaslessWallet(seedPhrase, config, "0'/0/0");
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### 3. Check USDT balance
|
|
126
|
+
|
|
127
|
+
```ts
|
|
128
|
+
import { TonTransfer } from '@gasfree-kit/ton-gasless';
|
|
129
|
+
|
|
130
|
+
const balance = await TonTransfer.checkBalance(seedPhrase, config);
|
|
131
|
+
|
|
132
|
+
console.log(balance.data.usdBalance);
|
|
133
|
+
console.log(balance.data.tokenBalance);
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### 4. Estimate the fee
|
|
137
|
+
|
|
138
|
+
```ts
|
|
139
|
+
const estimate = await TonTransfer.getTransactionEstimateFee(
|
|
140
|
+
seedPhrase,
|
|
141
|
+
config,
|
|
142
|
+
'10.00',
|
|
143
|
+
'EQCxE6mUtQJKFnGfaROTKOt1lZbDiiX1kCixRv7Nw2Id_sDs',
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
console.log(estimate.data.fee);
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### 5. Execute the gasless transfer
|
|
150
|
+
|
|
151
|
+
```ts
|
|
152
|
+
const result = await TonTransfer.transferUSDT(
|
|
153
|
+
seedPhrase,
|
|
154
|
+
config,
|
|
155
|
+
'50.00',
|
|
156
|
+
'EQCxE6mUtQJKFnGfaROTKOt1lZbDiiX1kCixRv7Nw2Id_sDs',
|
|
157
|
+
);
|
|
158
|
+
|
|
159
|
+
console.log(result.data.transactionHash);
|
|
160
|
+
console.log(result.data.fee);
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
## How The Flow Behaves
|
|
164
|
+
|
|
165
|
+
1. The SDK validates the recipient address.
|
|
166
|
+
2. The SDK asks the relay path for a fee quote.
|
|
167
|
+
3. The SDK checks that the wallet balance can cover `amount + fee`.
|
|
168
|
+
4. The transfer is submitted.
|
|
169
|
+
5. The relay pays TON gas and deducts the fee in USDT.
|
|
170
|
+
|
|
171
|
+
## Main Exports
|
|
172
|
+
|
|
173
|
+
| Export | What it does |
|
|
174
|
+
| ------------------------ | ---------------------------------------------------------- |
|
|
175
|
+
| `setupTonGaslessWallet` | Creates the WDK-backed TON wallet and resolves the address |
|
|
176
|
+
| `TonTransfer` | Checks balances, estimates fees, and sends transfers |
|
|
177
|
+
| `getTonGaslessConfig` | Expands and validates the runtime config |
|
|
178
|
+
| `tonUsdtTokenRoot` | Built-in TON USDT root address |
|
|
179
|
+
| `usdtTonBaseUnits` | Converts human-readable USDT to base units |
|
|
180
|
+
| `fromTonBaseUnitsToUsdt` | Converts base units back to readable USDT |
|
|
181
|
+
| `getTonUsdtValue` | Utility helper for TON to USDT conversions |
|
|
182
|
+
|
|
183
|
+
## Safety Notes
|
|
184
|
+
|
|
185
|
+
- `transferMaxFee` is capped by the SDK to prevent extreme fee deductions
|
|
186
|
+
- invalid TON addresses are rejected before sending
|
|
187
|
+
- self-transfers are blocked
|
|
188
|
+
- the user must have enough USDT for both transfer amount and fee
|
|
189
|
+
|
|
190
|
+
## License
|
|
191
|
+
|
|
192
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gasfree-kit/ton-gasless",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Gasless USDT transfers on TON via sponsored relay",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"README.md"
|
|
18
18
|
],
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@gasfree-kit/core": "0.
|
|
20
|
+
"@gasfree-kit/core": "0.2.0"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
23
23
|
"@tetherto/wdk-wallet-ton-gasless": "^1.0.0-beta.4",
|