Author(s): STON.fi Team
This guide demonstrates how to integrate Privy with the TON blockchain in a Vite + React app to enable wallet login as well as message and transaction signing.
Resources
Privy TON Wallets
Learn how to use Privy embedded wallets with TON for signing messages and transactions.
React quickstart
Get started with Privy’s React SDK.
Creating your Privy app
If you haven’t set up Privy yet, follow our React quickstart guide
to get your app ID and configure your app.
Installing with Vite
Create a new Vite + React + TypeScript application and install the required dependencies:vite.config.js file:
src/index.css and replace any existing code with:
src/App.css (we don’t need it), and remove the import statement import './App.css' from src/App.tsx if it exists.
Environment variables
Vite requires environment variables to be prefixed withVITE_:
Setting up the app entry point
Set up the main entry point with the Privy provider directly in your main.tsx file:Using Privy in your app
With Privy integrated, you can authenticate users, generate embedded wallets, and facilitate message and transaction signing.Log in with Privy
To log in users with Privy, use theuseLogin hook:
Creating a TON embedded wallet
First, create a custom hook to access the TON wallet from Privy’s linked accounts:useCreateWallet hook from extended chains to create a wallet:
Getting wallet balance
To check the balance of a TON wallet using our custom hooks and utilities:Checking wallet deployment status
TON wallets are smart contracts that need to be deployed before they can be used. Create a hook to check the deployment status:Deploying the wallet
Signing a message
To sign a message with a TON embedded wallet, we use the browser’s crypto.subtle API to hash the message to 32 bytes (SHA-256), which is then signed via signRawHash:Sending a transaction
To send TON from the embedded wallet using browser-compatible methods:Wallet deployment status component
Create a component to inform users about wallet deployment:Complete example container
Here’s the complete application that brings together all the components we’ve created:Creating the main App component
The App.tsx component will contain your main application logic:Run
Summary
-
Configure env
- In
.env(or.env.development), set: VITE_PRIVY_APP_ID=<your app id>VITE_TON_API_KEY=<optional toncenter api key>
- In
-
Start the app
- Run
npm run devand open the local URL.
- Run
-
Log in
- Click Log in with Privy (email auth).
-
Create a TON wallet (once)
- If you don’t have one yet, click Create TON Wallet.
-
Fund the wallet
- Send ≥ 0.05 TON to the wallet address shown in the UI.
-
Deploy the wallet
- Click Deploy Wallet once funded.
- Wait until you see ✓ Wallet is deployed.
-
Sign a message
- Click Sign Message to sign an example message (check the console for the signature).
-
Send TON
- Enter Recipient address (EQ…) and Amount in TON.
- Click Send … TON and wait for the success notice.

