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 unified API. This step-by-step guide covers webhooks, subscriptions, and event processing with code examples.
Introduction
In the world of Web3 and fintech, real-time event-driven architecture is no longer a luxury—it's a necessity. Whether you're monitoring on-chain transactions, automating payouts, or reacting to liquidity changes, your system needs to respond instantly. FluxRail provides a unified API that abstracts blockchain monitoring, payments, and settlement, making it the perfect backbone for event-driven applications. 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 processing. No SDKs—just plain HTTP requests.
Why Event-Driven with FluxRail?
FluxRail Core lets you subscribe to blockchain addresses and contracts across 31+ chains. When an event occurs (e.g., a transaction, a token transfer), FluxRail sends a signed webhook to your endpoint. This is ideal for building applications that need to react to on-chain activity in real time: payment detection, wallet monitoring, fraud alerts, and more. With FluxRail, you don't need to manage chain-specific infrastructure—just one API.
Prerequisites
Before we begin, ensure you have:
- A FluxRail account (sign up at fluxrail.io)
- An API key (test mode:
flux_test_...) - A publicly accessible webhook endpoint (e.g., using ngrok for local development)
- cURL or any HTTP client
Step 1: Create a Webhook Endpoint
First, set up a simple HTTP server that can receive POST requests. Here's a minimal example using Python's Flask (but you can use any language):
from flask import Flask, request, jsonify
app = Flask(__name__)
@app.route('/webhook', methods=['POST'])
def webhook():
payload = request.get_json()
# Verify signature (see Step 4)
print(payload)
return jsonify({'received': True}), 200
if __name__ == '__main__':
app.run(port=5000)
Run this locally, then expose it using ngrok http 5000 to get a public URL.
Step 2: Register the Webhook with FluxRail
Use the FluxRail API to register your webhook endpoint. You'll need your API key and the public URL from ngrok.
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-ngrok-url.ngrok.io/webhook",
"events": ["transaction.confirmed", "token_transfer"],
"description": "My real-time app webhook"
}'
The response will include a webhook ID and a signing secret (keep it safe!). This secret is used to verify that webhooks genuinely come from FluxRail.
Step 3: Create a Subscription
Now, create a subscription to monitor a specific address or contract. For example, let's subscribe to a USDC contract 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 '{
"type": "contract",
"chain": "ethereum",
"address": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
"events": ["token_transfer"],
"webhook_url": "https://your-ngrok-url.ngrok.io/webhook"
}'
This tells FluxRail to watch for token transfers on the USDC contract and send them to your webhook.
Step 4: Handle Incoming Webhooks Securely
FluxRail signs every webhook with HMAC SHA-256. The signature is in the X-FluxRail-Signature header. You must verify it to prevent spoofing. Here's how to verify in Python:
import hmac, hashlib, os
SECRET = os.environ['FLUXRAIL_WEBHOOK_SECRET']
def verify_signature(payload, signature):
computed = hmac.new(SECRET.encode(), payload, hashlib.sha256).hexdigest()
return hmac.compare_digest(computed, signature)
Then in your webhook handler, before processing, verify the signature. If invalid, return 401.
Step 5: Process Events in Real Time
Once your webhook receives an event, you can process it. For example, if you're building a payment detection system, you might:
- Parse the event payload (contains transaction hash, amount, sender, recipient, etc.)
- Update your database
- Trigger downstream actions (e.g., send a notification, execute a payout)
Here's a sample event payload:
{
"id": "evt_123",
"type": "token_transfer",
"chain": "ethereum",
"data": {
"transaction_hash": "0xabc...",
"from": "0x...",
"to": "0x...",
"amount": "100.00",
"token": "USDC"
},
"created_at": "2025-01-01T00:00:00Z",
"livemode": false
}
Step 6: Retry Logic and Error Handling
FluxRail automatically retries webhook delivery if your endpoint fails (e.g., returns 5xx). You can monitor deliveries via the API:
curl -X GET https://api.fluxrail.io/api/v1/webhooks/{webhook_id}/deliveries \
-H "X-API-Key: flux_test_xxx"
If you need to manually retry an event, use:
curl -X POST https://api.fluxrail.io/api/v1/events/{event_id}/retry \
-H "X-API-Key: flux_test_xxx"
Step 7: Test Your Setup
FluxRail's test mode is fully simulated. You can trigger a test webhook to ensure your endpoint works:
curl -X POST https://api.fluxrail.io/api/v1/webhooks/{webhook_id}/test \
-H "X-API-Key: flux_test_xxx"
This will send a sample event to your webhook.
Advanced: Using FluxRail Pay for Automated Payouts
Once you've detected a payment via webhook, you might want to trigger a payout. With FluxRail's Payouts product, you can do this seamlessly. For example, after confirming a payment, you can call:
curl -X POST https://api.fluxrail.io/api/v1/payouts/customers/{customer_id}/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"
}
}'
This will convert and settle the payout via the appropriate rail (ACH, SEPA, etc.)—FluxRail handles the rest.
Conclusion
Building real-time event-driven applications with FluxRail is straightforward. With just a few API calls, you can set up webhooks, subscribe to on-chain events, and trigger automated actions. FluxRail abstracts the complexity of blockchain monitoring and payment settlement, letting you focus on your application's logic. Start building today with FluxRail's free tier and scale as you grow.
For more details, check the FluxRail docs.