Building Real-Time Event-Driven Apps with FluxRail: Step-by-Step

Learn how to build real-time, event-driven applications on FluxRail using signed webhooks, address subscriptions, and the REST API — no SDK required. A complete step-by-step guide from webhook registration to verified event handling and gas-free transfers.

Why Event-Driven Beats Polling

If you've ever shipped a deposit watcher, you know the drill: a cron job hits a chain RPC every 15 seconds, compares block heights, and hopes it doesn't miss a reorg. It's brittle, expensive, and slow. FluxRail flips that model. You subscribe to an address or contract on any of 36+ chains, and FluxRail pushes a signed webhook the moment a matching event lands. Your application reacts instead of asking.

In this guide we'll build the full loop with the REST API directly — no SDK, just curl and fetch. By the end you'll have a webhook endpoint, a subscription, verified signatures, and a retry strategy.

Step 1 — Get Your API Key and Register a Webhook

Every request goes to https://api.fluxrail.io with an X-API-Key header. Start in test mode (flux_test_…); the sandbox is fully simulated, so you can exercise the entire lifecycle — including webhook deliveries — without touching real funds.

curl -X POST https://api.fluxrail.io/api/v1/webhooks \
  -H "X-API-Key: flux_test_xxx" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://your-app.example.com/hooks/fluxrail",
    "description": "Deposit watcher"
  }'

The response includes the webhook id and a signing secret. Store the secret in your environment — you'll need it in Step 4. You can confirm delivery health at any time:

curl https://api.fluxrail.io/api/v1/webhooks/{webhook_id}/deliveries \
  -H "X-API-Key: flux_test_xxx"

Before going live, fire a test payload to make sure your endpoint responds with a 2xx:

curl -X POST https://api.fluxrail.io/api/v1/webhooks/{webhook_id}/test \
  -H "X-API-Key: flux_test_xxx"

Step 2 — Create a Subscription

A subscription binds a chain address (or contract) to a webhook. Let's watch a wallet for incoming transfers on Ethereum:

curl -X POST https://api.fluxrail.io/api/v1/subscriptions \
  -H "X-API-Key: flux_test_xxx" \
  -H "Content-Type: application/json" \
  -d '{
    "chain": "ethereum",
    "address": "0x742d35Cc6634C0532925a3b844Bc454e4438f44e",
    "webhook_id": "{webhook_id}",
    "label": "treasury-wallet"
  }'

Need to onboard a thousand deposit addresses at once? Use the bulk endpoint instead of looping:

curl -X POST https://api.fluxrail.io/api/v1/subscriptions/bulk \
  -H "X-API-Key: flux_test_xxx" \
  -H "Content-Type: application/json" \
  -d '{
    "webhook_id": "{webhook_id}",
    "subscriptions": [
      { "chain": "ethereum", "address": "0xabc…", "label": "user-101" },
      { "chain": "tron", "address": "TQn9Y2khEsLJW1ChVWFMSMeRDow5KcbLSE", "label": "user-102" }
    ]
  }'

Check your coverage with GET /api/v1/subscriptions/stats, and list available networks with GET /api/v1/chains — every slug you see there is a valid chain value.

Step 3 — Receive and Verify the Webhook

FluxRail signs every delivery with HMAC SHA-256 in the X-FluxRail-Signature header and includes a livemode flag in the body. Never trust an unverified payload. Here's a minimal Node handler using only built-in modules and fetch-free crypto:

const crypto = require('crypto');
const express = require('express');
const app = express();

// Raw body is required for signature verification
app.post('/hooks/fluxrail', express.raw({ type: '*/*' }), (req, res) => {
  const signature = req.headers['x-fluxrail-signature'];
  const expected = crypto
    .createHmac('sha256', process.env.FLUXRAIL_WEBHOOK_SECRET)
    .update(req.body)
    .digest('hex');

  if (!crypto.timingSafeEqual(Buffer.from(signature), Buffer.from(expected))) {
    return res.status(401).send('invalid signature');
  }

  const event = JSON.parse(req.body.toString());
  if (event.livemode === false) {
    console.log('sandbox event:', event.type);
  }

  // Acknowledge fast, process async
  res.status(200).send('ok');
  queue.push(event);
});

app.listen(3000);

Two rules that save you pain: respond with a 2xx before doing slow work, and make your handler idempotent using the event id.

Step 4 — Query and Replay Events

Webhooks can fail if your server is down. FluxRail keeps the event log, so you can backfill or reconcile:

curl "https://api.fluxrail.io/api/v1/events?limit=50" \
  -H "X-API-Key: flux_test_xxx"

Inspect a single event, or re-deliver one that your endpoint missed:

curl https://api.fluxrail.io/api/v1/events/{event_id} \
  -H "X-API-Key: flux_test_xxx"

curl -X POST https://api.fluxrail.io/api/v1/events/{event_id}/retry \
  -H "X-API-Key: flux_test_xxx"

Per-subscription delivery history lives at GET /api/v1/subscriptions/{id}/webhook-logs, which is the fastest way to debug a single address that isn't firing.

Step 5 — Turn Events Into Money Movement

Detection is half the story. Suppose a deposit lands and you want to forward it. FluxRail's Pay product sponsors gas, so the user never needs native tokens for fees — but the wallet still needs enough of the asset being sent. Check first:

curl "https://api.fluxrail.io/api/v1/transfer/balance?chain=ethereum&address=0x742d…&token=USDT" \
  -H "X-API-Key: flux_test_xxx"

Then execute the transfer. Note that Pay requires an active webhook to already exist — which you registered in Step 1:

curl -X POST https://api.fluxrail.io/api/v1/transfer \
  -H "X-API-Key: flux_test_xxx" \
  -H "Content-Type: application/json" \
  -d '{
    "chain": "ethereum",
    "to": "0x9f8…",
    "amount": "25.00",
    "token": "USDT",
    "from_private_key": "0x…",
    "client_reference_id": "fwd-deposit-8821"
  }'

Every status change — transfer.completed, transfer.partial, transfer.failed — arrives at your webhook. There is no polling substitute, so your event handler is the source of truth.

Production Checklist

  • Verify every signature with the raw request body, not the parsed JSON.
  • Idempotency: dedupe on event id before writing to your ledger.
  • Fast ACK: return 2xx in under a second, enqueue the work.
  • Backfill on boot: call GET /api/v1/events for anything missed during downtime.
  • Separate test and live using livemode and distinct API keys.
  • Toggle, don't delete: POST /api/v1/subscriptions/{id}/toggle pauses a watcher without losing history.

That's the whole pattern: one webhook, one subscription, verified events, and a direct line into transfers. Grab a test key and read the full reference at fluxrail.io/docs.