THORChain Swap SDKs

Official client libraries for THORChain Swap (https://swap.thorchain.org). Two kinds, because there are two kinds of integration:

TypeScript / JavaScript

import { USwapApi, createUSwap } from '@tcswap/sdk'

// Quotes and routes across every supported provider.
// Amounts here are decimal strings, not 1e8 base units.
const { routes } = await USwapApi.getSwapQuote({
  sellAsset: 'BTC.BTC',
  buyAsset: 'ETH.ETH',
  sellAmount: '0.1',
  destinationAddress: '0x...'
})

// Connect a wallet and sign locally; the SDK never holds keys for you.
const uswap = createUSwap()

Python

from thorchain_swap import ThorchainSwapClient

client = ThorchainSwapClient()

quote = client.get_swap_quote(
    from_asset="BTC.BTC",
    to_asset="ETH.ETH",
    amount="100000000",  # 1 BTC, in 1e8 base units
)

print(quote["expected_amount_out"])

Go

package main

import (
	"context"
	"fmt"

	thorchainswap "github.com/thorchain/swap.thorchain/sdk/go"
)

func main() {
	client := thorchainswap.NewClient()

	quote, err := client.GetSwapQuote(context.Background(), thorchainswap.SwapQuoteRequest{
		FromAsset: "BTC.BTC",
		ToAsset:   "ETH.ETH",
		Amount:    "100000000",
	})
	if err != nil {
		panic(err)
	}

	fmt.Println(quote["expected_amount_out"])
}

Which one

@tcswap/sdk talks to the swap aggregator (https://api.thorchain.org/v1), which is x-api-key gated, and takes amounts as decimal strings. The Python and Go clients talk to this site's public MCP server and REST endpoints, need no key at all, and take amounts as strings in 1e8 base units. Pick the first to build a swap flow, the second to read quotes, pools, and network state.

None of them hold keys, sign transactions, or submit swaps on a user's behalf: the user always signs in their own wallet or sends funds themselves through the memoless flow.

Related

This page as markdown: /developers/sdks.md