Swypt Logo

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 key
  • x-api-secret: Your API secret

Contact for Access

Contact our support team to obtain your API credentials for production or testing environments.

javascript
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

ParameterDescriptionRequiredExample
typeOperation typeYes"onramp" | "offramp"
amountAmount to convertYes"100"
fiatCurrencyFiat currency codeYes"KES"
cryptoCurrencyCryptocurrency symbolYes"USDT"
networkBlockchain networkYes"celo"
categoryTransaction categoryNo (offramp only)"B2C"

On-ramp Quote Example

Converting KES to USDT:

javascript
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:

json
{
  "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:

javascript
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:

json
{
  "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.

javascript
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:

json
{
  "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:

  1. Call the Swypt smart contract withdrawToEscrow or withdrawWithPermit functions
  2. 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.

javascript
// 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.

javascript
// 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.

javascript
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

javascript
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:

json
{
  "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 processed
  • SUCCESS: Transaction completed successfully
  • FAILED: Transaction failed

On-ramp Flow

Overview

The on-ramp process consists of three steps:

  1. Initiate STK Push for M-Pesa payment
  2. Monitor transaction status
  3. 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.

javascript
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

javascript
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:

json
{
  "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.

javascript
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:

json
{
  "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:

javascript
// 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:

javascript
// 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

javascript
// 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

json
{
  "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

json
{
  "status": "error",
  "message": "API key and secret are required"
}

Validation Errors

json
{
  "statusCode": 400,
  "message": "Invalid network",
  "error": "Unsupported network. Supported networks: Lisk, celo, Base, Polygon"
}

Not Found Errors

json
{
  "status": "error",
  "message": "Transaction WD-xsy6e-HO not found"
}

Duplicate Transaction

json
{
  "status": "error",
  "message": "This blockchain transaction has already been processed",
  "data": {
    "orderID": "WD-xsy6e-HO"
  }
}

HTTP Status Codes

Status CodeDescriptionCommon Causes
200SuccessRequest completed successfully
400Bad RequestInvalid parameters, missing fields
401UnauthorizedInvalid or missing API credentials
404Not FoundTransaction or resource not found
500Internal Server ErrorServer-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

Support and Resources

Email Support

support@swypt.io

Checkout SDK

React component integration

View Documentation →

© 2025 Swypt API Documentation. All rights reserved.