🏄Solana

LI.FI is live on Solana!

LI.FI REST API offers seamless integration with the Solana blockchain through Allbridge Core. This integration enables users to perform USDC and USDT transfers between Solana and other supported Ethereum Virtual Machine (EVM) compatible chains, including ETH, POL, BSC (only USDT), OPT, AVA, ARB, and BAS.

Note: currently, Solana chain supports only USDC token.

In this documentation, we will explore how to use the API for requesting quotes, executing transactions, getting routes, and checking the status of transactions.

Requesting a Quote

To request a quote for a transaction between Solana and another blockchain, you can use the provided guide. Below is an example of a request to get a quote for transferring 10 USDC from Solana to POL:

const request = {
    fromChain: 'SOL',
    toChain: 'POL',
    fromToken: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v', // USDC on SOL
    toToken: '0x2791bca1f2de4661ed88a30c99a7a9449aa84174', // USDC on POL
    fromAmount: '10000000',
    fromAddress: YOUR_SOL_WALLET_ADDRESS,
    toAddress: YOUR_EVM_WALLET_ADDRESS,
    fromAmountForGas: 37376 // amount in fromToken
}

The key difference between EVM -> SOL and SOL -> EVM transfers is the structure of the transactionRequest. For SOL -> EVM transfers, it contains only a data parameter, which represents base64 encoded Solana transaction data:

"transactionRequest": {
    "data": "AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAsUBmw6CY1QcV7385AuJb6tDdM71YrLbjDGeWn6/zWFZAEcjcsOlIINY3LYFWBe38OO1l26BSpzB1L1bYnVNorsXkDqoJZ5Mb5PNE07yLa8RJGvFV55ILi1+vklkapJoW1yUKv7UyXP9sO3ptc4QOktFqSHRb9AYoDxZXcodBKfc4vN6ai03uOqBMXcmI4cih1E71LnDKMQljw0rqlnVVKOn98YHXWKE3PmeT4MetR4/Ep7+sfN+1vkcpHlwGeEHZgK4EIcmnLsIpOTZxLFhBBVIsDwUJkuCB/B43O01pI8fuLzyjGxJMo5db7lPEcx8Ns2BJ8kYOoL0ob3fnQ0eN3JwPzibblpkKkSjSk1qpqwB4d5rSn1PrbBHf6rOIO/O/W6AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABceQrkgrAQHdCyf7CIDjBD/Y4pzKA7iTYhaafiX1eik37c9HIG4v1EeQo1ENAm3KHS+LCOKkZ4WQntGZQgIyu7ixIazui3zX0pmHiw3K3u/XdzSJfZ+ugLzVfJnnOn3v2RmLUngAdF+k4G2bOshpHaEkSZUr1Y1/vT3G9R/qU8zKFLzTYC6vfOspR18AlAfdoQQSzchbXIKs9TVzmL7XEYAwZGb+UhFzL/7K26csOb57yM5bvF9xJrLEObOkAAAADG+nrzvtutOj1l82qryXQxsbvkwtL24OR8pgIDRS9dYceCg/3UzgsruALUdoCSm3XiyBz8VtBPnGEIhrYpcBQ26zvkSidWkhDjuJPqY+9JDKulE8Bq2dVUioc+URRKUUsG3fbh12Whk9nL4UbO63msHLSF7V9bN5E6jPWFfv8AqTLHwyN3CxGdzcZNzliJWl0TJu3X7nF6oB9sysdDGG/6Ag8ABQJAQg8ADhMAAAcQBAMMAQgRAgYLDRIFChMJccw/qau6fVaf/aDz3hWN+Sh9oNuBvkrLv0ttxmLuxpa1pXsmnZ0BxMAAAAAAAAAAAAAAAABVIAjA9ocML3flzB0uub3/A+MOoAUAAAAAAAAAAAAAAAAnkbyh8t5GYe2IowyZp6lEmqhBdOkDAAAAAAAA"
}

Executing the Transaction

To execute the transaction, you will need to perform several steps:

  1. Decode your Solana private key.

  2. Create a connection to the Solana network.

  3. Decode the transaction data received from the /quotes response.

  4. Deserialize the decoded transaction data into a VersionedTransaction.

  5. Sign the transaction with your Solana keypair.

  6. Send the transaction to the Solana network.

  7. Confirm the transaction's status.

import solanaWeb3, {
  BlockheightBasedTransactionConfirmationStrategy,
  VersionedTransaction,
} from '@solana/web3.js'
import base64 from 'ethers/lib/utils'
import bs58 from 'bs58'

