Quickstart
Create an API key, check it, and read your SwapWallet balances in a few minutes, with samples in cURL, Node.js, Python, PHP and Go.
This page takes you from no key to a working request against your own account. You need a SwapWallet account and a terminal; every step has the same request in cURL, Node.js, Python, PHP and Go.
Four steps
Create an API key
In the SwapWallet app, open Profile › API key and choose Create new key. The key starts with
apikey-and acts with your account’s full access, so keep it on your server and nowhere else.export SWAPWALLET_API_KEY="apikey-…" # paste your keyCheck the key
This request does nothing but confirm the key works. A
401means the header is missing, mistyped, or the key was replaced.curl https://swapwallet.app/api/v1/utils/authentication/check \ -H "Authorization: Bearer $SWAPWALLET_API_KEY"const response = await fetch('https://swapwallet.app/api/v1/utils/authentication/check', { method: 'GET', headers: { Authorization: `Bearer ${process.env.SWAPWALLET_API_KEY}`, }, }); const data = await response.json(); console.log(data.result);import os import requests response = requests.get( "https://swapwallet.app/api/v1/utils/authentication/check", headers={"Authorization": f"Bearer {os.environ['SWAPWALLET_API_KEY']}"}, ) print(response.json()["result"])<?php $ch = curl_init('https://swapwallet.app/api/v1/utils/authentication/check'); curl_setopt_array($ch, [ CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => [ 'Authorization: Bearer ' . getenv('SWAPWALLET_API_KEY'), ], ]); $data = json_decode(curl_exec($ch), true); print_r($data['result']);package main import ( "fmt" "io" "net/http" "os" ) func main() { req, _ := http.NewRequest("GET", "https://swapwallet.app/api/v1/utils/authentication/check", nil) req.Header.Set("Authorization", "Bearer "+os.Getenv("SWAPWALLET_API_KEY")) res, err := http.DefaultClient.Do(req) if err != nil { panic(err) } defer res.Body.Close() data, _ := io.ReadAll(res.Body) fmt.Println(string(data)) }{ "status": "OK" }Read your balances
Your first real data: what you hold, per token. Amounts are decimal strings, so parse them with a decimal type rather than a float.
curl https://swapwallet.app/api/v2/user/balance \ -H "Authorization: Bearer $SWAPWALLET_API_KEY"const response = await fetch('https://swapwallet.app/api/v2/user/balance', { method: 'GET', headers: { Authorization: `Bearer ${process.env.SWAPWALLET_API_KEY}`, }, }); const data = await response.json(); console.log(data.result);import os import requests response = requests.get( "https://swapwallet.app/api/v2/user/balance", headers={"Authorization": f"Bearer {os.environ['SWAPWALLET_API_KEY']}"}, ) print(response.json()["result"])<?php $ch = curl_init('https://swapwallet.app/api/v2/user/balance'); curl_setopt_array($ch, [ CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => [ 'Authorization: Bearer ' . getenv('SWAPWALLET_API_KEY'), ], ]); $data = json_decode(curl_exec($ch), true); print_r($data['result']);package main import ( "fmt" "io" "net/http" "os" ) func main() { req, _ := http.NewRequest("GET", "https://swapwallet.app/api/v2/user/balance", nil) req.Header.Set("Authorization", "Bearer "+os.Getenv("SWAPWALLET_API_KEY")) res, err := http.DefaultClient.Do(req) if err != nil { panic(err) } defer res.Body.Close() data, _ := io.ReadAll(res.Body) fmt.Println(string(data)) }{ "status": "OK", "result": [ { "token": "ETH", "amount": { "number": "0", "unit": "ETH" } }, { "token": "BNB", "amount": { "number": "0", "unit": "BNB" } }, { "token": "TON", "amount": { "number": "106.677", "unit": "TON" } }, { "token": "TRX", "amount": { "number": "340", "unit": "TRX" } }, { "token": "BTC", "amount": { "number": "0.00215", "unit": "BTC" } }, { "token": "USDT", "amount": { "number": "1149.5", "unit": "USDT" } }, { "token": "IRT", "amount": { "number": "48250000", "unit": "IRT" } } ] }Pick what to build