Quickstart
In this guide, you'll create your first Chainhook predicate to monitor STX transfers on the Stacks blockchain.
What you'll learn
Prerequisites
- For installation instructions, visit the Chainhook installation guide.
Quickstart
Generate a predicate file
Chainhook uses predicates to define what blockchain events to track. Generate a template predicate file:
$chainhook predicates new stx-transfer.json --stacks
This creates a boilerplate JSON file with the basic predicate structure. The --stacks
flag specifies you're tracking Stacks events (use --bitcoin
for Bitcoin).
Configure event tracking
Open stx-transfer.json
and update the if_this
section to track STX transfer events:
{"chain": "stacks","uuid": "87ac9bff-1052-4d02-9c79-3768a6f08a09","name": "STX Transfer","version": 1,"networks": {"mainnet": {"start_block": 154670,"if_this": {"scope": "stx_event","actions": ["transfer"]},"then_that": {"file_append": {"path": "stx-transfers.txt"}}}}}
This predicate will:
- Track all STX transfer events (
scope: "stx_event"
,actions: ["transfer"]
) - Start scanning from block 154670
- Append matching events to
stx-transfers.txt
Scan for events
Run the scan command to search historical blockchain data:
$chainhook predicates scan stx-transfer.json --mainnet
The first scan
downloads a chainstate archive from Hiro Archive. Subsequent scans use the cached data for faster performance.
View results
Check the output file to see the transfer events:
$head -5 stx-transfers.txt
Each line contains a JSON payload with transfer details including sender, recipient, amount, and block information.