Sending crypto through an API safely: idempotency, statuses and unknown outcomes

Send crypto from your backend without paying twice: idempotency keys, transfer statuses, address checks, fee coins and unknown broadcasts.

Published Updated 5 min read

Receiving crypto is forgiving: a missed webhook can be reconciled later. Sending is not. A blockchain transaction cannot be recalled, so a retry that creates a second transfer pays twice, and a transfer that looks failed but was in fact broadcast can be paid again by hand. This guide explains how the kryptr.io transfer API is built to avoid both, and what your code has to do.

The request

POST /api/v1/wallets/{id}/transfers
Idempotency-Key: withdrawal-81723
Content-Type: application/json

{"asset_id": "USDT.bsc", "to_address": "0x…", "amount": "120.5"}
  • asset_id is an asset of the wallet's networks, such as ETH.ethereum, USDT.tron or LTC.litecoin. GET /v1/wallet-assets lists them.
  • amount is a decimal string in whole units, with at most the asset's decimals.
  • callback_url is optional; transfer events go there in addition to your webhook endpoints, and it defaults to the wallet's own callback URL.
  • The API key needs the wallets:transfer scope.

Idempotency keys: one key, one transfer

Idempotency-Key is required. Generate it from your record of the payment (a withdrawal id), not randomly per HTTP attempt:

  • the first request with a key creates the transfer and answers 201;
  • a repeat with the same key and the same parameters answers 200 with the first transfer, without sending anything new;
  • a repeat with the same key and different parameters answers 409 idempotency_conflict.

So the rule for your code is simple: if a transfer request times out or the connection drops, send exactly the same request again with the same key. You either get the transfer that was created, or it is created now. You never get two.

Checks before anything is queued

The API refuses a transfer up front when it cannot succeed:

  • 400 invalid_address: the address fails its network's check (the EIP-55 checksum when the address is mixed case, the TRON, Bitcoin and Litecoin address checksums, the CRC of a TON friendly address);
  • 400 invalid_amount or unsupported_asset;
  • 422 insufficient_funds: the on-chain balance is too low;
  • 409 wallet_deleted: a deleted wallet cannot send;
  • 422 sanctioned_address: the recipient is on the OFAC SDN list;
  • 502 network_unavailable: the network's API could not be read, so the balance could not be checked.

The network fee comes from the wallet

Every transfer pays its network fee in the network's native coin, from the same wallet: ETH on Ethereum, Arbitrum, Optimism and Base, BNB on BNB Smart Chain, POL on Polygon, AVAX on Avalanche, TRX on TRON, BTC on Bitcoin, LTC on Litecoin, TON on TON. A wallet holding only USDT cannot send it. Keep some native coin on wallets you send from; on TRON, a USDT transfer without staked energy burns TRX, about 13 TRX in one of our own transfers in November 2026.

The status machine

Status Meaning
awaiting_approval held by the API key's policy (daily limit or address book) until you approve it with a 2FA code; approval moves it to pending, rejection to failed
pending queued, not yet signed
broadcasting a worker is signing and sending it
sent on the network; tx_hash is set
confirmed reached the network's confirmation count (final)
failed rejected, failed on chain or expired (final); failure_reason says why

Each step sends an event (transfer.created, transfer.sent, transfer.confirmed, transfer.failed) and GET /api/v1/transfers/{id} returns the current state. Treat only confirmed as paid and only failed as "not paid"; anything else is in progress.

One transfer in flight per address

A worker sends at most one transfer per address at a time. Account-based chains need it: an Ethereum transaction carries a nonce, a TON wallet a sequence number, and two transfers signed in parallel can collide. On Bitcoin and Litecoin the next transfer has to spend the previous transfer's change. So a batch of payouts from one wallet goes out one after another; to pay many recipients in parallel, send from several wallets.

When the outcome is unknown

The dangerous moment is the broadcast itself. A node can accept a transaction and then the connection drops before it answers. Was it sent?

kryptr treats that case conservatively:

  • if the error shows the transaction might have reached the network, the transfer is recorded as sent with its hash, and the confirmation checker settles it from the chain: confirmed if it lands, failed if the chain reports it failed;
  • on TRON and TON a transaction has an expiry; one that is not on chain 15 minutes after sending is marked failed with the reason "not included on chain before it expired";
  • a transfer left in broadcasting by a crash is never retried automatically, so the same funds are never signed and sent twice.

For your code that means:

  1. Never create a new transfer because an old one "looks stuck". Read its status first.
  2. A transfer in broadcasting for a long time needs a human look at the chain, not a resend.
  3. Retry only with the same Idempotency-Key; a new key is a new payment.

Protect the key that can send

  • Give wallets:transfer only to the service that sends, and keep read-only keys elsewhere.
  • Creating a key with wallets:transfer or wallets:mnemonic requires the account password and a TOTP code.
  • A dashboard transfer also asks for a TOTP code, and each code works once.
  • Every request is signed with HMAC-SHA256 and accepted once, within 5 minutes.
  • Give a sending key a daily limit in US dollars and an «address book only» rule: a transfer that breaks either gets the status awaiting_approval and waits until you approve or reject it in the dashboard with a 2FA code. A new address-book entry becomes usable after 24 hours.
  • A transfer to an address on the OFAC SDN list is refused with 422 sanctioned_address, whatever the key.
  • For an AI agent, make a key of its own and connect it through the MCP server kryptr-mcp (npx -y kryptr-mcp): it signs requests on your machine, reads the key's remaining budget (GET /api/v1/key) and cannot change the key's limits; KRYPTR_MCP_READ_ONLY=1 leaves out sending.

Checklist

  • Derive Idempotency-Key from your own payment id; retry with the same key.
  • Keep native coin on sending wallets for fees.
  • Pay out on transfer.confirmed; mark unpaid on transfer.failed.
  • Never resend a transfer that is sent or broadcasting.
  • Spread parallel payouts over several wallets.
  • Give sending keys a daily limit and an address book; approve held transfers in the dashboard.
  • Give an AI agent its own limited key through kryptr-mcp.

More guides