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

Learn how to build real-time, event-driven applications with FluxRail's Core blockchain monitoring. This step-by-step guide covers API authentication, webhook registration, signed payload verification, and chaining events into payments and payouts.

Why Event-Driven Architecture Needs Real-Time Blockchain Data

Event-driven applications react to changes the moment they happen. In Web3, those changes are on-chain: a deposit lands, a contract emits an event, a wallet balance shifts. Polling is the wrong tool — it's slow, expensive, and always behind. FluxRail's Core product gives you real-time blockchain event monitoring with signed webhooks across 36+ chains, so your backend can react instantly and verifiably.

This guide walks through the full lifecycle: authenticate, subscribe to addresses or contracts, receive signed webhooks, verify them, and handle retries. Every example uses the REST API directly — no SDKs, no wrappers. Copy, paste, run.

Step 1: Authenticate with Your API Key

All requests go to https://api.fluxrail.io with your API key in the X-API-Key header. Use flux_test_… for the fully simulated sandbox (full lifecycle and webhooks, no real money) and flux_live_… for production.

curl https://api.fluxrail.io/api/v1/chains \
  -H "X-API-Key: flux_test_xxx"

This returns the chains you can monitor. Inspect a single chain with GET /api/v1/chains/{slug}.

Step 2: Register a Webhook Endpoint

Before any subscription can deliver events, you need an active webhook. FluxRail signs every delivery with HMAC SHA-256 in the X-FluxRail-Signature header and includes a livemode flag.

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.com/webhooks/fluxrail",
    "events": ["address.activity", "contract.event"]
  }'

You can test a webhook with POST /api/v1/webhooks/{id}/test, toggle it with /toggle, and audit deliveries via GET /api/v1/webhooks/{id}/deliveries.

Step 3: Subscribe to Addresses or Contracts

Subscriptions define what you watch. Create one per address or contract, or batch them with POST /api/v1/subscriptions/bulk when onboarding many wallets at once.

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",
    "type": "address"
  }'

For contract events, set "type": "contract" and include the contract address. Manage subscriptions with GET/PUT/PATCH/DELETE /api/v1/subscriptions/{id}, and use /toggle or /duplicate for quick operations. GET /api/v1/subscriptions/stats gives you a summary of what's active.

Step 4: Verify Incoming Webhooks

Never trust an unsigned payload. Recompute the HMAC SHA-256 over the raw request body using your webhook secret, then compare it to X-FluxRail-Signature. Here's a minimal Node.js handler using fetch-style raw body access:

const crypto = require('crypto');

function verifyFluxRailSignature(rawBody, signature, secret) {
  const expected = crypto
    .createHmac('sha256', secret)
    .update(rawBody)
    .digest('hex');
  return crypto.timingSafeEqual(
    Buffer.from(expected),
    Buffer.from(signature)
  );
}

// Express example
app.post('/webhooks/fluxrail', express.raw({ type: '*/*' }), (req, res) => {
  const sig = req.headers['x-fluxrail-signature'];
  if (!verifyFluxRailSignature(req.body, sig, process.env.FLUXRAIL_WEBHOOK_SECRET)) {
    return res.status(401).send('Invalid signature');
  }
  const event = JSON.parse(req.body.toString());
  if (event.livemode === false) {
    console.log('Sandbox event', event);
  }
  // Process event.idempotently using event.id
  res.status(200).send('OK');
});

Always respond 200 quickly and process asynchronously. Use the event ID for idempotency.

Step 5: Query and Retry Events

Webhooks are the primary path, but the Events API is your safety net. List events with GET /api/v1/events, fetch one with GET /api/v1/events/{id}, and view aggregate stats with GET /api/v1/events/stats. If your endpoint was down, retry a delivery with POST /api/v1/events/{id}/retry.

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

This makes your pipeline resilient: even if a webhook is missed, you can reconcile from the events log.

Step 6: Chain Events into Payments and Payouts

Once you're reacting to on-chain events, you can trigger downstream actions. For gas-free transfers, FluxRail sponsors gas — but the wallet still needs enough value. Check first with GET /api/v1/transfer/balance?chain=&address=&token=, then execute with POST /api/v1/transfer. Note that transfers require an active webhook registered first, and status changes arrive as transfer.completed, transfer.partial, or transfer.failed.

For fiat settlement, the Payouts product converts stablecoins to bank accounts in 75+ countries. The flow is: create a customer, verify them, fund the wallet, then send. Every state transition arrives as a webhook — payout.pending_approval, payout.processing, payout.completed, or payout.failed. A registered active webhook is required before you can send any payout.

curl -X POST https://api.fluxrail.io/api/v1/payouts/customers/user-101/send \
  -H "X-API-Key: flux_live_xxx" \
  -H "Content-Type: application/json" \
  -d '{
    "amount": "250",
    "dest_currency": "USD",
    "method": "ach",
    "destination": {
      "account_owner_name": "Jane Doe",
      "account_number": "000123456789",
      "routing_number": "110000000",
      "account_type": "checking"
    }
  }'

The response returns the rail (e.g., ach) and a status of pending_approval. You'll learn the outcome through webhooks, not polling.

Putting It Together

You now have a complete event-driven loop: subscribe to on-chain activity, receive signed webhooks, verify them, reconcile via the Events API, and trigger transfers or payouts. FluxRail abstracts the chains, settlement networks, and compliance so you integrate one API. Start in sandbox with flux_test_…, then flip to flux_live_… when you're ready. Full reference at fluxrail.io/docs.