const keypair = solanaWeb3.Keypair.fromSecretKey(bs58.decode(YOUR_SOLANA_PRIVATE_KEY)) // get Solana keypair

const connection = new solanaWeb3.Connection(RPC_PROVIDER_URL, 'confirmed') // create a connection
const decodedTx = base64.decode(transactionRequest.data.toString()) // decode tx data
const deserializedTx = VersionedTransaction.deserialize(decodedTx) // deserialize decoded tx data into VersionedTransaction

deserializedTx.sign([keypair]) // sign the tx with your keypair
const txid = await connection.sendTransaction(deserializedTx, {
  maxRetries: 5,
  skipPreflight: true,
}) // send the tx

await connection.confirmTransaction(
  {
    signature: txid,
  } as BlockheightBasedTransactionConfirmationStrategy,
  'confirmed'
) // confirm the tx

Getting Routes

Routes provide the necessary information to initiate a transaction request. Here are two guides on how to request the route and execute it. Here's an example of a typical /routes request from POL to SOL:

{
  "fromChainId": "POL",
  "fromAmount": "2000000",
  "fromTokenAddress": "0x2791bca1f2de4661ed88a30c99a7a9449aa84174", // USDC on POL,
  "toChainId": "SOL",
  "toTokenAddress": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", // USDC on SOL,
  "fromAddress": YOUR_EVM_WALLET_ADDRESS,
  "toAddress": YOUR_SOLANA_WALLET_ADDRESS,
  "fromAmountForGas": 284126,
  "options": {
    "slippage": 0.03
  }
}

You can set the fromAmountForGas parameter in /routes or /quotes requests to receive gas on the destination chain. Please note that this value is limited by the Allbridge API, and if it exceeds the limit, the error with the suggested maximum value will be returned.

The maximum limit you can receive on the destination chain can be found by calling the Allbridge token-info endpoint. The txCostAmount.maxAmount parameter dictates the max amount that can be received in native token.

To execute the route, you need to pick one step from routes with the lifi type and make a /stepTransaction call.

Getting a Transaction to execute

To obtain transaction data for execution, you need to provide a full Step object. Typically, this object is retrieved by calling the /routes endpoint and selecting the most suitable route. Afterward, you can retrieve the transaction data for each required step using the /stepTransaction endpoint.

Here, you can find our full API reference

Typical /stepTransaction request will look like the following:

