@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
sk_.
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
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 throughstellar-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.
Finding the router address
If you need the deployed router address rather than the SDK:Understanding the route
A swap walks thepath 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
- SDK source and full type definitions: github.com/soroswap/sdk
- REST reference, if you would rather call the API directly: api.soroswap.finance/docs
- Getting started with the API: Soroswap API