Choose an API to get started

Swap API for Chia Tokens (CATs)

The Swap API provides instant quotes and asset swaps. It is based on dexie’s combined offers technology, which aggregates liquidity across multiple sources. The Swap API is the easiest and fastest way to swap CATs non-custodially on Chia for the best price.
Note: Currently only CAT-XCH pairs are supported, but support for CAT-CAT pairs is planned.
Swapping assets is a two-step process:
  1. Quote: Get a quote for the swap you want to make.
  2. Swap: Execute the swap by submitting an offer for the received quote.
💰 Tip: To earn fees for facilitating swaps, integrators can add a fee destination address to Step 2.

Step 1: Get Quote

GET https://api.dexie.space/v1/swap/quote
Query ParameterRequiredPossible ValuesNotes
fromyesXCH Asset Code (SBX, ...)
db1a... Asset ID
The asset you want to sell.
toyesXCH Asset Code (SBX, ...)
db1a... Asset ID
The asset you want to buy.
from_amountnointeger (mojos)
1000000000000 = 1 XCH
1000 = 1 DBX
The amount of the asset you want to sell.
Important: Amount is in sell currency.
to_amountnointeger (mojos)
1000000000000 = 1 XCH
1000 = 1 DBX
The amount of the asset you want to buy.
Important: Amount is in buy currency.

Step 2: Execute Swap

POST https://api.dexie.space/v1/swap
Content-Type: application/json
Post ParameterRequiredPossible ValuesNotes
offeryesOfferThe offer according to the quote from Step 1.
It is recommended to include a transaction fee and offer expiration.
fee_destinationnoxch1...An address for receiving a share of the swap fees.
0.5%of Combined Offer Amount
0.15%of Routed AMM Amount
Note: Fees include a small buffer for price changes between quote and execution and can vary slightly.

Supported Tokens

All CAT/XCH pairs with at least one AMM liquidity pool (eg. TibetSwap) are supported at the moment.
To get a list of supported tokens, use the following endpoint:
GET https://api.dexie.space/v1/swap/tokens
Response ValueTypeNotes
successbooleanIndicates success
tokens[]arrayArray of supported tokens
idstringToken Asset ID
namestringToken Name
codestringAsset Currency Code
denomintegerToken Denominator (mojos)
iconintegerURL to token icon

Example flow using Chia CLI RPC

Below is a shell script that demonstrates how to get a quote, create an offer and submit it to the swap endpoint.
#!/bin/sh set -e FROM_TOKEN="xch" TO_TOKEN="db1a9020d48d9d4ad22631b66ab4b9ebd3637ef7758ad38881348c5d24c38f20" TO_AMOUNT=10000 # 10 DBX in mojos # Get Quote QUOTE=$(curl -s "https://api.dexie.space/v1/swap/quote?from=$FROM_TOKEN&to=$TO_TOKEN&to_amount=$TO_AMOUNT") FROM_AMOUNT=$(echo "$QUOTE" | jq -r '.quote.from_amount') TX_FEE=$(echo "$QUOTE" | jq -r '.quote.suggested_tx_fee') # Create Offer OFFER_PAYLOAD=$(cat <<EOF { "offer": { "$([ "$FROM_TOKEN" = "xch" ] && echo "1" || echo "$FROM_TOKEN")": -$FROM_AMOUNT, "$([ "$TO_TOKEN" = "xch" ] && echo "1" || echo "$TO_TOKEN")": $TO_AMOUNT }, "fee": $TX_FEE } EOF ) OFFER=$(chia rpc wallet create_offer_for_ids "$OFFER_PAYLOAD" | jq -r '.offer') # Submit Offer SWAP=$(curl -s -X POST -H "Content-Type: application/json" -d "{\"offer\":\"$OFFER\"}" https://api.dexie.space/v1/swap) # Print Response echo "$SWAP" | jq

Note on failed swaps

In certain situations the swap might fail, for example due to a change in the quote between the quote and swap request. In this case the offer reverts to an open offer and other market participants can take it. To abort a failed swap, simply cancel the offer, let it expire, or do a new swap with the same input coins.

Disclaimer

The API is provided "as is", with no guarantee of completeness, accuracy, reliability, and without warranty of any kind. Use at your own risk.