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 blockchain monitoring API. This step-by-step guide covers webhook setup, subscription creation, signature verification, and automated workflows.
Introduction
Modern blockchain applications demand real-time reactivity. Whether you're tracking wallet deposits, monitoring smart contract events, or triggering automated workflows, waiting for manual polling is inefficient and costly. FluxRail's Core product provides a unified API for subscribing to blockchain events across 36+ chains, delivering signed webhooks instantly to your backend. In this guide, we'll build a real-time event-driven application from scratch using FluxRail – no SDKs, just raw HTTP calls.
Prerequisites
- A FluxRail account (sign up free)
- A test API key (
flux_test_...) - A webhook endpoint (e.g.,
https://your-app.com/webhook) - Basic familiarity with curl or HTTP clients
Step 1: Create a Webhook Endpoint
FluxRail sends events to your endpoint via POST requests. First, register your webhook URL:
curl -X POST https://api.fluxrail.io/api/v1/webhooks \
-H 'X-API-Key: flux_test_YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"url": "https://your-app.com/webhook",
"description": "My production webhook",
"events": ["transaction.confirmed", "token.transfer"]
}'The response includes a secret used to verify webhook signatures. Save it securely.
Step 2: Subscribe to an Address
Now subscribe to a blockchain address (e.g., a USDC wallet on Ethereum):
curl -X POST https://api.fluxrail.io/api/v1/subscriptions \
-H 'X-API-Key: flux_test_YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"chain": "ethereum",
"address": "0x1234567890abcdef1234567890abcdef12345678",
"webhook_id": "wh_abc123",
"confirmations": 2
}'FluxRail will start monitoring that address. When a transaction occurs, it sends a signed webhook to your endpoint.
Step 3: Verify Webhook Signatures
Every webhook includes an X-FluxRail-Signature header. Verify it using HMAC SHA-256 with your secret to ensure authenticity. Example in Node.js (Express):
const crypto = require('crypto');
app.post('/webhook', (req, res) => {
const signature = req.headers['x-fluxrail-signature'];
const payload = JSON.stringify(req.body);
const expected = crypto
.createHmac('sha256', process.env.FLUXRAIL_WEBHOOK_SECRET)
.update(payload)
.digest('hex');
if (signature !== expected) {
return res.status(401).send('Invalid signature');
}
// Process event
console.log('Event received:', req.body);
res.status(200).send('OK');
});Step 4: Handle Events and Retries
FluxRail automatically retries failed deliveries up to 3 times. You can also manually retry from the dashboard or API:
curl -X POST https://api.fluxrail.io/api/v1/events/evt_xyz/retry \
-H 'X-API-Key: flux_test_YOUR_API_KEY'Check event logs for debugging:
curl https://api.fluxrail.io/api/v1/events?limit=10 \
-H 'X-API-Key: flux_test_YOUR_API_KEY'Step 5: Build an Event-Driven Workflow
Combine with FluxRail Pay for gas-free transfers. Example: when a deposit is detected, automatically initiate a payout:
// Inside webhook handler
if (event.type === 'transaction.confirmed' && event.data.token === 'USDC') {
// Trigger a payout via FluxRail Payouts
fetch('https://api.fluxrail.io/api/v1/payouts/customers/user-101/send', {
method: 'POST',
headers: {
'X-API-Key': 'flux_live_YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
token: 'USDC',
network: 'ERC20',
amount: '100',
dest_currency: 'USD',
method: 'ach',
destination: {
account_owner_name: 'Jane Doe',
account_number: '000123456789',
routing_number: '110000000',
account_type: 'checking'
}
})
});
}Conclusion
With FluxRail, building real-time event-driven applications becomes straightforward. You get a single API for monitoring, transfers, liquidity, and payouts – all with built-in compliance. Start with the free plan and scale as you grow. For more examples, visit our docs.