Skip to main content
The supported way to use Soroswap from TypeScript is the official SDK, @soroswap/sdk. It wraps the Soroswap API, so you get routing across every supported protocol without assembling Soroban invocations by hand.
If you need to call the contracts directly from another contract, that is a different job: see Smart Contract Integration.

Install

You need an API key. Register at api.soroswap.finance/register; keys start with sk_.
The API key is a secret. Keep it server side. Do not ship it in a browser bundle.

Initialize

Every method takes an optional trailing network argument that overrides defaultNetwork for that one call.

The swap flow

A swap is four steps: quote, build, sign, send. The SDK does three of them; signing is yours, because the SDK never holds a key.

1. Quote

amount is a BigInt, in the asset’s smallest unit. Passing a number will not work. tradeType is TradeType.EXACT_IN when you know what you are spending, or TradeType.EXACT_OUT when you know what you want to receive. Other fields on the request: parts, maxHops, assetList, feeBps and gaslessTrustline. slippageBps and feeBps are basis points, so 50 is 0.5%. To see which protocols a network currently supports:

2. Build

If the quote carried a feeBps, build also requires referralId, the address the fee is paid to.

3. Sign

The SDK returns an unsigned XDR and stops there. Sign it with whatever the surrounding app already uses: a browser wallet through stellar-wallets-kit, or a keypair server side.

4. Send

Pools and prices

Liquidity

addLiquidity and removeLiquidity return an XDR the same way build does: you sign and send it yourself.
Fetch the pool first and derive amountA and amountB from its current ratio. Amounts that do not match the pool’s proportions fail during simulation.

Finding the router address

If you need the deployed router address rather than the SDK:
The addresses are also listed on Deployed Addresses.

Understanding the route

A swap walks the path array pair by pair, exchanging at each step (0 <-> 1, 1 <-> 2, and so on to n <-> n+1) until the route completes. Every extra hop costs fees and slippage, which is why routing quality matters and why the API computes it for you rather than leaving you to guess a path.

Reference