Initiate an atomic swap
curl --request POST \
--url http://localhost:8000/api/v1/swaps/init \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"rfq_id": "8e6635fb-ab37-4aed-89f4-bc9c98fb8b49",
"from_asset": "BTC",
"from_amount": 1500000,
"to_asset": "rgb:2NZGjyz-pJePUgegh-RLHbpx1Hy-iZMagWiZZ-qY4AxGymW-yCEYwwB",
"to_amount": 875000
}
'import requests
url = "http://localhost:8000/api/v1/swaps/init"
payload = {
"rfq_id": "8e6635fb-ab37-4aed-89f4-bc9c98fb8b49",
"from_asset": "BTC",
"from_amount": 1500000,
"to_asset": "rgb:2NZGjyz-pJePUgegh-RLHbpx1Hy-iZMagWiZZ-qY4AxGymW-yCEYwwB",
"to_amount": 875000
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
rfq_id: '8e6635fb-ab37-4aed-89f4-bc9c98fb8b49',
from_asset: 'BTC',
from_amount: 1500000,
to_asset: 'rgb:2NZGjyz-pJePUgegh-RLHbpx1Hy-iZMagWiZZ-qY4AxGymW-yCEYwwB',
to_amount: 875000
})
};
fetch('http://localhost:8000/api/v1/swaps/init', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_PORT => "8000",
CURLOPT_URL => "http://localhost:8000/api/v1/swaps/init",
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([
'rfq_id' => '8e6635fb-ab37-4aed-89f4-bc9c98fb8b49',
'from_asset' => 'BTC',
'from_amount' => 1500000,
'to_asset' => 'rgb:2NZGjyz-pJePUgegh-RLHbpx1Hy-iZMagWiZZ-qY4AxGymW-yCEYwwB',
'to_amount' => 875000
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$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 := "http://localhost:8000/api/v1/swaps/init"
payload := strings.NewReader("{\n \"rfq_id\": \"8e6635fb-ab37-4aed-89f4-bc9c98fb8b49\",\n \"from_asset\": \"BTC\",\n \"from_amount\": 1500000,\n \"to_asset\": \"rgb:2NZGjyz-pJePUgegh-RLHbpx1Hy-iZMagWiZZ-qY4AxGymW-yCEYwwB\",\n \"to_amount\": 875000\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
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("http://localhost:8000/api/v1/swaps/init")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"rfq_id\": \"8e6635fb-ab37-4aed-89f4-bc9c98fb8b49\",\n \"from_asset\": \"BTC\",\n \"from_amount\": 1500000,\n \"to_asset\": \"rgb:2NZGjyz-pJePUgegh-RLHbpx1Hy-iZMagWiZZ-qY4AxGymW-yCEYwwB\",\n \"to_amount\": 875000\n}")
.asString();require 'uri'
require 'net/http'
url = URI("http://localhost:8000/api/v1/swaps/init")
http = Net::HTTP.new(url.host, url.port)
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"rfq_id\": \"8e6635fb-ab37-4aed-89f4-bc9c98fb8b49\",\n \"from_asset\": \"BTC\",\n \"from_amount\": 1500000,\n \"to_asset\": \"rgb:2NZGjyz-pJePUgegh-RLHbpx1Hy-iZMagWiZZ-qY4AxGymW-yCEYwwB\",\n \"to_amount\": 875000\n}"
response = http.request(request)
puts response.read_body{
"swapstring": "1500000/BTC/875000/rgb:2NZGjyz-pJePUgegh-RLHbpx1Hy-iZMagWiZZ-qY4AxGymW-yCEYwwB/1715896416/9d342c6ba006e24abee84a2e034a22d5e30c1f2599fb9c3574d46d3cde3d65a2",
"payment_hash": "9d342c6ba006e24abee84a2e034a22d5e30c1f2599fb9c3574d46d3cde3d65a2"
}{
"error_code": "VALIDATION_ERROR",
"message": "Invalid swap request: missing payment_hash or swapstring",
"details": {},
"request_id": "req_01HV8Q9X7G0Q7Y3Z"
}{
"error": "missing_api_key"
}{
"detail": [
{
"loc": [
"body",
"rfq_id"
],
"msg": "Field required",
"type": "missing"
}
]
}{
"error_code": "RATE_LIMIT_EXCEEDED",
"message": "Too many requests",
"details": {
"retry_after": 60
},
"request_id": "req_01HV8Q9X7G0Q7Y3Z"
}{
"error_code": "INTERNAL_ERROR",
"message": "Internal Server Error",
"details": {},
"request_id": "req_01HV8Q9X7G0Q7Y3Z"
}{
"error_code": "SERVICE_UNAVAILABLE",
"message": "Trading service is starting up. Please try again in a few moments.",
"details": {},
"request_id": "req_01HV8Q9X7G0Q7Y3Z"
}swaps
Initiate an atomic swap
Create a maker-side atomic swap from a fresh RFQ. The response contains the swapstring and payment_hash the taker must whitelist before execution. Treat this as non-idempotent: creating a second swap requires a new request.
POST
/
api
/
v1
/
swaps
/
init
Initiate an atomic swap
curl --request POST \
--url http://localhost:8000/api/v1/swaps/init \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"rfq_id": "8e6635fb-ab37-4aed-89f4-bc9c98fb8b49",
"from_asset": "BTC",
"from_amount": 1500000,
"to_asset": "rgb:2NZGjyz-pJePUgegh-RLHbpx1Hy-iZMagWiZZ-qY4AxGymW-yCEYwwB",
"to_amount": 875000
}
'import requests
url = "http://localhost:8000/api/v1/swaps/init"
payload = {
"rfq_id": "8e6635fb-ab37-4aed-89f4-bc9c98fb8b49",
"from_asset": "BTC",
"from_amount": 1500000,
"to_asset": "rgb:2NZGjyz-pJePUgegh-RLHbpx1Hy-iZMagWiZZ-qY4AxGymW-yCEYwwB",
"to_amount": 875000
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
rfq_id: '8e6635fb-ab37-4aed-89f4-bc9c98fb8b49',
from_asset: 'BTC',
from_amount: 1500000,
to_asset: 'rgb:2NZGjyz-pJePUgegh-RLHbpx1Hy-iZMagWiZZ-qY4AxGymW-yCEYwwB',
to_amount: 875000
})
};
fetch('http://localhost:8000/api/v1/swaps/init', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_PORT => "8000",
CURLOPT_URL => "http://localhost:8000/api/v1/swaps/init",
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([
'rfq_id' => '8e6635fb-ab37-4aed-89f4-bc9c98fb8b49',
'from_asset' => 'BTC',
'from_amount' => 1500000,
'to_asset' => 'rgb:2NZGjyz-pJePUgegh-RLHbpx1Hy-iZMagWiZZ-qY4AxGymW-yCEYwwB',
'to_amount' => 875000
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$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 := "http://localhost:8000/api/v1/swaps/init"
payload := strings.NewReader("{\n \"rfq_id\": \"8e6635fb-ab37-4aed-89f4-bc9c98fb8b49\",\n \"from_asset\": \"BTC\",\n \"from_amount\": 1500000,\n \"to_asset\": \"rgb:2NZGjyz-pJePUgegh-RLHbpx1Hy-iZMagWiZZ-qY4AxGymW-yCEYwwB\",\n \"to_amount\": 875000\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
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("http://localhost:8000/api/v1/swaps/init")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"rfq_id\": \"8e6635fb-ab37-4aed-89f4-bc9c98fb8b49\",\n \"from_asset\": \"BTC\",\n \"from_amount\": 1500000,\n \"to_asset\": \"rgb:2NZGjyz-pJePUgegh-RLHbpx1Hy-iZMagWiZZ-qY4AxGymW-yCEYwwB\",\n \"to_amount\": 875000\n}")
.asString();require 'uri'
require 'net/http'
url = URI("http://localhost:8000/api/v1/swaps/init")
http = Net::HTTP.new(url.host, url.port)
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"rfq_id\": \"8e6635fb-ab37-4aed-89f4-bc9c98fb8b49\",\n \"from_asset\": \"BTC\",\n \"from_amount\": 1500000,\n \"to_asset\": \"rgb:2NZGjyz-pJePUgegh-RLHbpx1Hy-iZMagWiZZ-qY4AxGymW-yCEYwwB\",\n \"to_amount\": 875000\n}"
response = http.request(request)
puts response.read_body{
"swapstring": "1500000/BTC/875000/rgb:2NZGjyz-pJePUgegh-RLHbpx1Hy-iZMagWiZZ-qY4AxGymW-yCEYwwB/1715896416/9d342c6ba006e24abee84a2e034a22d5e30c1f2599fb9c3574d46d3cde3d65a2",
"payment_hash": "9d342c6ba006e24abee84a2e034a22d5e30c1f2599fb9c3574d46d3cde3d65a2"
}{
"error_code": "VALIDATION_ERROR",
"message": "Invalid swap request: missing payment_hash or swapstring",
"details": {},
"request_id": "req_01HV8Q9X7G0Q7Y3Z"
}{
"error": "missing_api_key"
}{
"detail": [
{
"loc": [
"body",
"rfq_id"
],
"msg": "Field required",
"type": "missing"
}
]
}{
"error_code": "RATE_LIMIT_EXCEEDED",
"message": "Too many requests",
"details": {
"retry_after": 60
},
"request_id": "req_01HV8Q9X7G0Q7Y3Z"
}{
"error_code": "INTERNAL_ERROR",
"message": "Internal Server Error",
"details": {},
"request_id": "req_01HV8Q9X7G0Q7Y3Z"
}{
"error_code": "SERVICE_UNAVAILABLE",
"message": "Trading service is starting up. Please try again in a few moments.",
"details": {},
"request_id": "req_01HV8Q9X7G0Q7Y3Z"
}Authorizations
Pass a Kaleido API key such as kld_live_c_....
Body
application/json
Response
Swap initialized successfully.
Example:
"30/rgb:2dkSTbr-jFhznbPmo-TQafzswCN-av4gTsJjX-ttx6CNou5-M98k8Zd/10/rgb:2eVw8uw-8G88LQ2tQ-kexM12SoD-nCX8DmQrw-yLMu6JDfK-xx1SCfc/1715896416/9d342c6ba006e24abee84a2e034a22d5e30c1f2599fb9c3574d46d3cde3d65a2"
Example:
"9d342c6ba006e24abee84a2e034a22d5e30c1f2599fb9c3574d46d3cde3d65a2"
Per-swap token required to poll /swaps/atomic/status. Returned only once here at initiation — store it alongside the payment hash.
Was this page helpful?
⌘I