Bitcoin and Web3 development is hard for a lot of reasons. Chief among them is that it can be difficult to get reliable blockchain data for your application. Many devs have to maintain their own index of blockchain chainstate, which can incur high storage costs and be challenging to keep up to date. Re-orgs of chainstate happen often, and every time there’s a re-org, you have to re-index the entire chain, which can be a time-intensive process.
Chainhook tackles this problem head-on in two ways: an engine that provides more efficient indexing and webhook-style triggers for building IFTTT logic in your applications.
What Is Chainhook?
Chainhook is an open-source engine that enables you to build consistent, reorg-proof databases that index only the information you want—you can specify what on-chain data you want to track, creating a lighter-weight index. This reduces both your storage management burden and the time it takes to spin up an index, enabling you to move more quickly.
Chainhook enables you to build consistent, reorg-proof databases that index only the information you want.
By working with a lighter database, you have faster query results, which helps end-user response time. A better developer experience, and a better user experience too.
Chainhook is fork-aware which means it keeps a store of all possible chain forks and checks each new on-chain event against those forks to maintain the current valid chain tip. In the event of a reorg, Chainhook will automatically rollback any invalid blocks and compute any new blocks.
Chainhook can be used as a standalone development tool and as a service to extract data from the Bitcoin and the Stacks blockchains to trigger IFTTT logic in your applications.
Trigger IFTTT Logic in Your Application
Chainhook is not only a powerful indexer. It also helps you create elegant event-based architecture, using individual “chainhooks”. Each chainhook trigger specifies a rule that is applied as a filtering function on every block transaction. You can customize these individual chainhooks based on an array of on-chain events, including:
- A certain amount of SIP-10 tokens were transferred
- A particular blockchain address received tokens on the Stacks or Bitcoin blockchain
- A particular print event was emitted by a contract
- A particular contract was involved in a transaction
- A quantity of BTC was received at a particular Bitcoin address
- And more
These events then trigger actions, such as writing to a database or a smart contract.
For example, Zest, a Bitcoin lending protocol, relies on chainhooks to observe events on both Bitcoin and Stacks blockchains. In particular, Zest Protocol uses smart contracts that create and adjust liquidity pools to fund loans, distribute rewards to BTC liquidity providers, and process withdrawals. All these use cases are event-driven, and those events trigger smart contract behavior and database updates in real-time. Zest can rest easy, knowing that their chainhooks will surface these events in a reliable and resilient manner.
In other words, you can think of a chainhook as triggering IFTTT (if this, then that) logic that corresponds to on-chain behavior. This is all possible without creating a separate comprehensive blockchain indexer.
You can think of an individual chainhook as IFTTT (if this, then that) logic that corresponds to on-chain behavior.
Say goodbye to unscalable, brittle and difficult-to-maintain IFTTT code in your app’s architecture. Say hello to chainhooks: reliable, reorg-resistant, customizable logic at your fingertips.
Start Building With Chainhook
Today, there are a few ways to get started with Chainhook, the transaction indexing engine, and chainhooks, customizable triggers that react to real-time blockchain events.
You can install Chainhook locally by following the instructions in the GitHub ReadMe. Learn how to use Chainhook locally in this demo video:
Alternatively, you can set up chainhooks in Clarinet or in the Hiro Platform. The Hiro Platform is a web-hosted developer experience that empowers you to create, build, and deploy smart contracts on Stacks, going from idea to mainnet in a predictable and repeatable way.
The Hiro Platform enables you to create and deploy smart contracts from a web browser, with zero installations.
The Hiro Platform increases your productivity by requiring fewer installs and fewer steps as you go from concept to mainnet. Last month, we launched deployment plans in the Hiro Platform, and today we are excited to announce Chainhook as a new feature in the Hiro Platform, giving you more development capabilities than ever before.
With the platform’s hosted developer experience, Chainhook makes cross-chain interaction more straightforward for all developers. Learn more about how to set up chainhooks in the platform in this video demo:
Read about how to create a chainhook in the Hiro Platform in our docs.
At Hiro, we want to empower developers to build exciting applications on Bitcoin, and with Chainhook, we’ve taken away all of the developer burden that comes with the time, energy and operational overhead costs that are required to get reliable blockchain data in your application.
Instead, you can focus on automating triggers that correspond to the blockchain events your app needs to respond to. We can’t wait to see what you build with chainhooks.
Today, Chainhook supports Bitcoin and Stacks, and the code is completely open-source. We encourage you to take a look at the code and build on it, and we welcome any contributions and feedback.