circle-checkSwaps from TON

Connecting a Web3 Wallet and Executing a Transaction through Rubic API

This page explains how to connect a Web3 wallet, retrieve token quotes, approve tokens, and execute a transaction using Rubic API, with examples using TonConnectUI

Connecting a Web3 Wallet

To interact with the blockchain, we first need to connect a wallet. Here are examples using TonConnectUI.

import { TonConnectUI } from '@tonconnect/ui';

async function connectWallet() {
    const tonConnect = new TonConnectUI(...);

    try {
          await this.tonConnect.connector.restoreConnection();
      } catch {}
      const isConnected = (await this.tonConnect.connectionRestored) && 
          tonConnect.connected;

      if (!isConnected) {
        const payload = await RetroBridgeApiService.getMessageToAuthWallet();
        this.tonConnect.setConnectRequestParameters({
          state: 'ready',
          value: { tonProof: this.window.btoa(payload) }
        });
        await this.openWalletModal();
      }
}

Retrieving Token Quotes

Now that the wallet is connected, we can request token quotes from Rubic API.

Endpoint: POST https://api-v2.rubic.exchange/api/routes/quoteBest

You get more information about quote endpoint here:

1Request Quotechevron-right

Retrieving Data to Execute a Transaction

To perform a token swap through Rubic API, we need to get the necessary data for the transaction.

Endpoint: POST https://api-v2.rubic.exchange/api/routes/swap

You get more information about swap endpoint here:

2Request Datachevron-right

Executing a Transaction with the API Response Data

Using the data obtained from the Rubic API, you can now execute the transaction.

Track your transaction

Now you can track your transaction status

Endpoint: GET https://api-v2.rubic.exchange/api/routes/status

You get more information about status endpoint here:

3Get Cross-Chain Statuschevron-right

Last updated