Skip to content
SwapWalletDocs
فارسیGet an API key

Detect incoming deposits

Find every crypto deposit and incoming transfer on your SwapWallet account with one request a minute, without running a blockchain node.

You don’t need to watch a blockchain to know when money reaches your SwapWallet account. Every deposit becomes a transaction on your account, so one request a minute is enough to see it, whether it came from an outside wallet or from another SwapWallet user.

Two kinds of deposit

TypeWhere it comes fromDetails in
CRYPTO_DEPOSITAn on-chain transfer from any outside wallet to your deposit addresscryptoDeposit
TRANSFERAnother SwapWallet user sending to you, settled inside SwapWallet with no network feetransfer

Ask for both, and treat a TRANSFER as incoming only when transfer.toUser.isYou is true: the same type also covers transfers you send.

Ask for the latest deposits

Call List transactions with both types; results come newest first. Add tokens= (repeatable) to watch only some coins. Twenty results cover a minute of deposits for almost every account, so you don’t need to page through results.

GET/v2/transaction
HTTP
GET /api/v2/transaction?types=CRYPTO_DEPOSIT&types=TRANSFER&limit=20
Authorization: Bearer apikey-…
JSON
{
  "status": "OK",
  "result": {
    "hasNext": true,
    "data": [
      {
        "id": 3051234,
        "supportCode": "SW-M3NP8QR-TXVW",
        "timestamp": 1795164100000,
        "type": "TRANSFER",
        "status": "SUCCEED",
        "network": "INTERNAL",
        "transfer": {
          "amount": { "number": "5", "unit": "TON" },
          "fromUser": { "id": 4821, "isYou": false, "name": "علی رضایی" },
          "toUser": { "id": 52310, "isYou": true, … }
        }
      },
      {
        "id": 3051210,
        "supportCode": "SW-K7NP2QR-MXVT",
        "timestamp": 1795164000000,
        "type": "CRYPTO_DEPOSIT",
        "status": "SUCCEED",
        "network": "TRON",
        "cryptoDeposit": {
          "amount": { "number": "50", "unit": "USDT" },
          "contract": "TRC20",
          "hash": "8ce3e71ef8635d2bf27913bb680d7f88ad0238ea42c779c4b30f4e587d07da8e",
          …
        }
      },
      …
    ]
  }
}

Process each deposit once

Everything this request returns is final. A crypto deposit is listed only after it is confirmed and credited to your balance, and a transfer only once it is complete, so there is nothing to wait for and no status to re-check.

What needs care is telling new deposits from old ones:

  1. Keep the id of every deposit you have handled, with a unique index, in your own database.
  2. On each run, handle every listed transaction whose id you haven’t recorded.
  3. Record the id and credit your customer in the same database transaction, so a crash between the two can’t pay twice.

Don’t track only the highest id you’ve seen. IDs are unique, but they aren’t handed out in the exact order transactions complete, so a deposit can show up with a lower id than one you already processed. Compare against the set of IDs you’ve handled instead.

const BASE = 'https://swapwallet.app/api';
const headers = { Authorization: `Bearer ${process.env.SWAPWALLET_API_KEY}` };

async function poll() {
  const url = `${BASE}/v2/transaction?types=CRYPTO_DEPOSIT&types=TRANSFER&limit=20`;
  const res = await fetch(url, { headers });
  const body = await res.json();
  if (body.status !== 'OK') throw new Error(body.error?.codeString ?? `HTTP ${res.status}`);

  for (const tx of body.result.data.reverse()) {            // oldest first
    if (tx.type === 'TRANSFER' && !tx.transfer.toUser.isYou) continue; // you sent it
    if (await db.deposits.has(tx.id)) continue;              // handled before

    // One database transaction: record tx.id (unique index) and credit the
    // customer together, so a crash can never credit the same deposit twice.
    await db.transaction(async (trx) => {
      await trx.deposits.insert({ swapwalletId: tx.id });
      await creditCustomer(trx, tx);
    });
  }
}

setInterval(() => poll().catch(console.error), 60_000);

Catch up after downtime

If your poller was off for a while, more than twenty deposits may have arrived. Page back through the list, newest first: send the smallest id of each page as beforeId and stop once the transactions are older than when your poller went down, plus a few minutes of overlap. Handle any id you haven’t recorded, then go back to the one-minute poll.