Swapping Tokens
Discover how to swap tokens efficiently using ONTON Finance
Introduction
ONTON Finance is a decentralized exchange (DEX) built on the TON blockchain, offering users a seamless and cost-effective way to swap tokens. By leveraging the Automated ONTON DEX (AMM) model, ONTON Finance enables users to trade tokens directly from liquidity pools, ensuring fast and efficient transactions.
Step-by-Step Guide to Swapping Tokens
Follow these simple steps to swap tokens on ONTON Finance:
-
Connect your wallet: Visit the ONTON Finance website and connect your TON wallet by clicking on the “Connect Wallet” button in the top right corner of the screen.
-
Select tokens: Choose the token pair you want to swap from the dropdown menus. For example, if you want to swap USDT for ONTON, select USDT in the “From” field and ONTON in the “To” field.
-
Enter the amount: Enter the amount of tokens you want to swap in the “From” field. The “To” field will automatically display the estimated amount of tokens you will receive based on the current exchange rate.
-
Review the details: Before confirming the transaction, review the swap details, including the exchange rate, slippage tolerance, and transaction fees. Adjust the slippage tolerance if needed.
-
Confirm the swap: If you are satisfied with the details, click the “Swap” button to initiate the transaction. Your wallet will prompt you to confirm the transaction and pay the associated fees.
-
Transaction complete: Once the transaction is confirmed on the TON blockchain, the swapped tokens will be deposited into your wallet. You can view your updated token balances in your wallet or on the ONTON Finance platform.
Detailed Transaction Flow Using SDK
To further illustrate the transaction flow and the use of the ONTON Finance SDK, refer to the mermaid diagram below:
SDK Usage Breakdown
To integrate ONTON Finance SDK into your application for token swapping, follow these steps:
Prerequisites
Ensure you have Node.js (version 18.10.0 or higher) installed on your machine.
Step 1: Install the Onton SDK
Add the Onton SDK to your project using npm:
Step 2: Import Required Libraries
Import the necessary libraries and configure environment variables:
Step 3: Define Helper Function to Await Seqno Change
Create a helper function to wait until the sequence number (seqno
) changes, ensuring transaction confirmation:
Step 4: Initialize Onton SDK and Execute Operations
Set up the main function to initialize the SDK and perform the token swap:
Replace the following environment variables with your actual values:
API_KEY
WALLET_ADDRESS
TOKEN0_JETTON_ADDRESS
TOKEN1_JETTON_ADDRESS
TOKEN0_AMOUNT
TOKEN1_AMOUNT
MNEMONIC
REFERRAL_ADDRESS
Applications and Integration Examples
Decentralized Finance (DeFi) Platforms
DeFi platforms can integrate the ONTON Finance SDK to offer users token swapping services directly within their interface. This can include yield farming platforms, lending and borrowing protocols, and decentralized exchanges.
Crypto Wallets
Crypto wallets can enhance their functionality by integrating the SDK to enable in-app token swaps. This provides users with a one-stop solution for managing their assets, reducing the need to use multiple platforms.
eCommerce and Payment Solutions
eCommerce platforms and payment solutions can use the SDK to accept a variety of cryptocurrencies, automatically swapping tokens as needed to provide seamless payment options for users.
Gaming and Virtual Worlds
Blockchain-based games and virtual worlds can integrate the SDK to facilitate in-game currency exchanges, enabling players to trade and swap tokens without leaving the game environment.
Tokenized Communities and DAOs
Decentralized Autonomous Organizations (DAOs) and tokenized communities can leverage the SDK to manage their native tokens, facilitate voting mechanisms, and distribute rewards to members.
Cross-Chain Bridges
Developers can build cross-chain bridges that utilize the ONTON Finance SDK to facilitate token swaps between different blockchain networks, enhancing liquidity and accessibility for users.
Investment and Portfolio Management Apps
Investment apps can integrate the SDK to allow users to rebalance their portfolios by swapping tokens directly within the app, providing a streamlined and efficient user experience.
Example: Integrating the SDK into a Crypto Wallet
Here’s an example of how to integrate the ONTON Finance SDK into a crypto wallet application:
Step 1: Install the Onton SDK
Add the Onton SDK to your project using npm:
Step 2: Import Required Libraries
Import the necessary libraries and configure environment variables:
Step 3: Define Helper Function to Await Seqno Change
Create a helper function to wait until the sequence number (seqno
) changes, ensuring transaction confirmation:
Step 4: Initialize Onton SDK and Execute Operations
Set up the main function to initialize the SDK and perform the token swap:
Replace the following environment variables with your actual values:
YOUR_API_KEY_HERE
YOUR_WALLET_ADDRESS_HERE
YOUR_SEND_JETTON_ADDRESS
YOUR_RECEIVE_JETTON_ADDRESS
YOUR_MNEMONIC_HERE
YOUR_REFERRAL_ADDRESS_HERE
By integrating the ONTON Finance SDK, developers can unlock a wide range of possibilities for enhancing their applications and providing users with a seamless, secure, and efficient token swapping experience.
Onton SDK Version
Ensure you are using the latest version of the Onton SDK to access the newest features and improvements.
Deployment
ONTON Finance is built on the TON blockchain, ensuring fast and secure transactions.
When you deploy your application using the Onton SDK, it interacts directly with the TON blockchain. No additional deployment steps are required.
Troubleshooting
Below are some common issues you might encounter while using the Onton SDK and their solutions:
Invalid Private Key
Ensure that you are using a valid private key when initializing the OntonSDK instance. Double-check your private key and ensure it is in the correct format.
Insufficient Balance
Make sure the account associated with your private key has enough balance to perform the required operations, such as swapping tokens or providing liquidity.
Network Connection Issues
Check your network connection and ensure you can successfully connect to the TON blockchain network. Verify that your firewall or network settings are not blocking the connection.
If you encounter any other issues or have questions, please contact our support team or consult the ONTON Finance community forum for assistance.
For the latest updates and changes to the Onton SDK, please refer to the SDK Changelog.
Quick Start
For a quick start with the Onton SDK, follow the steps outlined above in the SDK Usage Breakdown section. Ensure you have all prerequisites installed and environment variables configured correctly.