Real-Time Triggers (Webhooks)
Real-Time Triggers, commonly known as webhooks, are pivotal in integrating real-time data into Web3 applications. They enable instantaneous data access, prompt notifications, dynamic interactions, enhanced user experiences, automation, and streamlined workflows.
This document provides a step-by-step guide on implementing Real-Time Triggers in your Web3 applications.
Prerequisites
- Familiarity with ZettaBlock's APIs.
- Understanding of HTTP request methods and JSON format.
General Implementation Steps
Step 1: Write a Query
Choose the relevant data tables and write your desired logic. Keep in mind that webhooks are currently only supported for real-time (postgreSQL) tables.
Step 2: Create a Real-Time API
Create a one-click-ready API endpoint based on your query. Set your primary key and indexers depending on your logic.
Step 3: Create and Test a Webhook
In the API settings, select 'Create a Trigger'.
Configuration:
- Destination URL: Specify where the webhook should send data.
- Granularity: Choose between PerRecord and PerBatch.
- Format is automatically set to JSON.
- Testing: Use a testing tool to simulate events and verify the webhook's response.
Error Handling and Debugging
- Logs: Monitor webhook logs for errors or unexpected behavior.
- Status Codes: Pay attention to (external) HTTP status codes for success (200 OK), client errors (4xx), and server errors (5xx).
- Retry Logic: Implement retry mechanisms for failed webhook deliveries.
Example: Real-Time Notifications for High-Value ETH Transfers
This example demonstrates setting up a Real-Time Trigger in ZettaBlock for monitoring Ethereum transfers exceeding 50 ETH. The webhook will notify a specified Telegram channel upon detecting such transfers.
Step 1: Write a Query
SELECT
from_address,
transaction_hash,
amount
FROM
(
SELECT
from_address,
transaction_hash,
(VALUE / POW(10, decimals)) AS amount
FROM
ethereum_mainnet.eth_transfers
WHERE
data_creation_date = CURRENT_DATE
) AS subquery
WHERE
amount > 50
GROUP BY
1,
2,
3
Step 2: Create a Real-Time API
In this case, set your primary key to transaction_hash
.
Step 3: Create and Test a Webhook
Configuration:
- Destination URL: Enter the webhook URL provided by your Telegram bot.
- Granularity: Set to PerRecord to trigger notifications for each qualifying transaction.
With this setup, you receive real-time Telegram notifications for high-value ETH transfers, effectively utilizing ZettaBlock's Real-Time Triggers. These notifications not only keep you informed but also empower you to take immediate action.
Upon receiving a notification, you have the option to manually monitor the involved addresses more closely - however, you can also further automate this process.
The real-time data provided by these webhooks can be integrated into your own trading systems. For instance, you could automate a trading bot to initiate specific actions in response to these high-value transactions. The webhook acts as a trigger, setting off predefined trading strategies or adjustments in your bot, based on the nature and scale of the transactions detected.
Updated 9 months ago