THORChain Swap SDKs
Official client libraries for THORChain Swap (https://swap.thorchain.org). Two kinds, because there are two kinds of integration:
- Building swaps —
@tcswap/sdkon npm: quotes and routing across THORChain and Maya, wallet connection, and transaction building. It is the SDK this interface is itself built on. - Reading public data — the Python and Go clients here: thin, dependency-free wrappers over the keyless surfaces this site publishes (the MCP tools, the support endpoints, and optional client registration).
TypeScript / JavaScript
- Package:
@tcswap/sdk(npm) — https://www.npmjs.com/package/@tcswap/sdk - Install:
npm install @tcswap/sdk - Source: https://github.com/thorchain/TCSwap/tree/main/packages/sdk
- Status: Published on npm. The full swap SDK — quotes and routing across THORChain and Maya, wallet connection, and transaction building — and the SDK this interface is itself built on.
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
- Package:
thorchain-swap(PyPI) - Install:
pip install "git+https://github.com/thorchain/swap.thorchain#subdirectory=sdk/python" - Source: https://github.com/thorchain/swap.thorchain/tree/main/sdk/python
- Status: Source published in this repository, covering the keyless public surfaces of this site. Install directly from git —
pip install "git+https://github.com/thorchain/swap.thorchain#subdirectory=sdk/python"— until the PyPI release is cut.
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:
github.com/thorchain/swap.thorchain/sdk/go(Go modules) - Install:
go get github.com/thorchain/swap.thorchain/sdk/go - Source: https://github.com/thorchain/swap.thorchain/tree/main/sdk/go
- Status: Source published in this repository, covering the keyless public surfaces of this site, and importable as a Go module directly from the repository path.
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