SWYPT API Documentation
Complete guide for integrating Swypt's on-ramp and off-ramp APIs for seamless fiat-to-crypto conversions
Smart Contracts
- Polygon
- Celo
- Lisk
- Base
Features
- Real-time Quotes
- Fiat On/Off Ramps
- Secure Transactions
- Support System
Authentication
All API endpoints require authentication using API keys. Include these headers with every request:
Required Headers
x-api-key
: Your API keyx-api-secret
: Your API secret
Contact for Access
Contact our support team to obtain your API credentials for production or testing environments.
const response = await axios.post('https://pool.swypt.io/api/swypt-quotes', {
type: "onramp",
amount: "100",
fiatCurrency: "KES",
cryptoCurrency: "USDT",
network: "celo"
}, {
headers: {
'x-api-key': 'YOUR_API_KEY',
'x-api-secret': 'YOUR_API_SECRET'
}
});
Getting Quotes
Quote Endpoint
POST https://pool.swypt.io/api/swypt-quotes
Get quotes for converting between fiat and crypto currencies before performing any on-ramp or off-ramp operations.
Request Parameters
Parameter | Description | Required | Example |
---|---|---|---|
type | Operation type | Yes | "onramp" | "offramp" |
amount | Amount to convert | Yes | "100" |
fiatCurrency | Fiat currency code | Yes | "KES" |
cryptoCurrency | Cryptocurrency symbol | Yes | "USDT" |
network | Blockchain network | Yes | "celo" |
category | Transaction category | No (offramp only) | "B2C" |
On-ramp Quote Example
Converting KES to USDT:
const response = await axios.post('https://pool.swypt.io/api/swypt-quotes', {
type: "onramp",
amount: "200",
fiatCurrency: "KES",
cryptoCurrency: "USDT",
network: "celo"
}, {
headers: {
'x-api-key': 'YOUR_API_KEY',
'x-api-secret': 'YOUR_API_SECRET'
}
});
Response:
{
"statusCode": 200,
"message": "Quote retrieved successfully",
"data": {
"inputAmount": "200",
"outputAmount": 1.4999,
"inputCurrency": "KES",
"outputCurrency": "USDT",
"exchangeRate": 133.345489,
"type": "onramp",
"network": "celo",
"fee": {
"amount": 0.03097,
"currency": "USDT",
"details": {
"feeInKES": 4,
"estimatedOutputKES": 104
}
}
}
}
Off-ramp Quote Example
Converting USDT to KES:
const response = await axios.post('https://pool.swypt.io/api/swypt-quotes', {
type: "offramp",
amount: "2",
fiatCurrency: "KES",
cryptoCurrency: "USDT",
network: "celo",
category: "B2C"
}, {
headers: {
'x-api-key': 'YOUR_API_KEY',
'x-api-secret': 'YOUR_API_SECRET'
}
});
Response:
{
"statusCode": 200,
"message": "Quote retrieved successfully",
"data": {
"inputAmount": "2",
"outputAmount": 255.72,
"inputCurrency": "USDT",
"outputCurrency": "KES",
"exchangeRate": 128.3556,
"type": "offramp",
"network": "celo",
"fee": {
"amount": 0.05,
"currency": "USDT",
"details": {
"feeInKES": 6,
"estimatedOutputKES": 261.72
}
}
}
}
Supported Assets
GET https://pool.swypt.io/api/swypt-supported-assets
Retrieve all supported assets, networks, and currencies available for trading.
const response = await axios.get('https://pool.swypt.io/api/swypt-supported-assets', {
headers: {
'x-api-key': 'YOUR_API_KEY',
'x-api-secret': 'YOUR_API_SECRET'
}
});
Response Format:
{
"networks": ["Lisk", "celo", "Base", "Polygon"],
"fiat": ["KES"],
"crypto": {
"Polygon": [
{
"symbol": "USDT",
"name": "Tether Polygon",
"decimals": 6,
"address": "0xc2132D05D31c914a87C6611C10748AEb04B58e8F"
}
],
"celo": [
{
"symbol": "cKES",
"name": "celo KES",
"decimals": 18,
"address": "0x3a0d9d7764FAE860A659eb96A500F1323b411e68"
},
{
"symbol": "cUSD",
"name": "celo Dollar",
"decimals": 18,
"address": "0x765DE816845861e75A25fCA122bb6898B8B1282a"
}
],
"Base": [
{
"symbol": "USDbC",
"name": "USD Base Coin",
"decimals": 6,
"address": "0xd9aAEc86B65D86f6A7B5B1b0c42FFA531710b6CA"
}
],
"Lisk": [
{
"symbol": "LSK",
"name": "Lisk",
"decimals": 8,
"address": "0x0000000000000000000000000000000000000000"
}
]
}
}
Off-ramp Flow
Overview
The off-ramp process involves two main steps:
- Call the Swypt smart contract
withdrawToEscrow
orwithdrawWithPermit
functions - Call the Swypt off-ramp API endpoint to initiate the fiat transfer
1. Smart Contract Withdrawal
withdrawToEscrow
Performs a token withdrawal to an escrow account. Requires prior token approval.
// Approve contract first
await token.approve(contractAddress, amountPlusFee);
// Perform withdrawal
const tx = await contract.withdrawToEscrow(
tokenAddress,
amountPlusFee,
exchangeRate,
feeAmount
);
withdrawWithPermit
Enables token withdrawal using EIP-2612 permit, eliminating the need for a separate approval transaction.
// Create permit signature (on client side)
const domain = {
name: 'Token Name',
version: '1',
chainId: 1,
verifyingContract: tokenAddress
};
const permit = {
owner: userAddress,
spender: contractAddress,
value: amountPlusFee,
nonce: await token.nonces(userAddress),
deadline: Math.floor(Date.now() / 1000) + 3600 // 1 hour from now
};
const { v, r, s } = await signer._signTypedData(domain, types, permit);
// Call the withdraw function
const tx = await contract.withdrawWithPermit(
tokenAddress,
amountPlusFee,
exchangeRate,
feeAmount,
permit.deadline,
v,
r,
s
);
2. Process Off-ramp Transaction
POST https://pool.swypt.io/api/swypt-order-offramp
Process an off-ramp transaction after successful blockchain withdrawal.
const response = await axios.post('https://pool.swypt.io/api/swypt-order-offramp', {
chain: "celo",
hash: "0x80856f025035da9387873410155c4868c1825101e2c06d580aea48e8179b5e0b",
partyB: "254703710518",
tokenAddress: "0x48065fbBE25f71C9282ddf5e1cD6D6A887483D5e"
}, {
headers: {
'x-api-key': 'YOUR_API_KEY',
'x-api-secret': 'YOUR_API_SECRET'
}
});
3. Check Transaction Status
GET https://pool.swypt.io/api/order-offramp-status/:orderID
const response = await axios.get('https://pool.swypt.io/api/order-offramp-status/WD-xsy6e-HO', {
headers: {
'x-api-key': 'YOUR_API_KEY',
'x-api-secret': 'YOUR_API_SECRET'
}
});
Success Response:
{
"status": "success",
"data": {
"status": "SUCCESS",
"message": "Withdrawal completed successfully",
"details": {
"phoneNumber": "254703710518",
"ReceiverPartyPublicName": "254703710518 - Henry Kariuki Nyagah",
"transactionSize": "20.00",
"transactionSide": "withdraw",
"initiatedAt": "2025-02-02T12:45:21.859Z",
"mpesaReceipt": "TB21GOZTI9",
"completedAt": "2025-02-02T15:45:23.000Z"
}
}
}
Status Values
PENDING
: Transaction is being processedSUCCESS
: Transaction completed successfullyFAILED
: Transaction failed
Smart Contract Addresses
Polygon Mainnet
0x5d3398142E393bB4BBFF6f67a3778322d3F9D90BCelo Mainnet
0x2816a02000B9845C464796b8c36B2D5D199525d5Lisk Mainnet
0x2816a02000B9845C464796b8c36B2D5D199525d5Pharos Devnet
0x5d3398142E393bB4BBFF6f67a3778322d3F9D90BOn-ramp Flow
Overview
The on-ramp process consists of three steps:
- Initiate STK Push for M-Pesa payment
- Monitor transaction status
- Process crypto transfer to user after successful payment
1. Initiate STK Push
POST https://pool.swypt.io/api/swypt-onramp
Initiates the M-Pesa STK push process for fiat deposit.
const response = await axios.post('https://pool.swypt.io/api/swypt-onramp', {
partyA: "254703710518",
amount: "5000",
side: "onramp",
userAddress: "0x742d35Cc6634C0532925a3b844Bc454e4438f44e",
tokenAddress: "0xc2132D05D31c914a87C6611C10748AEb04B58e8F"
}, {
headers: {
'x-api-key': 'YOUR_API_KEY',
'x-api-secret': 'YOUR_API_SECRET'
}
});
2. Check On-ramp Status
GET https://pool.swypt.io/api/order-onramp-status/:orderID
const response = await axios.get('https://pool.swypt.io/api/order-onramp-status/D-rclsg-VL', {
headers: {
'x-api-key': 'YOUR_API_KEY',
'x-api-secret': 'YOUR_API_SECRET'
}
});
Success Response:
{
"status": "success",
"data": {
"status": "SUCCESS",
"message": "Deposit completed successfully",
"orderID": "D-ri3b1-7H",
"details": {
"phoneNumber": "254703710518",
"mpesaReceipt": "TBF842GPCO",
"transactionDate": "2025-02-15T08:33:38.000Z",
"resultDescription": "Transaction initiated"
}
}
}
3. Process Crypto Transfer
POST https://pool.swypt.io/api/swypt-deposit
Process the crypto transfer after successful M-Pesa payment.
const response = await axios.post('https://pool.swypt.io/api/swypt-deposit', {
chain: "celo",
address: "0x742d35Cc6634C0532925a3b844Bc454e4438f44e",
orderID: "D-ri3b1-7H",
project: "onramp"
}, {
headers: {
'x-api-key': 'YOUR_API_KEY',
'x-api-secret': 'YOUR_API_SECRET'
}
});
Success Response:
{
"status": 200,
"message": "Transaction processed successfully",
"createdAt": "2025-02-15T08:33:38.000Z",
"updatedAt": "2025-02-15T08:33:45.000Z",
"hash": "0x80856f025035da9387873410155c4868c1825101e2c06d580aea48e8179b5e0b"
}
Important Note
This endpoint should only be called after a successful STK push payment (status: SUCCESS). The system automatically calculates exchange rates and fees based on the payment amount.
Ticket System
Overview
The ticket system allows you to create support tickets for failed or problematic transactions. You can create tickets in two ways:
- From a failed/pending transaction using orderID
- Creating a new ticket directly with all required information
Create Off-ramp Ticket
POST https://pool.swypt.io/api/create-offramp-ticket
From Failed Transaction:
// Creating ticket from failed transaction
const response = await axios.post('https://pool.swypt.io/api/create-offramp-ticket', {
orderID: "WD-xsy6e-HO",
description: "Refund for failed withdrawal",
symbol: "USDT", // Optional override
chain: "Polygon" // Optional override
}, {
headers: {
'x-api-key': 'YOUR_API_KEY',
'x-api-secret': 'YOUR_API_SECRET'
}
});
Direct Ticket Creation:
// Creating new ticket directly
const response = await axios.post('https://pool.swypt.io/api/create-offramp-ticket', {
phone: "254703710518",
amount: "100",
description: "Failed withdrawal attempt",
side: "off-ramp",
userAddress: "0x742d35Cc6634C0532925a3b844Bc454e4438f44e",
symbol: "USDT",
tokenAddress: "0xc2132D05D31c914a87C6611C10748AEb04B58e8F",
chain: "Polygon"
}, {
headers: {
'x-api-key': 'YOUR_API_KEY',
'x-api-secret': 'YOUR_API_SECRET'
}
});
Create On-ramp Ticket
POST https://pool.swypt.io/api/user-onramp-ticket
// Creating ticket from failed transaction
const response = await axios.post('https://pool.swypt.io/api/user-onramp-ticket', {
orderID: "D-rm3qn-3Q",
description: "Refund for failed STK push",
symbol: "USDT", // Optional override
chain: "Polygon" // Optional override
}, {
headers: {
'x-api-key': 'YOUR_API_KEY',
'x-api-secret': 'YOUR_API_SECRET'
}
});
Response Format
{
"status": "success",
"data": {
"refund": {
"PhoneNumber": "254703710518",
"Amount": "100",
"Description": "Failed withdrawal attempt",
"Side": "off-ramp",
"userAddress": "0x742d35Cc6634C0532925a3b844Bc454e4438f44e",
"symbol": "USDT",
"tokenAddress": "0xc2132D05D31c914a87C6611C10748AEb04B58e8F",
"chain": "Polygon",
"_id": "507f1f77bcf86cd799439011",
"createdAt": "2025-02-15T12:00:00.000Z"
}
}
}
Error Handling
Common Error Types
Authentication Errors
{
"status": "error",
"message": "API key and secret are required"
}
Validation Errors
{
"statusCode": 400,
"message": "Invalid network",
"error": "Unsupported network. Supported networks: Lisk, celo, Base, Polygon"
}
Not Found Errors
{
"status": "error",
"message": "Transaction WD-xsy6e-HO not found"
}
Duplicate Transaction
{
"status": "error",
"message": "This blockchain transaction has already been processed",
"data": {
"orderID": "WD-xsy6e-HO"
}
}
HTTP Status Codes
Status Code | Description | Common Causes |
---|---|---|
200 | Success | Request completed successfully |
400 | Bad Request | Invalid parameters, missing fields |
401 | Unauthorized | Invalid or missing API credentials |
404 | Not Found | Transaction or resource not found |
500 | Internal Server Error | Server-side processing error |
Best Practices
- • Always check the response status before processing data
- • Implement proper error handling for network timeouts
- • Log error responses for debugging purposes
- • Use the ticket system for failed transactions