{
    "type": "lifi",
    "id": "306d4449-77bf-4e80-9755-2ad4349655b9",
    "tool": "allbridge",
    "toolDetails": {
        "key": "allbridge",
        "name": "Allbridge",
        "logoURI": "https://raw.githubusercontent.com/lifinance/types/main/src/assets/icons/bridges/allbridge.png"
    },
    "action": {
        "fromChainId": 137,
        "fromAmount": "2000000",
        "fromToken": {
            "address": "0x2791bca1f2de4661ed88a30c99a7a9449aa84174",
            "chainId": 137,
            "symbol": "USDC",
            "decimals": 6,
            "name": "USD Coin",
            "priceUSD": "1",
            "logoURI": "https://static.debank.com/image/coin/logo_url/usdc/e87790bfe0b3f2ea855dc29069b38818.png",
            "coinKey": "USDC"
        },
        "fromAddress": YOUR_EVM_WALLET_ADDRESS,
        "slippage": 0.03,
        "toChainId": 1151111081099710,
        "toToken": {
            "name": "USD Coin",
            "symbol": "USDC",
            "decimals": 6,
            "address": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
            "chainId": 1151111081099710,
            "logoURI": "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48/logo.png",
            "priceUSD": "1",
            "coinKey": "USDC"
        },
        "toAddress": YOUR_SOL_WALLET_ADDRESS
    },
    "estimate": {
        "tool": "allbridge",
        "fromAmount": "2000000",
        "fromAmountUSD": "2.00",
        "toAmount": "1992509",
        "toAmountMin": "1992509",
        "approvalAddress": "0x1231DEB6f5749EF6cE6943a275A1D3E7486F4EaE",
        "executionDuration": 120,
        "feeCosts": [
            {
                "name": "Allbridge's fee",
                "description": "AllBridge fee and messenger fee charged by Allbridge",
                "token": {
                    "address": "0x0000000000000000000000000000000000000000",
                    "chainId": 137,
                    "symbol": "MATIC",
                    "decimals": 18,
                    "name": "MATIC",
                    "priceUSD": "0.555942",
                    "logoURI": "https://static.debank.com/image/matic_token/logo_url/matic/6f5a6b6f0732a7a235131bd7804d357c.png",
                    "coinKey": "MATIC"
                },
                "amount": "224311470291386207",
                "amountUSD": "0.12",
                "percentage": "0.1247",
                "included": false
            }
        ],
        "gasCosts": [
            {
                "type": "SEND",
                "price": "119204890145",
                "estimate": "55000",
                "limit": "82500",
                "amount": "6556268957975000",
                "amountUSD": "0.01",
                "token": {
                    "address": "0x0000000000000000000000000000000000000000",
                    "chainId": 137,
                    "symbol": "MATIC",
                    "decimals": 18,
                    "name": "MATIC",
                    "priceUSD": "0.555942",
                    "logoURI": "https://static.debank.com/image/matic_token/logo_url/matic/6f5a6b6f0732a7a235131bd7804d357c.png",
                    "coinKey": "MATIC"
                }
            }
        ],
        "toAmountUSD": "1.99"
    },
    "includedSteps": [
        {
            "id": "e5490b84-fa3a-4bc8-bb3a-f6cd7f59c15e",
            "type": "cross",
            "action": {
                "fromChainId": 137,
                "fromAmount": "2000000",
                "fromToken": {
                    "address": "0x2791bca1f2de4661ed88a30c99a7a9449aa84174",
                    "chainId": 137,
                    "symbol": "USDC",
                    "decimals": 6,
                    "name": "USD Coin",
                    "priceUSD": "1",
                    "logoURI": "https://static.debank.com/image/coin/logo_url/usdc/e87790bfe0b3f2ea855dc29069b38818.png",
                    "coinKey": "USDC"
                },
                "fromAddress": YOUR_EVM_WALLET_ADDRESS,
                "slippage": 0.03,
                "toChainId": 1151111081099710,
                "toToken": {
                    "name": "USD Coin",
                    "symbol": "USDC",
                    "decimals": 6,
                    "address": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
                    "chainId": 1151111081099710,
                    "logoURI": "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48/logo.png",
                    "priceUSD": "1",
                    "coinKey": "USDC"
                },
                "toAddress": YOUR_SOL_WALLET_ADDRESS
            },
            "estimate": {
                "tool": "allbridge",
                "fromAmount": "2000000",
                "fromAmountUSD": "2.00",
                "toAmount": "1992509",
                "toAmountMin": "1992509",
                "approvalAddress": "0x7775d63836987f444E2F14AA0fA2602204D7D3E0",
                "executionDuration": 120,
                "feeCosts": [
                    {
                        "name": "Allbridge's fee",
                        "description": "AllBridge fee and messenger fee charged by Allbridge",
                        "token": {
                            "address": "0x0000000000000000000000000000000000000000",
                            "chainId": 137,
                            "symbol": "MATIC",
                            "decimals": 18,
                            "name": "MATIC",
                            "priceUSD": "0.555942",
                            "logoURI": "https://static.debank.com/image/matic_token/logo_url/matic/6f5a6b6f0732a7a235131bd7804d357c.png",
                            "coinKey": "MATIC"
                        },
                        "amount": "224311470291386207",
                        "amountUSD": "0.12",
                        "percentage": "0.1247",
                        "included": false
                    }
                ],
                "gasCosts": [
                    {
                        "type": "SEND",
                        "price": "119204890145",
                        "estimate": "55000",
                        "limit": "82500",
                        "amount": "6556268957975000",
                        "amountUSD": "0.01",
                        "token": {
                            "address": "0x0000000000000000000000000000000000000000",
                            "chainId": 137,
                            "symbol": "MATIC",
                            "decimals": 18,
                            "name": "MATIC",
                            "priceUSD": "0.555942",
                            "logoURI": "https://static.debank.com/image/matic_token/logo_url/matic/6f5a6b6f0732a7a235131bd7804d357c.png",
                            "coinKey": "MATIC"
                        }
                    }
                ]
            },
            "tool": "allbridge",
            "toolDetails": {
                "key": "allbridge",
                "name": "Allbridge",
                "logoURI": "https://raw.githubusercontent.com/lifinance/types/main/src/assets/icons/bridges/allbridge.png"
            }
        }
    ]
}

The response from such a call will have the same type as the /quote response.

Checking the Status of a Transaction

To check the status of a Solana transaction, you can follow the provided guide, which will help you monitor the progress and confirmation of your transaction on the Solana blockchain.

Last updated