Build a Personal On-Chain Alert System Using Dune
Building a personal on-chain alert system using Dune lets you monitor blockchain activity in real time without relying on third-party services. Whether you want to track whale movements, sudden TVL changes, or rare smart contract events, Dune's SQL-based platform makes it possible to create highly customized alerts. In this guide, you’ll learn how to set up queries, schedule them, and deliver notifications—all with concrete examples you can adapt for Ethereum, Polygon, or other supported chains.
By the end, you’ll have a fully functional on-chain alert system Dune that notifies you via Telegram or email whenever conditions you define are met. No coding beyond basic SQL required, and you can start free with Dune's publicly available query engine.
- Dune’s SQL gives you unmatched flexibility to define exactly which on-chain events trigger alerts.
- Combine Dune with external services like Pipedream to deliver Telegram or email notifications on a schedule.
- Always parameterize your queries to reuse them for different assets, chains, or thresholds.
- Time windows and aggregation are essential to avoid alert fatigue; alert on changes over a period, not each transaction.
- Test your queries against historical data to ensure correct logic before going live with alerts.
- Consider Dune’s paid tier if you need sub-5-minute latency or higher query frequency.
What Is an On-Chain Alert System and Why Build One with Dune?
An on-chain alert system automatically notifies you when specific blockchain events occur—such as a whale transferring a large amount of USDC, a DeFi protocol’s TVL dropping by 20%, or a rare interaction with a newly deployed contract. Dune provides the infrastructure to query raw blockchain data using SQL, store results, and trigger actions. Unlike commercial alert services like Nansen or Etherscan email alerts, Dune gives you full control over the logic, data sources, and notification frequency. You’re not limited to pre-built templates; you can combine on-chain data from multiple protocols, add time filters, and even join across chains.
Dune’s public dashboards and query library mean you don’t start from scratch. You can fork existing queries and tweak them for your alerting needs. The platform also offers an API and webhook integrations, making it possible to automate notifications without writing a server.
Core Concepts: Queries, Parameters, and Notifications
Every alert in Dune starts with a SQL query that returns a result set. You can use Dune’s Spellbook (pre-built abstractions) for standard tables like transfers, mints, or swaps. Key concepts:
- Parameters: Add dynamic filters like
block_timerange, token address, or threshold amounts. This makes alerts reusable for different assets or chains. - Scheduled executions: Dune’s free tier lets you schedule queries to run every 15 minutes; paid tiers allow more frequent runs. The query checks if new data meets your alert condition.
- Notifications: Dune doesn’t natively send push notifications, but you can use its webhook integration (via Pipedream, Zapier, or a custom endpoint) to forward results to Telegram, Discord, or email.
Example: A simple whale alert query filters fortransfer.amount > 1000000(in wei) andblock_time > now() - interval '30 minutes'. If the result set is non-empty, a webhook triggers a Telegram message.
Setting Up Your Dune Workspace for Alerting
Start by creating a free Dune account at dune.com. Navigate to “Create” > “Query” to open the SQL editor. For alerting, you’ll typically create a query that returns only rows that should trigger a notification. Follow these steps:
- Choose a dataset: Use the
ethereum.transferstable for token transfers,ethereum.tracesfor internal calls, or protocol-specific tables likeuniswap_v3_ethereum.Pool_collectfor fees. - Add a time filter: Always filter by
block_time >= now() - interval '1 hour'to limit scanning, especially on free tier. - Set a threshold: For whale moves, use
value / 1e6 > 1000for USDC (6 decimals) orvalue / 1e18 > 100for ETH (18 decimals). - Save the query: Name it clearly, e.g., “Whale Alert – USDC transfer > 1M”.
Building Your First Whale Movement Alert
Let’s build a real-world whale alert for USDC on Ethereum. The goal: get notified whenever a single transfer of over 1 million USDC occurs.
Query:
SELECT tx_hash, "from", "to", value / 1e6 AS amount_usdc, block_time
FROM ethereum.transfers
WHERE contract_address = '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48'
AND block_time >= now() - interval '1 hour'
AND value / 1e6 > 1000000
ORDER BY block_time DESCScheduling: In the query editor, click “Schedule” and set it to run every 15 minutes. Check “Notify if results” – but Dune doesn’t have built-in push. Instead, you’ll integrate with a webhook.
Webhook integration with Telegram: Use Pipedream (free) to connect Dune’s API to Telegram. Create a Pipedream workflow that runs on a cron schedule identical to your Dune query. Within the workflow, make an HTTP request to Dune’s API to execute the query and parse results. If results exist, send a Telegram bot message with the details.
Alternatively, use Dune’s own webhook feature (under Settings > Webhooks) – but note that it only triggers when the query itself is updated (not on schedule). For true cron-based alerts, the Pipedream approach is more reliable.
Advanced Alert: Tracking TVL Spikes and Drops
TVL (Total Value Locked) alerts require querying protocol-specific tables or using Dune’s DefiLama integration. For example, to monitor the TVL of a Uniswap v3 pool:
Query for pool TVL change over last 24 hours:
WITH tvl_today AS (
SELECT SUM(pool_amount_usd) AS tvl_now
FROM uniswap_v3_ethereum.Pool_day
WHERE pool_address = '0x8ad599c3a0ff1de082011efddc58f8520a63c0d1'
AND day = CURRENT_DATE
),
tvl_yesterday AS (
SELECT SUM(pool_amount_usd) AS tvl_before
FROM uniswap_v3_ethereum.Pool_day
WHERE pool_address = '0x8ad599c3a0ff1de082011efddc58f8520a63c0d1'
AND day = CURRENT_DATE - INTERVAL '1' DAY
)
SELECT
tvl_now,
tvl_before,
(tvl_now - tvl_before) / NULLIF(tvl_before, 0) * 100 AS pct_change
FROM tvl_today, tvl_yesterdayTo make it an alert, schedule it daily and check whether pct_change exceeds a threshold (e.g., -10%). For intraday changes, use hourly aggregates from hourly tables.
Note: Some protocols update TVL every hour; others daily. Check the underlying table refresh frequency on Dune.
Catching Rare On-Chain Events (e.g., Large Liquidations, Contract Interactions)
Rare events often involve unique transaction traces or events. For example, detecting when a whale’s position gets liquidated on Aave:
Query for Aave liquidations:
SELECT evt_tx_hash, evt_block_time, user, liquidator, repayed_amount / 1e18 AS amount_eth
FROM aave_v2_ethereum.LiquidationCall_evt
WHERE evt_block_time >= now() - interval '1 day'
ORDER BY repayed_amount DESCSet a threshold on repayed_amount to filter only large liquidations (>100 ETH).
Another example: Monitor a specific contract for interactions from a known address. Use ethereum.traces with a filter on from or to address and type = 'CALL'. This is useful for tracking when a foundation wallet moves tokens.
Parameterization: Make your alert reusable by adding parameters for min_amount and lookback_hours. For example:
SELECT ... WHERE value / 1e18 > {{min_amount_eth}} AND evt_block_time >= now() - interval '{{lookback_hours}} hours'You can then define different parameter sets for different rare events.
Comparison Table: Dune vs. Other Alert Tools
| Feature | Dune (Free) | Dune (Paid) | Nansen | Etherscan Alerts | Custom Bot (Tenderly, Alchemy) |
|---|---|---|---|---|---|
| Real-time | Delayed (15 min) | Near real-time (1-5 min) | Near real-time | Real-time | Real-time |
| Customizable SQL | Full SQL | Full SQL | Pre-built queries | No SQL | Requires dev skills |
| Cost | Free | $$$ per month | $$$ per month | Free (limited) | Free tier (limited) / Pay-as-you-go |
| Complexity | Medium | Medium | Low | Very low | High |
| Whale tracking | Easy via SQL | Easy via SQL | Easy (prebuilt) | Basic address monitoring | Flexible |
| TVL alerts | Requires DefiLama tables | Same | Included (limited) | Not available | Manual setup |
Dune is the best compromise for those who want full control without building infrastructure from scratch.
Scheduling and Automating with Dune API and Webhooks
To move beyond manual checking, you need automation. Dune provides a REST API (with keys under Account Settings) and webhook endpoints. Steps:
- Get an API key: In Dune, go to Settings > API Keys. Create a key and note the ID.
- Execute a query via API: Use
POST /v1/query/{query_id}/executewith your API key in the header. The response includes an execution ID. - Fetch results: Poll
GET /v1/execution/{execution_id}/resultsuntil status isQUERY_STATE_COMPLETED. - Webhook trigger: Dune can call a webhook URL after a query finishes. Set this under “Webhooks” in the query editor. The webhook receives a payload with the query results (if any).
For those without a server, use Pipedream as mentioned. Alternatively, set up a simple Node.js script using Dune’s official API client library and run it on a cron service like Cron-Job.org.
Example: A Pipedream workflow that runs every 10 minutes, calls Dune API to execute a whale alert query, and sends a Telegram message if the result set is non-empty. The entire workflow is free for moderate usage.
Optimizing Alerts to Avoid Notification Fatigue
Too many false positives will make you ignore alerts. Strategies to keep notifications meaningful:
- Use minimum value thresholds: For whales, set a threshold high enough to filter standard transfers (e.g., >1M USDC). Adjust based on historical transfers in your query.
- Time window limiting: Only scan the last 15–60 minutes. This prevents repeated alerts for the same old event.
- Aggregate before alerting: Instead of alerting on each transfer, use
SUMover an hour to detect accumulation patterns. For TVL changes, compare current value to a moving average. - Add deduplication: In your webhook, store the last alerted
tx_hash(orblock_time) and skip if same. - Use Dune’s built-in “only notify if results” along with a unique identifier column to avoid retriggering.
With Dune’s paid tier, you can run queries more frequently and benefit from query caching, reducing the chance of missing events while still avoiding bombardment.
Security and Data Accuracy Considerations
When building an on-chain alert system with Dune, trust the index but verify. Dune indexes data from RPC nodes, and while extremely reliable, there can be brief delays (especially on free tier).
- Orphaned blocks: Rarely, a block might be included then reorged. Dune handles reorgs within a few minutes. Add a buffer: alert on events older than 1–2 minutes.
- API key security: Store your Dune API key in environment variables, never in client-side code. If using Pipedream, use their secret store.
- Webhook endpoints: If self-hosting, only accept requests from Dune’s IP range (documented) and validate the payload signature if available.
- Data completeness: Some Ethereum L2s or sidechains might have delayed indexing. For critical alerts, cross-reference with other indexers like The Graph subgraphs.
Finally, test your queries historical before enabling alerts. Run a query that covers the past week and verify it catches known events (e.g., a recent large transfer you manually found on Etherscan).
Step-by-step
- Create a Dune account and navigate to the Query editor.
- Write a SQL query that filters for your event (e.g., token transfers above a threshold) with a time filter.
- Save the query and note its Query ID from the URL.
- Add parameters for threshold amount and lookback hours to make the query reusable.
- Schedule the query: click Schedule and set a frequency (every 15 minutes on free tier).
- Generate a Dune API key from your Account Settings (API Keys).
- Set up a Pipedream workflow (or similar) that runs on a cron schedule, calls the Dune API to execute the query, and checks if results exist.
- If results exist, use a Telegram Bot API call or email service to send a notification with relevant details (tx_hash, amount, addresses).
- Test the alert by manually triggering the query and verifying the notification arrives.
- Adjust thresholds and time windows to reduce false positives and ensure alerts are actionable.
Common mistakes to avoid
- Using a lookback window too large (e.g., past 24 hours) causing high Dune query costs and redundant alerts.
- Forgetting to convert token decimals (e.g., treating USDC as 18 decimals instead of 6) leading to extremely wrong thresholds.
- Relying solely on Dune's built-in webhook (which only fires on query updates) instead of a cron-based schedule, missing scheduled executions.
- Not deduplicating transactions in the webhook logic, causing repeated alerts for the same event.
- Using free tier for high-frequency alerts (every 1 minute) but hitting rate limits or query execution quotas.
- Ignoring reorgs and alerting on unconfirmed blocks, resulting in false positives.
Frequently asked questions
How do I get notified when a whale moves more than 10 ETH?
Write a Dune query on the ethereum.transfers table for the Wrapped ETH contract (0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2) with a filter for value / 1e18 > 10 and a time window of the last 15 minutes. Then set up a Pipedream workflow to execute that query every 15 minutes and send a Telegram notification if results exist.
Can I use Dune alerts for free?
Yes, Dune’s free tier allows you to run queries on a schedule (every 15 minutes) and access the API. You can build a free alert system by combining Dune with Pipedream’s free tier and a Telegram bot. However, free tier has query execution limits, so choose your intervals wisely.
What’s the easiest way to get alerts for TVL changes?
Use Dune’s pre-built DefiLama integration tables (e.g., defillama.ethereum.tvl) and write a query that compares the latest hourly TVL with the previous hour. Set a percent change threshold. Schedule the query daily or hourly and use a webhook to notify you.
How often does Dune update its data?
On the free tier, data is updated approximately every 15 minutes (block-by-block). Paid plans offer near real-time updates (1-5 minute delay). For second-level precision, consider using Alchemy or Tenderly webhooks instead.
Do I need to know programming to set up alerts?
You need basic SQL knowledge for the queries. For the notification layer, some familiarity with JSON and webhook configuration is helpful, but tools like Pipedream have visual interfaces that minimize coding.
Related reading
Track the entities behind the concepts
DeFi Intel maps 11,000+ protocols, tokens and companies to a typed knowledge graph — with live data, incidents and regulation.