Swaps VIA deposit

This page explains how to execute a transaction via deposit using Rubic API.

Swap via deposit does not require a wallet connection. User should make a deposit by himself.

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

async function quoteBest() {
    const response = await fetch("https://api-v2.rubic.exchange/api/routes/quoteBest", {
        method: "POST",
        headers: {
            "Content-Type": "application/json",
        },
        body: {
            "srcTokenAddress": "0x0000000000000000000000000000000000000000",
            "srcTokenAmount": "3",
            "srcTokenBlockchain": "COSMOS",
            "dstTokenAddress": "0x0000000000000000000000000000000000000000",
            "dstTokenBlockchain": "TRON",
            "referrer": "rubic.exchange"
          }
    });
    const data = await response.json();
    const { estimate, transaction, id } = data;
    console.log(estimate);
    // {
    //     This is an estimated amount you will get after the swap.
    //     "destinationTokenAmount": "56.797373",
    //     "destinationTokenMinAmount": "55.093452",
    //
    //     "destinationUsdAmount": 13.26,
    //     "destinationUsdMinAmount": 12.86,
    //
    //     "destinationWeiAmount": "56797373",
    //     "destinationWeiMinAmount": "55093452",
    //
    //     "durationInMinutes": 5,
    //     "priceImpact": 3.29,
    //     "slippage": 0.03
    // }
    
    console.log(id);
    // This is the swap ID. It will be needed later for swap request.
    return data;
}

You get more information about quote endpoint here:

Request Quote

Retrieving deposit quotes

We can request deposit quotes even without wallet connection.

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

You get more information about deposit quote endpoint here:

Request Quote

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:

Request Data

Retrieving Deposit Data to Make Transfer

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/swapDepositTrade

Executing a Transaction with the API Response Data

You should display the depositAddress, amountToSend, exchangeId and extraFields fields from the transaction object in your UI. The user should send amount to the received depositAddress from his wallet by himself.

User should pass the extraFields.value field otherwise the transaction may fail.

The screenshot shows how a user should make a deposit:

Last updated

Was this helpful?