curl --request POST \
--url https://api.sarafa.site/v3/swap \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"amount": "100",
"from_currency": "USD",
"to_currency": "USDC",
"reference": "swap-100",
"callback_url": "https://merchant.example/payments",
"quote": true
}
'import requests
url = "https://api.sarafa.site/v3/swap"
payload = {
"amount": "100",
"from_currency": "USD",
"to_currency": "USDC",
"reference": "swap-100",
"callback_url": "https://merchant.example/payments",
"quote": True
}
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({
amount: '100',
from_currency: 'USD',
to_currency: 'USDC',
reference: 'swap-100',
callback_url: 'https://merchant.example/payments',
quote: true
})
};
fetch('https://api.sarafa.site/v3/swap', 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://api.sarafa.site/v3/swap",
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([
'amount' => '100',
'from_currency' => 'USD',
'to_currency' => 'USDC',
'reference' => 'swap-100',
'callback_url' => 'https://merchant.example/payments',
'quote' => true
]),
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 := "https://api.sarafa.site/v3/swap"
payload := strings.NewReader("{\n \"amount\": \"100\",\n \"from_currency\": \"USD\",\n \"to_currency\": \"USDC\",\n \"reference\": \"swap-100\",\n \"callback_url\": \"https://merchant.example/payments\",\n \"quote\": true\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("https://api.sarafa.site/v3/swap")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"amount\": \"100\",\n \"from_currency\": \"USD\",\n \"to_currency\": \"USDC\",\n \"reference\": \"swap-100\",\n \"callback_url\": \"https://merchant.example/payments\",\n \"quote\": true\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.sarafa.site/v3/swap")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"amount\": \"100\",\n \"from_currency\": \"USD\",\n \"to_currency\": \"USDC\",\n \"reference\": \"swap-100\",\n \"callback_url\": \"https://merchant.example/payments\",\n \"quote\": true\n}"
response = http.request(request)
puts response.read_body{
"status": "success",
"quote": {
"source_currency": "USD",
"destination_currency": "USDC",
"amount": "100",
"exchange_rate": "1",
"amount_received": "97",
"total_fees": "3",
"total_debit": "100",
"pricing": "temporary_fixed"
}
}{
"status": "failed",
"error": "<string>",
"request_id": "<string>",
"issues": [
{
"path": [
"<string>"
],
"message": "<string>"
}
]
}{
"status": "failed",
"error": "<string>",
"request_id": "<string>",
"issues": [
{
"path": [
"<string>"
],
"message": "<string>"
}
]
}{
"status": "failed",
"error": "<string>",
"request_id": "<string>",
"issues": [
{
"path": [
"<string>"
],
"message": "<string>"
}
]
}{
"status": "failed",
"error": "<string>",
"request_id": "<string>",
"issues": [
{
"path": [
"<string>"
],
"message": "<string>"
}
]
}{
"status": "failed",
"error": "<string>",
"request_id": "<string>",
"issues": [
{
"path": [
"<string>"
],
"message": "<string>"
}
]
}{
"status": "failed",
"error": "<string>",
"request_id": "<string>",
"issues": [
{
"path": [
"<string>"
],
"message": "<string>"
}
]
}{
"status": "failed",
"error": "<string>",
"request_id": "<string>",
"issues": [
{
"path": [
"<string>"
],
"message": "<string>"
}
]
}Swap wallet balances
Convert between USD and USDC or USDT within your account.
curl --request POST \
--url https://api.sarafa.site/v3/swap \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"amount": "100",
"from_currency": "USD",
"to_currency": "USDC",
"reference": "swap-100",
"callback_url": "https://merchant.example/payments",
"quote": true
}
'import requests
url = "https://api.sarafa.site/v3/swap"
payload = {
"amount": "100",
"from_currency": "USD",
"to_currency": "USDC",
"reference": "swap-100",
"callback_url": "https://merchant.example/payments",
"quote": True
}
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({
amount: '100',
from_currency: 'USD',
to_currency: 'USDC',
reference: 'swap-100',
callback_url: 'https://merchant.example/payments',
quote: true
})
};
fetch('https://api.sarafa.site/v3/swap', 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://api.sarafa.site/v3/swap",
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([
'amount' => '100',
'from_currency' => 'USD',
'to_currency' => 'USDC',
'reference' => 'swap-100',
'callback_url' => 'https://merchant.example/payments',
'quote' => true
]),
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 := "https://api.sarafa.site/v3/swap"
payload := strings.NewReader("{\n \"amount\": \"100\",\n \"from_currency\": \"USD\",\n \"to_currency\": \"USDC\",\n \"reference\": \"swap-100\",\n \"callback_url\": \"https://merchant.example/payments\",\n \"quote\": true\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("https://api.sarafa.site/v3/swap")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"amount\": \"100\",\n \"from_currency\": \"USD\",\n \"to_currency\": \"USDC\",\n \"reference\": \"swap-100\",\n \"callback_url\": \"https://merchant.example/payments\",\n \"quote\": true\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.sarafa.site/v3/swap")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"amount\": \"100\",\n \"from_currency\": \"USD\",\n \"to_currency\": \"USDC\",\n \"reference\": \"swap-100\",\n \"callback_url\": \"https://merchant.example/payments\",\n \"quote\": true\n}"
response = http.request(request)
puts response.read_body{
"status": "success",
"quote": {
"source_currency": "USD",
"destination_currency": "USDC",
"amount": "100",
"exchange_rate": "1",
"amount_received": "97",
"total_fees": "3",
"total_debit": "100",
"pricing": "temporary_fixed"
}
}{
"status": "failed",
"error": "<string>",
"request_id": "<string>",
"issues": [
{
"path": [
"<string>"
],
"message": "<string>"
}
]
}{
"status": "failed",
"error": "<string>",
"request_id": "<string>",
"issues": [
{
"path": [
"<string>"
],
"message": "<string>"
}
]
}{
"status": "failed",
"error": "<string>",
"request_id": "<string>",
"issues": [
{
"path": [
"<string>"
],
"message": "<string>"
}
]
}{
"status": "failed",
"error": "<string>",
"request_id": "<string>",
"issues": [
{
"path": [
"<string>"
],
"message": "<string>"
}
]
}{
"status": "failed",
"error": "<string>",
"request_id": "<string>",
"issues": [
{
"path": [
"<string>"
],
"message": "<string>"
}
]
}{
"status": "failed",
"error": "<string>",
"request_id": "<string>",
"issues": [
{
"path": [
"<string>"
],
"message": "<string>"
}
]
}{
"status": "failed",
"error": "<string>",
"request_id": "<string>",
"issues": [
{
"path": [
"<string>"
],
"message": "<string>"
}
]
}{
"amount": "100",
"from_currency": "USD",
"to_currency": "USDC",
"reference": "swap-100",
"callback_url": "https://merchant.example/payments",
"quote": true
}
{
"status": "success",
"quote": {
"source_currency": "USD",
"destination_currency": "USDC",
"amount": "100",
"exchange_rate": "1",
"amount_received": "97",
"total_fees": "3",
"total_debit": "100",
"pricing": "temporary_fixed"
}
}
"quote": false. A successful swap returns HTTP 200 with a completed transaction and its quote. Both wallets must be active and the source wallet must have sufficient balance.Authorizations
Use the full key from the merchant dashboard API section. Keep it on your server.
Body
- Option 1
- Option 2
Only USD to/from USDC or USDT. The currencies must differ. Conversion is 1:1, with 3% deducted from proceeds.
USD USDC, USDT Positive decimal string, not a JSON number. Zero is invalid. Currency-specific precision and payment limits also apply.
^[0-9]+([.][0-9]{1,18})?$"100.00"
Your idempotency reference, unique across charge, transfer, swap, and checkout creation within your organization. Reuse it with unchanged details for execution retries.
1 - 128HTTPS URL without embedded credentials. Required even for quotes. Receives signed payment callbacks.
^https://"https://merchant.example/payments"
True returns a quote without moving funds or creating a transaction. Set false to execute.
