' // Another wallet
}
];
connector.connect(sources);
```
```
--------------------------------
### Get User's TON Wallet Info with useTonWallet
Source: https://ton-connect.github.io/sdk/modules/_tonconnect_ui-react.html
The `useTonWallet` hook provides information about the currently connected TON wallet. It returns `null` if no wallet is connected. The returned object contains wallet details like name and device information.
```typescript
import { useTonWallet } from '@tonconnect/ui-react';
export const Wallet = () => {
const wallet = useTonWallet();
return (
wallet && (
Connected wallet: {wallet.name}
Device: {wallet.device.appName}
)
);
};
```
--------------------------------
### constructor
Source: https://ton-connect.github.io/sdk/classes/_tonconnect_ui.TonConnect.html
Initializes a new instance of the TonConnect class.
```APIDOC
## constructor
* new TonConnect(options?: TonConnectOptions): TonConnect
#### Parameters
* `Optional`options: TonConnectOptions
#### Returns TonConnect
```
--------------------------------
### Get User's TON Address with useTonAddress
Source: https://ton-connect.github.io/sdk/modules/_tonconnect_ui-react.html
Use the `useTonAddress` hook to retrieve the user's current TON wallet address. Pass `true` for a user-friendly format or `false` for the raw address. Returns an empty string if the wallet is not connected.
```typescript
import { useTonAddress } from '@tonconnect/ui-react';
export const Address = () => {
const userFriendlyAddress = useTonAddress();
const rawAddress = useTonAddress(false);
return (
address && (
User-friendly address: {userFriendlyAddress}
Raw address: {rawAddress}
)
);
};
```
--------------------------------
### Initialize a remote wallet connection via universal link
Source: https://ton-connect.github.io/sdk/modules/_tonconnect_sdk.html
Connect to a remote wallet using a universal link. This link can be displayed as a QR code or used as a deeplink.
```APIDOC
## Initialize a remote wallet connection via universal link
### Description
Connect to a remote wallet using a universal link. This link can be displayed as a QR code or used as a deeplink. The connection status is updated via `connector.onStatusChange`.
### Method
```javascript
connector.connect(walletConnectionSource)
```
### Parameters
#### Request Body
- **walletConnectionSource** (object, required): An object containing connection details.
- **universalLink** (string, required): The universal link for the wallet.
- **bridgeUrl** (string, required): The bridge URL for the wallet.
### Request Example
```javascript
const walletConnectionSource = {
universalLink: 'https://app.tonkeeper.com/ton-connect',
bridgeUrl: 'https://bridge.tonapi.io/bridge'
}
const universalLink = connector.connect(walletConnectionSource);
```
```
--------------------------------
### Web Animations Polyfill
Source: https://ton-connect.github.io/sdk/modules/_tonconnect_ui-react.html
Instructions on how to use the `web-animations-js` polyfill to resolve issues with animations not working.
```APIDOC
## Animations not working
### Description
If you are experiencing issues with animations not working in your environment, it might be due to a lack of support for the Web Animations API. To resolve this issue, you can use the `web-animations-js` polyfill.
### Usage
#### Using npm
To install the polyfill, run the following command:
```bash
npm install web-animations-js
```
Then, import the polyfill in your project:
```javascript
import 'web-animations-js';
```
#### Using CDN
Alternatively, you can include the polyfill via CDN by adding the following script tag to your HTML:
```html
```
Both methods will provide a fallback implementation of the Web Animations API and should resolve the animation issues you are facing.
```
--------------------------------
### WalletsListManager Constructor
Source: https://ton-connect.github.io/sdk/classes/_tonconnect_ui.WalletsListManager.html
Initializes a new instance of the WalletsListManager class. It accepts an optional options object to configure cache TTL and the wallets list source.
```APIDOC
## constructor
### Description
Initializes a new instance of the WalletsListManager class.
### Parameters
- `options` (object) - Optional. Configuration options for the manager.
- `cacheTTLMs` (number) - Optional. Time-to-live for the cache in milliseconds.
- `walletsListSource` (string) - Optional. URL for the wallets list source.
```
--------------------------------
### openModal
Source: https://ton-connect.github.io/sdk/classes/_tonconnect_ui.TonConnectUI.html
Opens the wallet connection modal window.
```APIDOC
## openModal
* openModal(): Promise
Opens the modal window, returns a promise that resolves after the modal window is opened.
#### Returns Promise
```
--------------------------------
### Commit and Push Demo App Changes
Source: https://ton-connect.github.io/sdk/media/DEVELOPERS.md
Commit the changes made to the demo application and push them to the repository. This action will update the GitHub pages for the demo app.
```shell
git add . && git commit -m "chore: update @tonconnect/ui-react to CURRENT_VERSION" && git push origin HEAD
```
--------------------------------
### Combine All UI Preferences
Source: https://ton-connect.github.io/sdk/modules/_tonconnect_ui.html
Apply multiple UI preferences at once, including theme, border radius, and custom color schemes for both dark and light modes. This demonstrates a comprehensive configuration.
```javascript
tonConnectUI.uiOptions = {
uiPreferences: {
theme: THEME.DARK,
borderRadius: 's',
colorsSet: {
[THEME.DARK]: {
connectButton: {
background: '#29CC6A'
}
},
[THEME.LIGHT]: {
text: {
primary: '#FF0000'
}
}
}
}
};
```
--------------------------------
### createVersionInfo
Source: https://ton-connect.github.io/sdk/functions/_tonconnect_ui.createVersionInfo.html
Creates a version info object. This function takes a Version object as input and returns a Version object.
```APIDOC
## Function createVersionInfo
* createVersionInfo(version: Version): Version
Create a version info.
#### Parameters
* version: Version
#### Returns Version
```
--------------------------------
### Initialize Connector and Restore Connection
Source: https://ton-connect.github.io/sdk/modules/_tonconnect_sdk.html
Initialize the TonConnect connector and attempt to restore a previous connection. This is useful if the user has connected their wallet before.
```javascript
import TonConnect from '@tonconnect/sdk';
const connector = new TonConnect();
connector.restoreConnection();
```
--------------------------------
### Clone Demo DApp Repository
Source: https://ton-connect.github.io/sdk/media/DEVELOPERS.md
Clone the demo-dapp-with-wallet repository to update its package versions. This is a necessary step before testing new releases of TON Connect packages.
```shell
git clone git@github.com:ton-connect/demo-dapp-with-wallet.git && cd demo-dapp-with-wallet
```
--------------------------------
### Link Packages Locally
Source: https://ton-connect.github.io/sdk/media/DEVELOPERS.md
Link individual packages within the 'packages' directory to your local environment using 'npm link'. This is typically done before linking them to a demo application.
```shell
cd packages/ui-react && npm link
cd ../ui && npm link
cd ../protocol && npm link
cd ../sdk && npm link
```
--------------------------------
### BrowserEventDispatcher Constructor
Source: https://ton-connect.github.io/sdk/classes/_tonconnect_ui.BrowserEventDispatcher.html
Initializes a new instance of the BrowserEventDispatcher class.
```APIDOC
## constructor
* new BrowserEventDispatcher(): BrowserEventDispatcher
#### Type Parameters
* T extends { type: string }
#### Returns BrowserEventDispatcher
```
--------------------------------
### Set System Theme
Source: https://ton-connect.github.io/sdk/modules/_tonconnect_ui.html
Configure the TON Connect UI to use the system's default theme. This is the default behavior if no theme is explicitly set.
```javascript
tonConnectUI.uiOptions = {
uiPreferences: {
theme: 'SYSTEM'
}
};
```
--------------------------------
### createConnectionStartedEvent
Source: https://ton-connect.github.io/sdk/functions/_tonconnect_ui.createConnectionStartedEvent.html
Creates a connection init event with the specified version.
```APIDOC
## Function createConnectionStartedEvent
* createConnectionStartedEvent(version: Version): ConnectionStartedEvent
Create a connection init event.
#### Parameters
* version: Version
#### Returns ConnectionStartedEvent
```
--------------------------------
### Fetch Available Wallets
Source: https://ton-connect.github.io/sdk/modules/_tonconnect_ui.html
Retrieve a list of available wallets that can be connected. This can be done using an instance of TonConnectUI or statically.
```javascript
const walletsList = await tonConnectUI.getWallets();
```
```javascript
const walletsList = await TonConnectUI.getWallets();
```
--------------------------------
### Initialize injected wallet connection
Source: https://ton-connect.github.io/sdk/modules/_tonconnect_sdk.html
Connect to an injected wallet using its JavaScript bridge key. The connection status is updated via `connector.onStatusChange`.
```APIDOC
## Initialize injected wallet connection
### Description
Connect to an injected wallet using its JavaScript bridge key. The connection status is updated via `connector.onStatusChange`.
### Method
```javascript
connector.connect(walletConnectionSource)
```
### Parameters
#### Request Body
- **walletConnectionSource** (object, required): An object containing connection details.
- **jsBridgeKey** (string, required): The JavaScript bridge key for the wallet.
### Request Example
```javascript
const walletConnectionSource = {
jsBridgeKey: 'tonkeeper'
}
connector.connect(walletConnectionSource);
```
```
--------------------------------
### Configure UI Package Build Script
Source: https://ton-connect.github.io/sdk/media/DEVELOPERS.md
Modify the 'build' script in 'packages/ui/package.json' to include 'vite build'. This change is a temporary workaround to ensure watch mode functions correctly during development.
```json
{
"scripts": {
"build": "tsc --noEmit --emitDeclarationOnly false && vite build"
}
}
```
--------------------------------
### Build All Packages
Source: https://ton-connect.github.io/sdk/media/DEVELOPERS.md
Build all packages within the TON Connect SDK monorepo. This command compiles the TypeScript code and prepares packages for linking or publishing.
```shell
pnpm build
```
--------------------------------
### getWallets
Source: https://ton-connect.github.io/sdk/classes/_tonconnect_ui.WalletsListManager.html
Fetches and returns a list of available TON wallets.
```APIDOC
## getWallets
### Description
Fetches and returns a list of available TON wallets.
### Returns
- `Promise` - A promise that resolves to an array of wallet information objects.
```
--------------------------------
### Handle Wallet App Requests with Protocol Models
Source: https://ton-connect.github.io/sdk/modules/_tonconnect_protocol.html
Use protocol models to define a handler for incoming requests from a dApp. This function should process the request and return a `WalletResponse`.
```typescript
import { AppRequest, RpcMethod, WalletResponse } from '@tonconnect/protocol';
function myWalletAppRequestsHandler(request: AppRequest): Promise> {
// handle request, ask the user for a confirmation and return WalletResponse
}
```
--------------------------------
### Open Specific Wallet Modal
Source: https://ton-connect.github.io/sdk/modules/_tonconnect_ui.html
Open a modal window for a specific wallet using its 'app_name'. This method is experimental.
```javascript
await tonConnectUI.openSingleWalletModal('wallet_identifier');
```
--------------------------------
### Publish New Release of @tonconnect/ui
Source: https://ton-connect.github.io/sdk/media/DEVELOPERS.md
Use this command to publish a new release of the @tonconnect/ui package. This is the standard command for releasing stable versions.
```shell
cd packages/ui && pnpm publish --access=public
```
--------------------------------
### openSingleWalletModal
Source: https://ton-connect.github.io/sdk/classes/_tonconnect_ui.TonConnectUI.html
Opens the experimental single wallet modal window for a specified wallet.
```APIDOC
## openSingleWalletModal
* openSingleWalletModal(wallet: string): Promise
`Experimental`
Opens the single wallet modal window, returns a promise that resolves after the modal window is opened.
```
--------------------------------
### Fetch Wallets List
Source: https://ton-connect.github.io/sdk/modules/_tonconnect_ui.html
Retrieve a list of available wallets that can be used for connection. This can be done using either an instance of TonConnectUI or the static method.
```APIDOC
const walletsList = await tonConnectUI.getWallets();
// Or using the static method:
const walletsListStatic = await TonConnectUI.getWallets();
```
--------------------------------
### Extend Wallets List with Custom Wallets
Source: https://ton-connect.github.io/sdk/modules/_tonconnect_ui.html
Pass a custom array of wallets to `uiOptions` to extend the default list. Custom wallets can be defined using `jsBridgeKey` for browser extensions or `bridgeUrl` and `universalLink` for HTTP-compatible wallets.
```typescript
import { UIWallet } from '@tonconnect/ui';
const customWallet: UIWallet = {
name: '',
imageUrl: '',
aboutUrl: '',
jsBridgeKey: '',
bridgeUrl: '',
universalLink: ''
};
tonConnectUI.uiOptions = {
walletsListConfiguration: {
includeWallets: [customWallet]
}
}
```
--------------------------------
### Create Unified Link for Wallet Connection
Source: https://ton-connect.github.io/sdk/modules/_tonconnect_sdk.html
Generate a unified link that can be accepted by any wallet by passing an array of `http-wallet-connection-sources`. If multiple wallets share the same bridge URL, it only needs to be listed once.
```javascript
const sources = [
{
bridgeUrl: 'https://bridge.tonapi.io/bridge' // Tonkeeper
},
{
bridgeUrl: 'https://' // Tonkeeper
}
];
connector.connect(sources);
```
--------------------------------
### Set Connect Request Parameters (ton_proof)
Source: https://ton-connect.github.io/sdk/modules/_tonconnect_ui.html
Use `tonConnectUI.setConnectRequestParameters` to manage parameters for the `ton_proof` request. This allows you to set a loading state while waiting for backend responses, provide the `tonProof` payload, or remove the loader.
```APIDOC
## Add connect request parameters (ton_proof)
Use `tonConnectUI.setConnectRequestParameters` function to pass your connect request parameters.
This function takes one parameter:
Set state to 'loading' while you are waiting for the response from your backend. If user opens connect wallet modal at this moment, he will see a loader.
```typescript
tonConnectUI.setConnectRequestParameters({
state: 'loading'
});
```
or
Set state to 'ready' and define `tonProof` value. Passed parameter will be applied to the connect request (QR and universal link).
```typescript
tonConnectUI.setConnectRequestParameters({
state: 'ready',
value: {
tonProof: ''
}
});
```
or
Remove loader if it was enabled via `state: 'loading'` (e.g. you received an error instead of a response from your backend). Connect request will be created without any additional parameters.
```typescript
tonConnectUI.setConnectRequestParameters(null);
```
You can call `tonConnectUI.setConnectRequestParameters` multiple times if your tonProof payload has bounded lifetime (e.g. you can refresh connect request parameters every 10 minutes).
```typescript
// enable ui loader
tonConnectUI.setConnectRequestParameters({ state: 'loading' });
// fetch you tonProofPayload from the backend
const tonProofPayload: string | null = await fetchTonProofPayloadFromBackend();
if (!tonProofPayload) {
// remove loader, connect request will be without any additional parameters
tonConnectUI.setConnectRequestParameters(null);
} else {
// add tonProof to the connect request
tonConnectUI.setConnectRequestParameters({
state: "ready",
value: { tonProof: tonProofPayload }
});
}
```
You can find `ton_proof` result in the `wallet` object when wallet will be connected:
```typescript
tonConnectUI.onStatusChange(wallet => {
if (wallet && wallet.connectItems?.tonProof && 'proof' in wallet.connectItems.tonProof) {
checkProofInYourBackend(wallet.connectItems.tonProof.proof);
}
});
```
```
--------------------------------
### Set Connect Request Parameters with Ton Proof
Source: https://ton-connect.github.io/sdk/modules/_tonconnect_ui.html
Configure `tonConnectUI.setConnectRequestParameters` with `state: 'ready'` and a `tonProof` value to apply specific parameters to the connect request, including QR codes and universal links.
```typescript
tonConnectUI.setConnectRequestParameters({
state: 'ready',
value: {
tonProof: ''
}
});
```
--------------------------------
### UnknownAppError Constructor
Source: https://ton-connect.github.io/sdk/classes/_tonconnect_ui.UnknownAppError.html
Initializes a new instance of the UnknownAppError class. This error is thrown when an app tries to send an RPC request to the injected wallet while not connected.
```APIDOC
## constructor
* new UnknownAppError(
...args: [message?: string, options?: { cause?: unknown }],
): UnknownAppError
#### Parameters
* ...args: [message?: string, options?: { cause?: unknown }]
#### Returns UnknownAppError
```