DEV Community

Cover image for Accept USDC / USDT Without Running Your Own Wallet Infrastructure (Afriex API)
0xSonOfUri for Afriex

Posted on

Accept USDC / USDT Without Running Your Own Wallet Infrastructure (Afriex API)

Stablecoins are becoming core infrastructure for global payments.

But building with them usually means:

  • managing private keys
  • running indexers
  • tracking on-chain activity

That’s a lot of overhead.

In this guide, you’ll learn how to accept USDC / USDT without running your own custody infrastructure, using the Afriex API.


What You’ll Build

  • A backend endpoint that returns deposit instructions (address + network)
  • A webhook system to confirm payments reliably
  • A production-ready flow using idempotency and retries-safe logic

The Mental Model

Stop thinking:

“I need to manage wallets”

Start thinking:

“I’m building on payment rails”

With Afriex:

  • You don’t generate private keys
  • You don’t run blockchain infrastructure
  • You rely on Afriex for:

    • deposit attribution
    • transaction state
    • settlement

Your job is to:

  • create a payment / invoice object
  • show deposit instructions
  • confirm payments via webhooks

Step 0 — Setup API Access

Base URLs

  • Sandbox: https://sandbox.api.afriex.com
  • Production: https://api.afriex.com

Environment Variables

AFRIEX_API_BASE_URL="https://api.afriex.com"
AFRIEX_API_KEY="your-api-key"
AFRIEX_WEBHOOK_PUBLIC_KEY="your-public-key"
Enter fullscreen mode Exit fullscreen mode

Example Request

curl -sS -G "https://api.afriex.com/api/v1/org/balance" \
  -H "x-api-key: YOUR_AFRIEX_API_KEY"
Enter fullscreen mode Exit fullscreen mode

Step 1 — Create Your Payment Object

Afriex does not create payment links for you.

You define your own invoice / payment intent:

{
  id: "internal_id",
  reference: "unique_reference",
  asset: "USDC",
  amount: 100,
  status: "pending",
  expiresAt: Date
}
Enter fullscreen mode Exit fullscreen mode

Tip: Make reference globally unique and reuse it across retries.


Step 2 — Get Deposit Address

Endpoint

GET /api/v1/payment-method/crypto-wallet
Enter fullscreen mode Exit fullscreen mode

Example

curl -sS -G "https://api.afriex.com/api/v1/payment-method/crypto-wallet" \
  -H "x-api-key: YOUR_API_KEY" \
  --data-urlencode "asset=USDC"
Enter fullscreen mode Exit fullscreen mode

Response

{
  "data": [
    { "address": "0x...", "network": "ETHEREUM_MAINNET" },
    { "address": "TY...", "network": "TRON_MAINNET" }
  ]
}
Enter fullscreen mode Exit fullscreen mode

Backend Example

const wallet = await fetch(url).then(res => res.json())

const preferred =
  wallet.data.find(w => w.network === "ETHEREUM_MAINNET") ??
  wallet.data[0]

return {
  address: preferred.address,
  network: preferred.network,
  asset: "USDC"
}
Enter fullscreen mode Exit fullscreen mode

Important Note

This endpoint is:

Production only

It does not work in sandbox.


Step 3 — Display Payment Instructions

Your UI should show:

  • Asset (USDC / USDT)
  • Network
  • Address (copy + QR)

Also include:

Sending on the wrong network may result in lost funds


Step 4 — Confirm Payments (Webhooks)

This is the most important part.

Do NOT:

  • rely on user confirmation
  • rely on block explorers

Use Afriex webhooks.


Webhook Setup

  • Configure your webhook URL in the dashboard
  • Copy your webhook public key
  • Allowlist Afriex IPs

Signature Verification

import crypto from "crypto"

function verifySignature(signature, rawBody, publicKey) {
  const verifier = crypto.createVerify("RSA-SHA256")
  verifier.update(rawBody)
  return verifier.verify(publicKey, signature, "base64")
}
Enter fullscreen mode Exit fullscreen mode

Important: verify the raw request body, not parsed JSON.


Events

  • TRANSACTION.CREATED
  • TRANSACTION.UPDATED

Logic

if (event === "TRANSACTION.UPDATED" && status === "SUCCESS") {
  markInvoiceAsPaid()
}
Enter fullscreen mode Exit fullscreen mode

Ensure this operation is idempotent.


Step 5 — Idempotency

Outbound

Use:

{
  "meta": {
    "reference": "invoice_123",
    "idempotencyKey": "idem_invoice_123"
  }
}
Enter fullscreen mode Exit fullscreen mode

Inbound

Webhooks may retry.

Ensure:

  • no duplicate credits
  • safe re-processing

Use database constraints or “update-if-not-paid” logic.


Step 6 — Reconciliation

Use Afriex APIs for support and debugging:

  • Get transaction
  • List transactions
  • Get balance

⚠️ Common Pitfalls

1. Crypto Wallet Not Working in Dev

→ It’s production only


2. Wrong Network Deposits

→ Only present one supported network


3. Webhook Verification Fails

→ Use raw body + correct public key


4. Duplicate Credits

→ Fix with idempotency


Why This Matters

Stablecoins are becoming:

Core rails for global payments

The real opportunity isn’t just using them.

It’s building systems on top of them.


Summary

With Afriex, you can:

  • Accept USDC / USDT
  • Avoid custody complexity
  • Use webhooks for reliable confirmation
  • Build production-ready payment systems

Final Thought

Afriex gives you the rails.

You build the product.


Top comments (0)