You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As an early user, I want to share my notes and get any feedback about using Chainhooks.
Chainhooks is the answer to the question, "How do I react to events occurring on the Stacks or Bitcoin chain?"
When you create an app, you create a smart contract that updates the state of the blockchain based on transactions made by users. If I build a smart contract with a token A that I want to swap for token B, I will be sending a transaction where a method of the smart contract will be called, and this method will be taking some tokens from my balance and giving me some other token(s). The state is updated.
If I want to react to these state changes, I need to come up with a solution that observes the blockchain, and poll the state of the chain.
Polling is a bit hard to implement, plus blockchains can fork.
The way the chainhooks layer works, is as a developer I am going to register a predicate that will be evaluated every time a new block is mined. When this predicate appears to be true, then I will be given an alert. Then based on that, I can take some further action.
Predicates can be categorized as any action that takes place on the blockchain, like for Stacks
txid for a specific transaction
ft-events like minting and burning fungible tokens
nft-events like transfer and burning
stx-event like minting or locked for PoX
print-events for contracts that emit print events, or
contract-deploy with either a specific deployer or a trait included.
And/or for monitoring the Bitcoin chain
tx-id
outputs - OP_RETURN output ending with a set of characters, p2pkh payments,
Chainhooks available as a self-hosted solution, as well as Hiro hosted solution in the future.
Some more notes:
Chainhooks is not a websocket Stacks API. The websocket in the API is unfortunately shadowing fork events, which means if your transaction is mined, you will be getting a notification. But if there is a fork, then there would be some issues with consistency
In chainhooks, you receive a payload with two loads, one is "APPLY" with a set of transactions to apply, and "ROLLBACK" that provides tx to rollback if there is a fork.
Stacks blockchain API was meant to index a certain set of data, whereas this Chainhooks layer is designed to help you index your own data.
Right now we have a stateless chainhooks, which means you can only evaluate predicates on blocks being streamed, which makes it available for only new protocols.
@lgalabru is wrapping up stateful version, which gives ability to scan history of chain, and is coming sometime in the next quarter
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
As an early user, I want to share my notes and get any feedback about using Chainhooks.
Chainhooks is the answer to the question, "How do I react to events occurring on the Stacks or Bitcoin chain?"
Here's a list of predicates under the chainhook-node folder
Predicates can be categorized as any action that takes place on the blockchain, like for Stacks
txid
for a specific transactionft-events
like minting and burning fungible tokensnft-events
like transfer and burningstx-event
like minting or locked for PoXprint-events
for contracts that emit print events, orcontract-deploy
with either a specific deployer or a trait included.And/or for monitoring the Bitcoin chain
tx-id
outputs
- OP_RETURN output ending with a set of characters, p2pkh payments,Chainhooks available as a self-hosted solution, as well as Hiro hosted solution in the future.
Some more notes:
Beta Was this translation helpful? Give feedback.
All reactions