Omniston Guide (React)

Quick integration guide for Omniston - start building cross-DEX aggregation features in minutes

This guide will walk you through creating a basic token swap app using the Omniston protocol to swap assets across different DEXes (STON.fi V1, STON.fi V2, DeDust, etc.). We'll integrate wallet connectivity with TonConnect (via @tonconnect/ui-react) to allow users to connect their TON wallet and perform a swap. The guide is beginner-friendly and assumes minimal React experience.

Note: In this demo, we will leverage Tailwind CSS for styling instead of using custom CSS. The setup for Tailwind CSS is already included in the instructions below, so you don't need to set it up separately.

Note: You can use any package manager (npm, yarn, pnpm, or bun) to set up your React project. In this tutorial, we'll demonstrate with pnpm.


Table of Contents


1. Introduction

In this quickstart, we will build a minimal React app to:

  • Connect to a TON wallet (via TonConnect UI).

  • Fetch available tokens from STON.fi and display them in dropdowns.

  • Request a quote (RFQ) from Omniston for the best swap route (no separate "Simulate" step needed; Omniston fetches quotes automatically).

  • Build and execute a swap transaction across multiple DEXes.

  • Track the trade status until completion.

We will use:

  • @ston-fi/omniston-sdk-react – React hooks to interact with Omniston (request quotes, track trades, etc.).

  • @ston-fi/api – Fetch token lists from STON.fi (and potentially other data).

  • @tonconnect/ui-react – Provides a React-based TON wallet connect button and utilities.

  • @ton/core – TON low-level library used for advanced functionality.


2. Setting Up the Project

2.1 Create a React App

First, let's check if pnpm is installed on your system:

If you see a version number (like 10.4.0), pnpm is installed. If you get an error, you'll need to install pnpm first:

Now we'll create a new React project using Vite. However, you can use any React setup you prefer (Next.js, CRA, etc.).

Run the following command to create a new Vite-based React project:

When prompted, type your desired project name (e.g., omniston-swap-app):

Then enter the folder:


2.2 Installing the Required Packages

Within your new React project directory, install the Omniston SDK, TonConnect UI, the TON core library, and STON.fi API library:

Next, install Tailwind CSS and its Vite plugin:

Additionally, install the Node.js polyfills plugin for Vite, which is necessary to provide Buffer and other Node.js APIs in the browser environment (required by TON libraries):

Configure the Vite plugin by updating vite.config.js file. Only the buffer shim plus the global Buffer are required for TON libraries, so the configuration stays tight:

Then, import Tailwind CSS in your main CSS file. Open src/index.css and replace any existing code with:

