Workflows for processing new blocks and transactions using block-triggered webhooks (from Alchemy Notify) and matching against watched addresses. These workflows demonstrate the block trigger pattern where the workflow reacts to incoming block data and extracts relevant transactions.
Directory Structure
building-blocks/indexer-block-trigger/
โโโ block-trigger-go/ (Go-based workflow)
โ โโโ workflow/
โ โโโ main.go
โ โโโ config.staging.json
โ โโโ config.production.json
โ โโโ workflow.yaml
โ โโโ README.md
โโโ block-trigger-ts/ (TypeScript-based workflow)
โโโ workflow/
โโโ main.ts
โโโ package.json
โโโ config.staging.json (optional)
โโโ workflow.yaml
โโโ README.md
Overview
These workflows demonstrate how to:
- React to block events via HTTP webhook triggers (We use Alchemy Notify for this workflow)
- Match transactions to a list of watched addresses
- Process and return JSON-formatted block and transaction data
- Implement the same logic in both Go and TypeScript
Both workflows process incoming block data and extract:
- Block number, hash, timestamp
- All transactions in the block
- Transactions where the
toaddress matches a watched address
Workflows
1 block-trigger-go (Go Implementation)
Language: Go
Features:
- Uses
http.Triggerfrom CRE Go SDK - Matches transactions to watched addresses from config
- Returns formatted JSON summary of block and matched transactions
Running the workflow:
cd building-blocks/indexer-block-trigger/block-trigger-go
cre workflow simulate workflow --non-interactive --trigger-index 0 --http-payload test-block.json --target staging-settings
2 block-trigger-ts (TypeScript Implementation)
Language: TypeScript
Features:
- Uses HTTP trigger from CRE TypeScript SDK
- Matches transactions to watched addresses from config
- Returns formatted JSON summary of block and matched transactions
Running the workflow:
cd building-blocks/indexer-block-trigger/block-trigger-ts/workflow
bun install
cre workflow simulate workflow --non-interactive --trigger-index 0 --http-payload test-block.json --target staging-settings
Setup and Testing
1 Prerequisites
For Go workflow:
- Install CRE CLI
- Login:
cre login - Install Go
For TypeScript workflow:
- Install CRE CLI
- Login:
cre login - Install Bun (or Node.js)
- Run
bun installin the workflow directory
2 Running the Workflows
Go Workflow:
cd building-blocks/indexer-block-trigger/block-trigger-go
cre workflow simulate workflow --non-interactive --trigger-index 0 --http-payload test-block.json --target staging-settings
TypeScript Workflow:
cd building-blocks/indexer-block-trigger/block-trigger-ts
cre workflow simulate workflow --non-interactive --trigger-index 0 --http-payload test-block.json --target staging-settings
3 Example Output
Both workflows return JSON output like:
{
"blockNumber": 12345678,
"blockHash": "0xabc...",
"timestamp": 1700000000,
"totalLogs": 42,
"uniqueTransactions": 10,
"matchedTransactions": 2,
"transactions": [
{
"hash": "0xdef...",
"from": "0x...",
"to": "0x73b668d8374ddb42c9e2f46fd5b754ac215495bc",
"value": "1000000000000000000"
}
]
}
Setting Up Alchemy Webhooks
1 Step-by-step Alchemy setup
To use Alchemy for block-triggered workflows, follow these steps:
- Sign up on Alchemy and navigate to their dashboard.
- Create a new app on the dashboard with your preferred network.
- Click on your app to open the app dashboard and scroll down to the
servicessection. - Click on the Webhooks service and in the pane that opens, click on
Real-time Notifications, then click onGet Started. - Choose webhook type
Customto listen for new blocks or events on every new block. - In the custom webhook pane, add other details including webhook name, chain, network, query template, and webhook URL.
- Click on
Create Webhookto save the webhook and test the webhook URL.
Tips:
- Make sure your webhook URL is accessible and correctly configured to receive POST requests.
- You may want to use a tool like Webhook.site for initial testing.
- Double-check the network and chain settings to match your workflow requirements.
- The query template should match the data you want to extract from each block/event.
Example Use Cases
1. Monitoring High-Value Addresses
Track transactions to specific addresses in real time:
{
"watchedAddresses": ["0x...", "0x..."]
}
2. Contract Interaction Tracking
Detect when contracts of interest receive transactions:
{
"watchedAddresses": ["0xContract1", "0xContract2"]
}
3. Block-Level Analytics
Summarize block activity and matched transactions for analytics dashboards.
CREATED BY CHAINLINK LABS