Choose an API to get started
Offers API
Post, Query or Stream Offers for CATs and NFTs
Swap API
Quote and Instantly Swap CATs
Prices API
Price Data Feeds for CATs
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:
- Quote: Get a quote for the swap you want to make.
- 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/quoteQuery Parameter | Required | Possible Values | Notes |
---|---|---|---|
from | yes | XCH Asset Code (SBX, ...) db1a... Asset ID | The asset you want to sell. |
to | yes | XCH Asset Code (SBX, ...) db1a... Asset ID | The asset you want to buy. |
from_amount | no | integer (mojos) 1000000000000 = 1 XCH 1000 = 1 DBX | The amount of the asset you want to sell. Important: Amount is in sell currency. |
to_amount | no | integer (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/swapContent-Type: application/json
Post Parameter | Required | Possible Values | Notes |
---|---|---|---|
offer | yes | Offer | The offer according to the quote from Step 1. It is recommended to include a transaction fee and offer expiration. |
fee_destination | no | xch1... | An address for receiving a share of the swap fees. 0.5%of Combined Offer Amount Note: Fees include a small buffer for price changes between quote and execution and can vary slightly.0.15%of Routed AMM Amount |
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/tokensResponse Value | Type | Notes |
---|---|---|
success | boolean | Indicates success |
tokens[] | array | Array of supported tokens |
id | string | Token Asset ID |
name | string | Token Name |
code | string | Asset Currency Code |
denom | integer | Token Denominator (mojos) |
icon | integer | URL 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.