Swap Endpoint

The /swap endpoint allows you to execute a token swap on the Solana blockchain. This endpoint prepares the transaction for you to sign and send to the chain.

Jito is now supported by the API! set the jitoTip param to include a tip instruction in your serialized transaction.

We currently support the following:

  • Pump.fun
  • Moonshot
  • Orca
  • Raydium
  • Raydium CPMM
  • Tokens supported by Jupiter

Request

GET https://swap.solxtence.com/swap

Parameters

ParameterDescriptionExample
from *The address of the token you're swapping fromSo11111111111111111111111111111111111111112
to *The address of the token you're swapping to2CKpz5rLrXZSmoTwwskCiYgSEDhyuqM2q4s5znJVRrFA
amount *The amount of the 'from' token you want to swap2
payer *The public key of the wallet that is sending the transactionDL2aVh5Cj7vxUyCyRSht1D7N19SPH3tyPLdUUTp6FhNG
slipdefault is auto. The maximum slippage percentage you're willing to accept10
feeDefault is auto. Priority fee: extra SOL you are willing to pay to speed up the transaction.0.000005
jitoTipJito tip in SOL. If set, A jito tip instruction will be included and fee will be ignored.0.002
txTypeDefault is v0 for versioned transaction (recommended). use legacy for legacy transaction.v0
⚠️

The slip parameter represents slippage in percentage. For example, use "1" for 1% slippage.

JSON Examples

{
  "from": "So11111111111111111111111111111111111111112",
  "to": "2CKpz5rLrXZSmoTwwskCiYgSEDhyuqM2q4s5znJVRrFA",
  "amount": "1",
  "payer": "PUBLIC_KEY",
  "slip": "1",
  "fee": "0.000005",
}
⚠️

Remember to replace 'PUBLIC_KEY' with the actual payer public key address.

Response Explanation

  • transaction:
    • serializedTx: The serialized transaction string. This is the most important field you need for executing the swap.
    • txType: The type of transaction ('legacy' or 'v0').
    • executionTime: The time taken to prepare the transaction.
  • swapDetails:
    • inputAmount: The amount of the source token to be swapped.
    • outputAmount: The estimated amount of the destination token you'll receive.
    • minimumOutputAmount: The minimum amount you'll receive considering the slippage.
    • priceData:
      • spotPrice: The current market price of the token pair.
      • effectivePrice: The actual price you're getting for the swap.
      • priceImpactPercentage: The percentage difference between spot and effective price. (Often occurs when there is insufficient trading activity)
    • feeInfo:
      • swapFee: The fee charged for the swap.
      • platformFeeAmount: The cost charged by the trading platform, measured in SOL Lamports.
      • platformFeeFormatted: The platform cost shown in SOL.
  • tokenInfo: Details about the source and destination tokens, including their addresses and decimal places.

The serializedTx in the transaction object is the most crucial piece of information. This is the serialized transaction that you'll need to deserialize, sign, and send to the Solana network to complete the swap.

Error Codes

🚫

In case of an error, you may receive one of the following HTTP status codes:

  • 400: Bad request (check your parameters)
  • 429: Too many requests (you've exceeded the rate limit)
  • 500: Internal server error

Example Usage

Here's an example of how to use the /swap endpoint with cURL:

curl 'https://swap.solxtence.com/swap?from=So11111111111111111111111111111111111111112&to=2CKpz5rLrXZSmoTwwskCiYgSEDhyuqM2q4s5znJVRrFA&amount=1&slip=1&payer=PUBLIC_KEY&txType=v0'
⚠️

Remember to replace 'PUBLIC_KEY' with the actual payer public key address.

Next Steps After receiving the serialized transaction, you'll need to:

  • Deserialize the transaction
  • Sign the transaction with the payer's private key
  • Send the signed transaction to the Solana network

Pro tip: Use the txType parameter to specify whether you want a legacy or versioned (v0) transaction.

Example on GitHub (Python, Javascript...)

For a hands-on guide to managing Solana transactions, including full buy or sell operations, check out this example (opens in a new tab) on GitHub. It covers both Python and JavaScript implementations.

Glossary

  • Serialized Transaction: A transaction that has been encoded into a specific format that can be transmitted over the network.

  • Deserialize: The process of converting a serialized transaction back into its original format to sign and send it to the blockchain.

  • Slippage: The gap between an order's predicted price and the price at which the order performs.

  • Public Key: A cryptographic key used to receive tokens or other assets. It is part of a key pair, where the public key is shared openly, and anyone can use it to send assets to the associated wallet.

  • Private Key: A secret cryptographic key that is used to sign transactions and prove ownership of assets within a wallet. It must be kept secure, as anyone with access to it can control the associated wallet and its assets.