@tonconnect/ui-react 2.2.0-beta.0 → 2.3.0-beta.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 +196 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@ You can find more details and the protocol specification in the [docs](https://d
|
|
|
12
12
|
|
|
13
13
|
# Getting started
|
|
14
14
|
|
|
15
|
-
[Latest API documentation](https://ton-connect.github.io/sdk/modules/
|
|
15
|
+
[Latest API documentation](https://ton-connect.github.io/sdk/modules/_tonconnect_ui_react.html)
|
|
16
16
|
|
|
17
17
|
# Getting started
|
|
18
18
|
|
|
@@ -39,6 +39,48 @@ export function App() {
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
```
|
|
42
|
+
### Using with Next.js
|
|
43
|
+
|
|
44
|
+
`TonConnectUIProvider` relies on browser APIs and should be rendered only on the client side. In a Next.js application mark the component that wraps the provider with `"use client"` or dynamically import the provider to disable server side rendering.
|
|
45
|
+
|
|
46
|
+
Example for the `app` router:
|
|
47
|
+
|
|
48
|
+
```tsx
|
|
49
|
+
// app/providers.tsx
|
|
50
|
+
'use client';
|
|
51
|
+
|
|
52
|
+
import { TonConnectUIProvider } from '@tonconnect/ui-react';
|
|
53
|
+
|
|
54
|
+
export function Providers({ children }: { children: React.ReactNode }) {
|
|
55
|
+
return (
|
|
56
|
+
<TonConnectUIProvider manifestUrl="https://<YOUR_APP_URL>/tonconnect-manifest.json">
|
|
57
|
+
{children}
|
|
58
|
+
</TonConnectUIProvider>
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
For the `pages` router you can dynamically import the provider:
|
|
64
|
+
|
|
65
|
+
```tsx
|
|
66
|
+
import dynamic from 'next/dynamic';
|
|
67
|
+
|
|
68
|
+
const TonConnectUIProvider = dynamic(
|
|
69
|
+
() => import('@tonconnect/ui-react').then(m => m.TonConnectUIProvider),
|
|
70
|
+
{ ssr: false }
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
function MyApp({ Component, pageProps }) {
|
|
74
|
+
return (
|
|
75
|
+
<TonConnectUIProvider manifestUrl="https://<YOUR_APP_URL>/tonconnect-manifest.json">
|
|
76
|
+
<Component {...pageProps} />
|
|
77
|
+
</TonConnectUIProvider>
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
With both approaches the provider is executed only in the browser and works correctly.
|
|
83
|
+
|
|
42
84
|
|
|
43
85
|
You can also specify required wallet features to filter wallets that will be displayed in the connect wallet modal:
|
|
44
86
|
|
|
@@ -229,6 +271,152 @@ export const Settings = () => {
|
|
|
229
271
|
};
|
|
230
272
|
```
|
|
231
273
|
|
|
274
|
+
## Sign data
|
|
275
|
+
|
|
276
|
+
Sign arbitrary data with the user's wallet. The wallet will display the data to the user for confirmation before signing. Wallet must be connected when you call `signData`, otherwise an error will be thrown.
|
|
277
|
+
|
|
278
|
+
### Data Types
|
|
279
|
+
|
|
280
|
+
You can sign three types of data. Choose the right format based on your use case:
|
|
281
|
+
|
|
282
|
+
- **Text** - Use for human-readable text that users should see and understand
|
|
283
|
+
- **Cell** - Use for TON Blockchain data that should be used in smart contracts (wallet may show unknown content warning)
|
|
284
|
+
- **Binary** - For other arbitrary data (least preferred due to security warnings)
|
|
285
|
+
|
|
286
|
+
#### Text Format
|
|
287
|
+
|
|
288
|
+
Use when you need to sign human-readable text. The wallet displays the text to the user.
|
|
289
|
+
|
|
290
|
+
**Parameters:**
|
|
291
|
+
- `type` (string, required): Must be `"text"`
|
|
292
|
+
- `text` (string, required): UTF-8 text to sign
|
|
293
|
+
- `network` (string, optional): `"-239"` for mainnet, `"-3"` for testnet
|
|
294
|
+
- `from` (string, optional): Signer address in raw format `"0:<hex>"`
|
|
295
|
+
|
|
296
|
+
```tsx
|
|
297
|
+
import { useTonConnectUI } from '@tonconnect/ui-react';
|
|
298
|
+
|
|
299
|
+
export const SignTextData = () => {
|
|
300
|
+
const [tonConnectUI] = useTonConnectUI();
|
|
301
|
+
|
|
302
|
+
const handleSignText = async () => {
|
|
303
|
+
const textData = {
|
|
304
|
+
type: "text",
|
|
305
|
+
text: "Confirm new 2fa number:\n+1 234 567 8901",
|
|
306
|
+
network: "-239", // MAINNET = '-239', TESTNET = '-3'
|
|
307
|
+
from: "0:348bcf827469c5fc38541c77fdd91d4e347eac200f6f2d9fd62dc08885f0415f"
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
try {
|
|
311
|
+
const result = await tonConnectUI.signData(textData);
|
|
312
|
+
console.log('Signed:', result);
|
|
313
|
+
} catch (e) {
|
|
314
|
+
console.error('Error:', e);
|
|
315
|
+
}
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
return <button onClick={handleSignText}>Sign Text Data</button>;
|
|
319
|
+
};
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
#### Binary Format
|
|
323
|
+
|
|
324
|
+
Use for arbitrary binary data. The wallet shows a warning about unknown content.
|
|
325
|
+
|
|
326
|
+
**Parameters:**
|
|
327
|
+
- `type` (string, required): Must be `"binary"`
|
|
328
|
+
- `bytes` (string, required): Base64 encoded binary data (not url-safe)
|
|
329
|
+
- `network` (string, optional): `"-239"` for mainnet, `"-3"` for testnet
|
|
330
|
+
- `from` (string, optional): Signer address in raw format `"0:<hex>"`
|
|
331
|
+
|
|
332
|
+
```tsx
|
|
333
|
+
import { useTonConnectUI } from '@tonconnect/ui-react';
|
|
334
|
+
|
|
335
|
+
export const SignBinaryData = () => {
|
|
336
|
+
const [tonConnectUI] = useTonConnectUI();
|
|
337
|
+
|
|
338
|
+
const handleSignBinary = async () => {
|
|
339
|
+
const binaryData = {
|
|
340
|
+
type: "binary",
|
|
341
|
+
bytes: "1Z/SGh+3HFMKlVHSkN91DpcCzT4C5jzHT3sA/24C5A==",
|
|
342
|
+
network: "-239", // MAINNET = '-239', TESTNET = '-3'
|
|
343
|
+
from: "0:348bcf827469c5fc38541c77fdd91d4e347eac200f6f2d9fd62dc08885f0415f"
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
try {
|
|
347
|
+
const result = await tonConnectUI.signData(binaryData);
|
|
348
|
+
console.log('Signed:', result);
|
|
349
|
+
} catch (e) {
|
|
350
|
+
console.error('Error:', e);
|
|
351
|
+
}
|
|
352
|
+
};
|
|
353
|
+
|
|
354
|
+
return <button onClick={handleSignBinary}>Sign Binary Data</button>;
|
|
355
|
+
};
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
#### Cell Format
|
|
359
|
+
|
|
360
|
+
Use for TON Blockchain data with TL-B schema. The wallet can parse and display the content if the schema is valid.
|
|
361
|
+
|
|
362
|
+
**Parameters:**
|
|
363
|
+
- `type` (string, required): Must be `"cell"`
|
|
364
|
+
- `schema` (string, required): TL-B schema of the cell payload
|
|
365
|
+
- `cell` (string, required): Base64 encoded BoC (not url-safe) with single-root cell
|
|
366
|
+
- `network` (string, optional): `"-239"` for mainnet, `"-3"` for testnet
|
|
367
|
+
- `from` (string, optional): Signer address in raw format `"0:<hex>"`
|
|
368
|
+
|
|
369
|
+
```tsx
|
|
370
|
+
import { useTonConnectUI } from '@tonconnect/ui-react';
|
|
371
|
+
|
|
372
|
+
export const SignCellData = () => {
|
|
373
|
+
const [tonConnectUI] = useTonConnectUI();
|
|
374
|
+
|
|
375
|
+
const handleSignCell = async () => {
|
|
376
|
+
const cellData = {
|
|
377
|
+
type: "cell",
|
|
378
|
+
schema: "transfer#0f8a7ea5 query_id:uint64 amount:(VarUInteger 16) destination:MsgAddress response_destination:MsgAddress custom_payload:(Maybe ^Cell) forward_ton_amount:(VarUInteger 16) forward_payload:(Either Cell ^Cell) = InternalMsgBody;",
|
|
379
|
+
cell: "te6ccgEBAQEAVwAAqg+KfqVUbeTvKqB4h0AcnDgIAZucsOi6TLrfP6FcuPKEeTI6oB3fF/NBjyqtdov/KtutACCLqvfmyV9kH+Pyo5lcsrJzJDzjBJK6fd+ZnbFQe4+XggI=",
|
|
380
|
+
network: "-239", // MAINNET = '-239', TESTNET = '-3'
|
|
381
|
+
from: "0:348bcf827469c5fc38541c77fdd91d4e347eac200f6f2d9fd62dc08885f0415f"
|
|
382
|
+
};
|
|
383
|
+
|
|
384
|
+
try {
|
|
385
|
+
const result = await tonConnectUI.signData(cellData);
|
|
386
|
+
console.log('Signed:', result);
|
|
387
|
+
} catch (e) {
|
|
388
|
+
console.error('Error:', e);
|
|
389
|
+
}
|
|
390
|
+
};
|
|
391
|
+
|
|
392
|
+
return <button onClick={handleSignCell}>Sign Cell Data</button>;
|
|
393
|
+
};
|
|
394
|
+
```
|
|
395
|
+
|
|
396
|
+
### Response
|
|
397
|
+
|
|
398
|
+
All signData calls return the same response structure:
|
|
399
|
+
|
|
400
|
+
```ts
|
|
401
|
+
interface SignDataResult {
|
|
402
|
+
signature: string; // Base64 encoded signature
|
|
403
|
+
address: string; // Wallet address in raw format
|
|
404
|
+
timestamp: number; // UNIX timestamp in seconds (UTC)
|
|
405
|
+
domain: string; // App domain name
|
|
406
|
+
payload: object; // Original payload from the request
|
|
407
|
+
}
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
### Signature Verification
|
|
411
|
+
|
|
412
|
+
After receiving the signed data, you need to verify the signature to ensure it's authentic and was signed by the claimed wallet address.
|
|
413
|
+
|
|
414
|
+
**For backend verification:** See [TypeScript verification example](https://github.com/ton-connect/demo-dapp-with-react-ui/blob/master/src/server/services/sign-data-service.ts#L32-L109) showing how to verify signatures on your server.
|
|
415
|
+
|
|
416
|
+
**For smart contract verification:** See [FunC verification example](https://github.com/p0lunin/sign-data-contract-verify-example/blob/master/contracts/sign_data_example.fc) showing how to verify signatures in TON smart contracts.
|
|
417
|
+
|
|
418
|
+
**For complete technical details:** See the [Sign Data specification](https://github.com/ton-blockchain/ton-connect/blob/main/requests-responses.md#sign-data) for full signature verification requirements.
|
|
419
|
+
|
|
232
420
|
### useIsConnectionRestored
|
|
233
421
|
Indicates current status of the connection restoring process.
|
|
234
422
|
You can use it to detect when connection restoring process if finished.
|
|
@@ -403,3 +591,10 @@ Please note that this is just a warning and should not affect the functionality
|
|
|
403
591
|
```shell
|
|
404
592
|
npm install encoding
|
|
405
593
|
```
|
|
594
|
+
|
|
595
|
+
## How to find a sent transaction on the blockchain
|
|
596
|
+
|
|
597
|
+
See the detailed guide: [Transaction-by-external-message](../../guidelines/transaction-by-external-message.md)
|
|
598
|
+
|
|
599
|
+
This guide explains how to find the corresponding transaction on the TON blockchain by the BOC of an external-in message.
|
|
600
|
+
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tonconnect/ui-react",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0-beta.0",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"dev": "vite",
|
|
6
6
|
"build": "tsc && vite build"
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"vite-plugin-dts": "^1.7.1"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@tonconnect/ui": "2.
|
|
55
|
+
"@tonconnect/ui": "2.3.0-beta.0"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
58
58
|
"react": ">=17.0.0",
|