You can also remove src/App.css (we don't need it), and remove the import statement import './App.css' from src/App.tsx.

After making these changes, you can verify that your app still runs correctly by starting the development server:

This should launch your app in development mode, typically at http://localhost:5173. You should see the Vite + React logo and text on a plain white background. Since we've removed the default styling (App.css), the page will look simpler than the default template.

If you see the logo and text, it means your Vite + React setup is working correctly. Make sure everything loads without errors before proceeding to the next step.


3. Connecting the Wallet

3.1 Add nessary providers

Open src/main.tsx (Vite's default entry point) and wrap your application with both the TonConnectUIProvider and OmnistonProvider. The TonConnectUIProvider makes the TonConnect context available to your app for wallet connectivity, while the OmnistonProvider enables Omniston's functionality throughout your application. Also, point the TonConnect provider to a manifest file (which we will create next) that describes your app to wallets.


3.2 Create the TonConnect Manifest

In the public folder of your project, create a file named tonconnect-manifest.json. This manifest provides wallet apps with information about your application (like name and icon). You should customize this manifest for your own application. Here's an example:

Make sure to update these fields for your application:

  • url: The base URL where your app is served

  • name: Your application's display name (this is what wallets will show to users)

  • iconUrl: A link to your app's icon (should be a 180×180 PNG image)

Make sure this file is accessible. When the dev server runs, you should be able to fetch it in your browser at http://localhost:5173/tonconnect-manifest.json.


3.3 Add the Connect Wallet Button

In your main App component (e.g., src/App.tsx), import and include the TonConnectButton. For example:


4. Fetching Available Assets

Next, let's dynamically retrieve the list of tokens (assets) that can be swapped on STON.fi. We use the STON.fi API client (@ston-fi/api) for this. Here's a simplified example that filters assets by liquidity (high to medium). We'll store them in state and present them in From/To dropdowns.

First, add the necessary imports to what we have in src/App.tsx:

Initialize the state variables in your App component:

Add the asset fetching logic with useEffect:

Create the main UI structure:

Add the token selection dropdowns:

Add the loading state and close the component:


5. Requesting a Quote

We'll use the useRfq hook from @ston-fi/omniston-sdk-react to request a quote. It will fetch quotes automatically based on the parameters given.

Add additional imports to the top of the file:

Add utility functions for converting token amounts:

Set up the useRfq hook to automatically fetch quotes:

Add the quote display section to your tsx (insert after the amount input field):

Any time the user changes the token or amount, useRfq automatically refreshes the quote.


6. Building a Transaction and Sending It

Once we have a quote, we can build the transaction that will execute the swap. We'll use the useOmniston hook to access the Omniston instance and build the transaction.

Replace imports for @tonconnect/ui-react and @ston-fi/omniston-sdk-react with:

Add wallet connection hooks and omniston instance:

Create the transaction building function:

Add the swap execution function:

Add the Execute Swap button (insert after in quote section):


7. Tracking Your Trade

7.1 Install the TON Package

We'll track trades using the useTrackTrade hook from @ston-fi/omniston-sdk-react. First, ensure you have the @ton/ton package installed if you haven't already:

7.2 Using the useTrackTrade Hook

After you've built and sent the swap transaction, you can track its status with useTrackTrade. This hook takes the quoteId of the trade, your wallet address, and the outgoing transaction hash. It periodically checks the trade's on-chain status, letting you know if it's pending, settled, or partially filled.

Replace imports for @ton/ton and @ston-fi/omniston-sdk-react for trade tracking:

Add state variables for tracking:

Reset tracking state when inputs change:

Update the useRfq hook to stop fetching quotes during trade execution:

Set up the trade tracking hook:

Add helper function to translate trade results:

Add utility functions for transaction hash extraction:

Update the handleSwap function to capture transaction details:

Add the trade status display (insert after the divider line):

Update the error display in the quote section


8. Testing Your Swap

  1. Start the development server:

  1. Open your app in the browser at http://localhost:5173.

  2. Connect your TON wallet via the "Connect Wallet" button.

  3. Select tokens from the dropdowns and enter an amount.

  4. Omniston automatically fetches and displays a quote. Confirm it's valid.

  5. Click "Execute Swap" to finalize the transaction. Approve it in your wallet.

  6. Once the swap completes on-chain, your wallet balances should update accordingly.


9. Conclusion

Congratulations! You've built a minimal React + Vite app with Tailwind CSS that:

  • Connects to a TON wallet using TonConnect.

  • Dynamically fetches available tokens from STON.fi.

  • Requests real-time quotes (RFQs) from Omniston automatically.

  • Builds and sends swap transactions.

Feel free to expand this demo with:

  • Custom slippage settings.

  • Better error-handling and success notifications.

  • Additional settlement methods or cross-chain logic.

  • Learn how to add referral fees to your Omniston swaps by reading the Referral Fees guide.

Happy building with Omniston!

10. Live Demo

With this Replit demo, you can:

  • Open the project directly in your browser

  • Fork the Replit to make your own copy

  • Run the application to see it in action

  • Explore and modify the code to learn how it works

  • Experiment with different features and UI changes

Alternatively, you can run this example locally by cloning the GitHub repository:

This will start the development server and you can access the app at http://localhost:5173.

11. Advanced Example App

For those seeking a feature-rich, more advanced approach, we also have a Next.js Omniston Demo App that:

  • Uses Next.js for a scalable framework

  • Utilizes hooks and providers for an elegant architecture

  • Demonstrates better error handling, robust state management, and additional STON.fi and Omniston features

You can explore the code in our repository:

Omniston SDK Next.js Demo App

Or see it in action at our live demo:

Omniston Demo App

12. Using AI Agents for Automated Implementation

For developers looking to accelerate their development process, you can leverage AI coding agents to automatically implement the Omniston swap functionality described in this guide. While we showcase Gemini CLI in our example (due to its generous free tier), you can use any AI coding assistant such as Claude Code, GitHub Copilot, Cursor Agent, or similar tools.

You can also follow along with a recorded walkthrough:

12.1 Why AI Agents?

Modern AI coding agents can:

  • Understand complex documentation and implement complete features

  • Set up project structure and dependencies automatically

  • Handle common configuration and setup errors

  • Provide working implementations in minutes instead of hours

12.2 Setting Up with Gemini CLI (Example)

We'll demonstrate with Gemini CLI, but the approach works with any AI agent that can read documentation and execute commands.

12.2.1 Installing Gemini CLI

  1. Install the Gemini CLI by following the instructions at: https://github.com/google-gemini/gemini-cli

  2. Authenticate with your Google account when prompted. The free tier includes:

    • 60 model requests per minute

    • 1,000 model requests per day

12.2.2 Setting Up the Implementation Guide

  1. Download the GEMINI.md file from the gist: https://gist.github.com/mrruby/311a9d96f12bc7303bb1046dc92092b3

  2. Rename the file based on your AI agent:

    • For Gemini CLI: Use GEMINI.md as-is (no renaming needed)

    • For Claude Code: Rename GEMINI.md to CLAUDE.md

    • For other AI agents (GitHub Copilot, Cursor, etc.): Rename GEMINI.md to AGENTS.md

  3. Create a new directory for your project and place the guide file inside it:

12.2.3 Running the Automated Implementation

  1. From within your project directory, run the Gemini CLI:

  2. When the CLI interface opens, type:

  3. The AI agent will:

    • Ask for permission to use commands like pnpm, npm, etc.

    • Automatically create the project structure

    • Install all necessary dependencies

    • Implement the complete swap functionality

    • Set up the UI components and styling

  4. If any errors occur during the process:

    • Simply paste the error message back to the AI agent

    • It will analyze and fix the issue automatically

    • In most cases, the implementation completes successfully in one shot

12.3 Using Other AI Agents

The same approach works with other AI coding assistants:

  • Gemini CLI: Download GEMINI.md from the gist and use as-is

  • Claude Code: Download GEMINI.md from the gist and rename it to CLAUDE.md, then place it in your project and ask Claude Code to implement the guide

  • GitHub Copilot: Download GEMINI.md from the gist and rename it to AGENTS.md, open the guide in your editor and use Copilot Chat to implement step by step

  • Cursor Agent: Download GEMINI.md from the gist and rename it to AGENTS.md, load the documentation and request full implementation via Cursor's agent mode

  • Other AI Tools: Download GEMINI.md and rename to AGENTS.md for compatibility with most AI assistants

Note: The gist contains GEMINI.md which works directly with Gemini CLI. For Claude Code, rename it to CLAUDE.md. For other AI agents (GitHub Copilot, Cursor, etc.), rename it to AGENTS.md for best compatibility.

12.4 Benefits of Using AI Agents

  • Speed: Get a working implementation in minutes instead of hours

  • Accuracy: AI agents follow the quickstart guide precisely

  • Error Handling: Automatically resolve most common setup issues

  • Learning Tool: Watch how the implementation unfolds step by step

  • Customization: After the initial setup, you can modify the generated code to fit your specific needs

  • Cost-Effective: Many AI coding tools offer free tiers (like Gemini CLI) or are included in existing subscriptions

12.5 Best Practices

  1. Review the Code: Always review AI-generated code before using it in production

  2. Understand the Flow: Use the generated code as a learning tool to understand the Omniston protocol

  3. Customize: Adapt the generated code to your specific requirements

  4. Test Thoroughly: Test the implementation with small amounts before processing larger transactions

  5. Security: Never commit API keys or mnemonics to version control

This approach is particularly useful for:

  • Developers new to the TON ecosystem

  • Quick prototyping and proof-of-concepts

  • Learning by example with a working implementation

  • Avoiding common setup pitfalls and configuration errors

  • Exploring different implementation approaches rapidly

Last updated