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

Learn how to build real-time event-driven applications using FluxRail's Core product. This step-by-step guide covers webhook setup, subscriptions, signature verification, and integrating payouts with blockchain events.

Introduction

In the world of Web3, fintech, and cross-border payments, real-time event-driven architecture is the backbone of responsive, scalable applications. Whether you're monitoring blockchain transactions, automating payouts, or reacting to on-chain activity, the ability to receive and process events as they happen is critical. FluxRail provides a unified API that abstracts blockchain monitoring, gas-free transfers, liquidity, and payouts — all with signed webhooks for real-time updates. In this guide, we'll walk through building a real-time event-driven application using FluxRail's Core product, focusing on webhooks, subscriptions, and event handling. By the end, you'll have a working setup to monitor blockchain addresses and react to transactions instantly.

Prerequisites

Before we dive in, ensure you have:

  • A FluxRail account (sign up at fluxrail.io)
  • An API key (test mode: flux_test_…)
  • Basic knowledge of REST APIs and webhooks
  • An HTTP client (curl, Postman, or your preferred tool)

Step 1: Understanding FluxRail Core

FluxRail Core is a real-time blockchain monitoring product. It allows you to subscribe to addresses or contracts across 36+ chains and receive events via signed webhooks. The key endpoints are:

  • POST /api/v1/subscriptions — create a subscription
  • GET /api/v1/events — fetch past events
  • POST /api/v1/webhooks — configure webhook endpoints

All requests are authenticated with the X-API-Key header.

Step 2: Setting Up a Webhook Endpoint

First, you need a public HTTPS endpoint to receive webhook events. For local development, use a tunneling service like ngrok. For this example, we'll use a simple HTTP server (e.g., a small Node.js server) to log incoming events. Here's a minimal example using Node.js (no SDK, just plain HTTP):

const http = require('http');
const server = http.createServer((req, res) => {
  let body = '';
  req.on('data', chunk => body += chunk);
  req.on('end', () => {
    console.log('Received webhook:', body);
    res.writeHead(200, {'Content-Type': 'application/json'});
    res.end(JSON.stringify({received: true}));
  });
});
server.listen(3000, () => console.log('Webhook listener on port 3000'));

Run this server and expose it publicly (e.g., ngrok http 3000). Note the public URL, e.g., https://abc123.ngrok.io/webhook.

Step 3: Registering a Webhook with FluxRail

Now, register your webhook endpoint with FluxRail using the POST /api/v1/webhooks endpoint. Provide a URL and optionally select events you want to receive. For simplicity, we'll receive all events.

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://abc123.ngrok.io/webhook",
    "description": "My test webhook"
  }'

The response will include a webhook ID and a secret for signature verification. Save the secret — you'll need it to verify incoming requests.

Step 4: Creating a Subscription

Next, create a subscription to monitor a blockchain address. Use the POST /api/v1/subscriptions endpoint. Specify the chain (e.g., ethereum), the address, and the event types you care about (e.g., incoming transactions).

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": "0x1234567890abcdef1234567890abcdef12345678",
    "event_types": ["transaction"],
    "webhook_url": "https://abc123.ngrok.io/webhook"
  }'

You can also create bulk subscriptions using POST /api/v1/subscriptions/bulk.

Step 5: Verifying Webhook Signatures

FluxRail signs all webhooks with HMAC SHA-256 using your webhook secret. The signature is in the X-FluxRail-Signature header. Always verify the signature to ensure the request is genuine. Here's a Node.js example:

const crypto = require('crypto');
// In your HTTP handler, extract headers and body
const signature = req.headers['x-fluxrail-signature'];
const secret = 'your_webhook_secret';
const expected = crypto.createHmac('sha256', secret).update(body).digest('hex');
if (signature !== expected) {
  res.writeHead(401);
  res.end('Invalid signature');
  return;
}
// Process event

Step 6: Handling Events

When a transaction occurs on the monitored address, FluxRail sends a POST request to your webhook URL with a JSON payload containing event details. The payload includes the event type, chain, address, transaction hash, and more. Here's a sample event:

{
  "id": "evt_123",
  "type": "transaction",
  "chain": "ethereum",
  "address": "0x1234...",
  "data": {
    "hash": "0xabc...",
    "from": "0x...",
    "to": "0x1234...",
    "value": "1000000000000000000"
  },
  "created_at": "2023-01-01T00:00:00Z",
  "livemode": false
}

Your application can process this event — for example, trigger a payout, update a database, or send a notification.

Step 7: Testing with the Sandbox

FluxRail's test mode is fully simulated. You can trigger test events by using the POST /api/v1/webhooks/{id}/test endpoint, which sends a sample event to your webhook. This is great for verifying your setup.

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

Step 8: Fetching Event History

In case you miss a webhook (e.g., server down), FluxRail stores events. You can retrieve them using GET /api/v1/events. Use pagination and filters to fetch specific events.

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

You can also retry failed webhook deliveries via POST /api/v1/events/{id}/retry.

Building a Real-Time Payout Trigger

Now let's combine Core with Payouts. Suppose you want to automatically pay out a user when they deposit funds to a monitored address. When you receive a transaction event, you can call the Payouts API to initiate a transfer. Here's a conceptual flow:

  1. Webhook received for deposit.
  2. Validate the event (check amount, address).
  3. Call POST /api/v1/payouts/customers/{id}/send to pay out the equivalent in fiat.
  4. Update your database with the payout status.

Example payout call:

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

Best Practices

  • Always verify webhook signatures to prevent spoofing.
  • Respond to webhooks quickly (within 2 seconds) with a 200 OK to avoid retries.
  • Process events asynchronously (e.g., queue them) to avoid blocking.
  • Use idempotency keys for critical operations like payouts.
  • Monitor webhook delivery logs via GET /api/v1/webhooks/{id}/deliveries.

Conclusion

With FluxRail, building real-time event-driven applications is straightforward. You can monitor blockchain activity, receive signed webhooks, and automate downstream actions like payouts — all through one API. The sandbox allows you to test everything without real funds. Start building today with FluxRail and unlock the power of real-time blockchain integration.

For more details, check the FluxRail Docs.