Skip to main content
Author(s): STON.fi Team
This guide was contributed by the STON.fi Team, and has not been validated by Privy. Please review and test thoroughly before using in production. If you find a bug or problem with this resource, please let Privy support know and we’ll alert STON.fi Team.
This guide extends the Getting started with Privy and TON application by adding token swap functionality using Omniston - a protocol that aggregates liquidity from multiple DEXes including STON.fi and DeDust.

Prerequisites

Before starting this guide, ensure you have:
  • Completed the Getting started with Privy and TON guide
  • A working React app with Privy authentication for TON
  • A deployed and funded TON wallet (minimum 0.05 TON for gas fees)
  • The existing utilities and hooks from the previous guide already implemented

Step 1: Install Omniston SDK and STON.fi API

From your existing project root, install the Omniston SDK and STON.fi API:

Step 2: Add Omniston provider

Update your src/main.tsx to add the Omniston provider:

Step 3: Create asset fetching hook

Create a simple hook to fetch available tokens:

Step 3.5: Add utility files

The swap hook needs some utility files to work with TON and Privy. Create these if you don’t have them already:

Step 4: Create the swap hook

This hook handles quoting, building transactions, signing with Privy, and tracking:
This hook integrates Omniston’s RFQ (Request for Quote) system to find the best swap rates across multiple DEXes, then builds and signs transactions using Privy’s embedded wallet.

Step 5: Create the swap interface component

Build a simple swap interface:

Step 6: Integrate with your TonWalletManager

Add tabs to switch between wallet and swap functionality in your existing TonWalletManager component:

Step 7: Test your integration

  1. Start your development server:
  1. Test the complete flow:
    • Log in with your email
    • Ensure your wallet is deployed and funded
    • Switch to the Swap tab
    • Select tokens to swap (e.g., TON → USDT)
    • Enter an amount
    • Review the quote
    • Execute the swap
    • Monitor the trade status

Troubleshooting

Common Issues

  • “Only embedded wallets are supported”
    • The swap functionality only works with Privy embedded wallets
    • Imported or delegated wallets are not supported
  • “Wallet not deployed”
    • Deploy your wallet first using the deployment flow from the previous guide
    • Ensure you have at least 0.05 TON for deployment
  • “Insufficient balance”
    • Swaps require the input amount plus gas fees (be sure to have at least ~0.2 TON for gas)
    • Top up your wallet and try again

Summary

This guide extends your Privy + TON application with:
  • Omniston SDK integration for DEX aggregation
  • Quote fetching from multiple liquidity sources
  • Transaction building and signing with Privy
  • Real-time trade tracking
  • A polished swap UI with error handling
You can now seamlessly swap tokens on TON blockchain using Privy embedded wallets, with the best rates aggregated from multiple DEXes.