With chainhooks, you can automatically trigger an action in response to on-chain events on Stacks, Bitcoin, and other Bitcoin layers, enabling you to use IFTTT (if_this, then_that) logic to power your applications. To learn more about Chainhook, refer to Chainhook overview documentation.
This guide helps you create a chainhook using the Hiro Platform.
Once you are on the Projects page, select the project to create a chainhook.
You'll see a navigation bar with two tabs, Contracts, and Chainhooks. Select Chainhooks to create a new chainhook.
Select the Create chainhook button at the bottom of the screen.
A new pane opens up on the right to create a chainhook. Use the following fields to create a chainhook:
Name: Define a chainhook name of your choice.
Chain: Select between Bitcoin and Stacks to create a chainhook.
Network: Choose a network between
testnet to observe for events.
If-this: Based on the selected chain, you will see a list of available scopes for the
For Bitcoin, the available predicate options are
For Stacks, the available predicate options are
Then-that: This action is defaulted to
http_post to allow the chainhook to post events to the URL specified in the below option.
URL: Specify a URL to post chainhook events to the HTTP_post method.
Authorization Header: This field is optional to add a Secret to the
authorization header when posting payloads.
Start Block: This field must specify the start block to search the chain.
End Block: It is optional to specify the end block. However, to optimize your scan time, it is recommended to specify this field.
Expire After Occurrence: You can specify a number greater than or equal to 1 to expire the chainhook after a specific number of occurrences. You can leave this blank if you don't want to set any limit.
Decode Clarity Values: This is enabled by default for stacks predicates to help you decode clarity values in your contract.
You'll see the following options for Bitcoin chain,
Include Proof: Enable this option when you have evidence that the transaction or block has been verified and authorized by the sender using their private key. This proof is generally a cryptographic signature to a transaction or block on the Bitcoin blockchain.
Include Inputs: Enable this option to include Bitcoin transaction inputs in the payload. In a Bitcoin transaction, inputs are references to previous transactions' outputs (also known as unspent transaction outputs or UTXOs) that are being spent in the current transaction. These inputs provide evidence that the sender has the right to spend the funds.
Include Outputs: Enable this option to include Bitcoin transaction outputs in the payload. Including outputs in a Bitcoin transaction refers to specifying the destinations and amounts of Bitcoin being sent as part of a transaction. Outputs in a Bitcoin transaction represent the recipients' addresses and the corresponding amounts of Bitcoin they are receiving.
Include Witness: Enable this option to include Bitcoin transaction witness in the payload. The witness data for a transaction includes the cryptographic signatures and other related information placed alongside the transaction data in the block.
Once you define the all the required fields, you can select Create Chainhook.
The right pane navigates to the Projects page with the Chainhooks tab open, and you can view the chainhook created.
MAINNET headers are updated based on the selected fields used to create a chainhook.
Based on the chosen network, the respective status columns in the Chainhook list page will be updated to Deployed.
Note that there may be other fields in the UI to create a chainhook based on the predicates defined.
Once the chainhook is created, you can edit the chainhook by using the ellipse on the created chainhook row.
You can update the fields and select Update chainhook.
Use the ellipse on the chainhook row to duplicate the chainhook created earlier.
This opens a right pane with all the fields populated to use to create a duplicate chainhook.
You can update the fields or directly select Create chainhook to duplicate a copy of the chainhook.
Use the ellipse on the chainhook row to delete the chainhook. You will see a confirmation window to confirm if you want to delete the chainhook.