Returns the best route for the given trade pair using smart settings
curl --request POST \
--url https://backend.swap.coffee/v1/route/smart \
--header 'Content-Type: application/json' \
--header 'X-Api-Key: <api-key>' \
--data '
{
"input_token": {
"blockchain": "ton",
"address": "native"
},
"output_token": {
"blockchain": "ton",
"address": "native"
},
"input_amount": 1,
"output_amount": 1,
"max_splits": 4,
"additional_data": {
"sender_address": "UQCNTO0Nh0Z7QNyRW1BLWfk08f2dAOw4izrx9sO6OUPg4DoV",
"referral_name": "tonkeeper"
}
}
'import requests
url = "https://backend.swap.coffee/v1/route/smart"
payload = {
"input_token": {
"blockchain": "ton",
"address": "native"
},
"output_token": {
"blockchain": "ton",
"address": "native"
},
"input_amount": 1,
"output_amount": 1,
"max_splits": 4,
"additional_data": {
"sender_address": "UQCNTO0Nh0Z7QNyRW1BLWfk08f2dAOw4izrx9sO6OUPg4DoV",
"referral_name": "tonkeeper"
}
}
headers = {
"X-Api-Key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'X-Api-Key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
input_token: {blockchain: 'ton', address: 'native'},
output_token: {blockchain: 'ton', address: 'native'},
input_amount: 1,
output_amount: 1,
max_splits: 4,
additional_data: {
sender_address: 'UQCNTO0Nh0Z7QNyRW1BLWfk08f2dAOw4izrx9sO6OUPg4DoV',
referral_name: 'tonkeeper'
}
})
};
fetch('https://backend.swap.coffee/v1/route/smart', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://backend.swap.coffee/v1/route/smart",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'input_token' => [
'blockchain' => 'ton',
'address' => 'native'
],
'output_token' => [
'blockchain' => 'ton',
'address' => 'native'
],
'input_amount' => 1,
'output_amount' => 1,
'max_splits' => 4,
'additional_data' => [
'sender_address' => 'UQCNTO0Nh0Z7QNyRW1BLWfk08f2dAOw4izrx9sO6OUPg4DoV',
'referral_name' => 'tonkeeper'
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"X-Api-Key: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://backend.swap.coffee/v1/route/smart"
payload := strings.NewReader("{\n \"input_token\": {\n \"blockchain\": \"ton\",\n \"address\": \"native\"\n },\n \"output_token\": {\n \"blockchain\": \"ton\",\n \"address\": \"native\"\n },\n \"input_amount\": 1,\n \"output_amount\": 1,\n \"max_splits\": 4,\n \"additional_data\": {\n \"sender_address\": \"UQCNTO0Nh0Z7QNyRW1BLWfk08f2dAOw4izrx9sO6OUPg4DoV\",\n \"referral_name\": \"tonkeeper\"\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-Api-Key", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://backend.swap.coffee/v1/route/smart")
.header("X-Api-Key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"input_token\": {\n \"blockchain\": \"ton\",\n \"address\": \"native\"\n },\n \"output_token\": {\n \"blockchain\": \"ton\",\n \"address\": \"native\"\n },\n \"input_amount\": 1,\n \"output_amount\": 1,\n \"max_splits\": 4,\n \"additional_data\": {\n \"sender_address\": \"UQCNTO0Nh0Z7QNyRW1BLWfk08f2dAOw4izrx9sO6OUPg4DoV\",\n \"referral_name\": \"tonkeeper\"\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://backend.swap.coffee/v1/route/smart")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["X-Api-Key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"input_token\": {\n \"blockchain\": \"ton\",\n \"address\": \"native\"\n },\n \"output_token\": {\n \"blockchain\": \"ton\",\n \"address\": \"native\"\n },\n \"input_amount\": 1,\n \"output_amount\": 1,\n \"max_splits\": 4,\n \"additional_data\": {\n \"sender_address\": \"UQCNTO0Nh0Z7QNyRW1BLWfk08f2dAOw4izrx9sO6OUPg4DoV\",\n \"referral_name\": \"tonkeeper\"\n }\n}"
response = http.request(request)
puts response.read_body{
"input_token": {
"address": {
"blockchain": "ton",
"address": "native"
},
"metadata": {
"name": "ARBUZ",
"symbol": "ARBUZ",
"decimals": 123,
"listed": true,
"verification": "whitelisted",
"image_url": "<string>"
}
},
"output_token": {
"address": {
"blockchain": "ton",
"address": "native"
},
"metadata": {
"name": "ARBUZ",
"symbol": "ARBUZ",
"decimals": 123,
"listed": true,
"verification": "whitelisted",
"image_url": "<string>"
}
},
"input_amount": 123,
"output_amount": 123,
"input_usd": 123,
"output_usd": 123,
"recommended_gas": 123,
"price_impact": 123,
"paths": [
{
"blockchain": "ton",
"dex": "stonfi",
"pool_address": "<string>",
"input_token": {
"address": {
"blockchain": "ton",
"address": "native"
},
"metadata": {
"name": "ARBUZ",
"symbol": "ARBUZ",
"decimals": 123,
"listed": true,
"verification": "whitelisted",
"image_url": "<string>"
}
},
"output_token": {
"address": {
"blockchain": "ton",
"address": "native"
},
"metadata": {
"name": "ARBUZ",
"symbol": "ARBUZ",
"decimals": 123,
"listed": true,
"verification": "whitelisted",
"image_url": "<string>"
}
},
"swap": {
"result": "fully_fulfilled",
"input_amount": 123,
"output_amount": 123,
"before_reserves": [
123
],
"after_reserves": [
123
],
"reason": "<string>",
"left_amount": 123
},
"recommended_gas": 123,
"average_gas": 123,
"next": "<array>"
}
],
"savings": 123,
"left_amount": 123,
"estimated_cashback_usd": 123,
"partner_commission_ton": 123,
"mev_protection_fee": 123
}{
"error": "<string>"
}Routing
Returns the best route for the given trade pair using smart settings
POST
/
v1
/
route
/
smart
Returns the best route for the given trade pair using smart settings
curl --request POST \
--url https://backend.swap.coffee/v1/route/smart \
--header 'Content-Type: application/json' \
--header 'X-Api-Key: <api-key>' \
--data '
{
"input_token": {
"blockchain": "ton",
"address": "native"
},
"output_token": {
"blockchain": "ton",
"address": "native"
},
"input_amount": 1,
"output_amount": 1,
"max_splits": 4,
"additional_data": {
"sender_address": "UQCNTO0Nh0Z7QNyRW1BLWfk08f2dAOw4izrx9sO6OUPg4DoV",
"referral_name": "tonkeeper"
}
}
'import requests
url = "https://backend.swap.coffee/v1/route/smart"
payload = {
"input_token": {
"blockchain": "ton",
"address": "native"
},
"output_token": {
"blockchain": "ton",
"address": "native"
},
"input_amount": 1,
"output_amount": 1,
"max_splits": 4,
"additional_data": {
"sender_address": "UQCNTO0Nh0Z7QNyRW1BLWfk08f2dAOw4izrx9sO6OUPg4DoV",
"referral_name": "tonkeeper"
}
}
headers = {
"X-Api-Key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'X-Api-Key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
input_token: {blockchain: 'ton', address: 'native'},
output_token: {blockchain: 'ton', address: 'native'},
input_amount: 1,
output_amount: 1,
max_splits: 4,
additional_data: {
sender_address: 'UQCNTO0Nh0Z7QNyRW1BLWfk08f2dAOw4izrx9sO6OUPg4DoV',
referral_name: 'tonkeeper'
}
})
};
fetch('https://backend.swap.coffee/v1/route/smart', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://backend.swap.coffee/v1/route/smart",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'input_token' => [
'blockchain' => 'ton',
'address' => 'native'
],
'output_token' => [
'blockchain' => 'ton',
'address' => 'native'
],
'input_amount' => 1,
'output_amount' => 1,
'max_splits' => 4,
'additional_data' => [
'sender_address' => 'UQCNTO0Nh0Z7QNyRW1BLWfk08f2dAOw4izrx9sO6OUPg4DoV',
'referral_name' => 'tonkeeper'
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"X-Api-Key: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://backend.swap.coffee/v1/route/smart"
payload := strings.NewReader("{\n \"input_token\": {\n \"blockchain\": \"ton\",\n \"address\": \"native\"\n },\n \"output_token\": {\n \"blockchain\": \"ton\",\n \"address\": \"native\"\n },\n \"input_amount\": 1,\n \"output_amount\": 1,\n \"max_splits\": 4,\n \"additional_data\": {\n \"sender_address\": \"UQCNTO0Nh0Z7QNyRW1BLWfk08f2dAOw4izrx9sO6OUPg4DoV\",\n \"referral_name\": \"tonkeeper\"\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-Api-Key", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://backend.swap.coffee/v1/route/smart")
.header("X-Api-Key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"input_token\": {\n \"blockchain\": \"ton\",\n \"address\": \"native\"\n },\n \"output_token\": {\n \"blockchain\": \"ton\",\n \"address\": \"native\"\n },\n \"input_amount\": 1,\n \"output_amount\": 1,\n \"max_splits\": 4,\n \"additional_data\": {\n \"sender_address\": \"UQCNTO0Nh0Z7QNyRW1BLWfk08f2dAOw4izrx9sO6OUPg4DoV\",\n \"referral_name\": \"tonkeeper\"\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://backend.swap.coffee/v1/route/smart")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["X-Api-Key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"input_token\": {\n \"blockchain\": \"ton\",\n \"address\": \"native\"\n },\n \"output_token\": {\n \"blockchain\": \"ton\",\n \"address\": \"native\"\n },\n \"input_amount\": 1,\n \"output_amount\": 1,\n \"max_splits\": 4,\n \"additional_data\": {\n \"sender_address\": \"UQCNTO0Nh0Z7QNyRW1BLWfk08f2dAOw4izrx9sO6OUPg4DoV\",\n \"referral_name\": \"tonkeeper\"\n }\n}"
response = http.request(request)
puts response.read_body{
"input_token": {
"address": {
"blockchain": "ton",
"address": "native"
},
"metadata": {
"name": "ARBUZ",
"symbol": "ARBUZ",
"decimals": 123,
"listed": true,
"verification": "whitelisted",
"image_url": "<string>"
}
},
"output_token": {
"address": {
"blockchain": "ton",
"address": "native"
},
"metadata": {
"name": "ARBUZ",
"symbol": "ARBUZ",
"decimals": 123,
"listed": true,
"verification": "whitelisted",
"image_url": "<string>"
}
},
"input_amount": 123,
"output_amount": 123,
"input_usd": 123,
"output_usd": 123,
"recommended_gas": 123,
"price_impact": 123,
"paths": [
{
"blockchain": "ton",
"dex": "stonfi",
"pool_address": "<string>",
"input_token": {
"address": {
"blockchain": "ton",
"address": "native"
},
"metadata": {
"name": "ARBUZ",
"symbol": "ARBUZ",
"decimals": 123,
"listed": true,
"verification": "whitelisted",
"image_url": "<string>"
}
},
"output_token": {
"address": {
"blockchain": "ton",
"address": "native"
},
"metadata": {
"name": "ARBUZ",
"symbol": "ARBUZ",
"decimals": 123,
"listed": true,
"verification": "whitelisted",
"image_url": "<string>"
}
},
"swap": {
"result": "fully_fulfilled",
"input_amount": 123,
"output_amount": 123,
"before_reserves": [
123
],
"after_reserves": [
123
],
"reason": "<string>",
"left_amount": 123
},
"recommended_gas": 123,
"average_gas": 123,
"next": "<array>"
}
],
"savings": 123,
"left_amount": 123,
"estimated_cashback_usd": 123,
"partner_commission_ton": 123,
"mev_protection_fee": 123
}{
"error": "<string>"
}Body
application/json
Defines the maximum number of independent paths (i.e., transactions) the route can split into. For v4 wallets, you can omit this or set it to 4; for v5 wallets, you can set it to 20 (this is our internal upper limit, and we may reduce it later to something like 10).
Required range:
1 <= x <= 20Response
resulting route