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
Copy file name to clipboardExpand all lines: content/docs/stacks/chainhook/guides/observing-contract-calls.mdx
+15-13
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
---
2
-
title: Observing Contract Calls with Chainhook
2
+
title: Observing contract calls with Chainhook
3
3
description: Learn how to use Chainhook to observe a function call for a voting contract.
4
4
---
5
5
@@ -29,7 +29,7 @@ In this guide, you will learn how to:
29
29
30
30
## Create the predicate
31
31
32
-
The `predicate` is your main interface for querying the Chainhook data indexer. Chainhook uses this to select the appropriate blockchain, network, and scope for monitoring transactions.
32
+
The `predicate` is your main interface for querying the Chainhook data indexer. Chainhook uses this predicate to select the appropriate blockchain, network, and scope for monitoring transactions.
33
33
34
34
For the Stacks blockchain, run the following command to generate a `predicate` template:
35
35
@@ -92,7 +92,7 @@ The `contract_call` scope allows Chainhook to observe blockchain data when the s
92
92
```
93
93
94
94
<Callouttype="warn"title="Warning">
95
-
The function defined in the `method` property of your `predicate` must be directly called for Chainhook to observe events. Calling the function from another contract or from within a different function on the same contract will not generate a `payload`. Below is an example of a `cast-vote` function that would not trigger an event.
95
+
The function defined in the `method` property of your `predicate` must be directly called in order for Chainhook to observe events. Calling the function from another contract or from within a different function on the same contract will not generate a `payload`. Below is an example of a `cast-vote` function that would not trigger an event.
96
96
```clarity
97
97
(define-public (call-cast-vote)
98
98
(cast-vote)
@@ -105,7 +105,7 @@ Finally, define how Chainhook delivers the payload when it is triggered by your
105
105
1.`file_append`
106
106
2.`http_post`
107
107
108
-
When choosing to use file_append, specify the path where Chainhook will post the payload data.
108
+
When choosing to use `file_append`, specify the path where Chainhook will post the payload data.
The `cast-vote` function records a vote by storing the address that calls it. It also logs relevant data using the `print` function, which can be useful for when you want to track additional on-chain events that are not part of the built-in Clarity functions.
194
194
@@ -244,12 +244,12 @@ Within the `apply` arrays element, the `block_identifer` object gives us the `in
244
244
<Callouttype="warn"title="Warning">
245
245
The hash returned in the `block_identifer` object is not that block hash you
246
246
would see in [Stacks Explorer](https://explorer.hiro.so/?chain=testnet), but
247
-
`index_block_hash` returned from the Stacks API [get
247
+
`index_block_hash` returned from the Stacks API's[get
248
248
block](/stacks/api/blocks/get-block) endpoint. You can use the `apply` array's
249
249
metadata object to get the `stacks_block_hash`.
250
250
</Callout>
251
251
252
-
We can retrieve the `stacks_block_hash` by navigating to the the `apply` arrays object `metadata` element. This hash will match the block hash display in the Stacks Explorer.
252
+
We can retrieve the `stacks_block_hash` by navigating to the `apply` arrays object `metadata` element. This hash will match the block hash display in the Stacks Explorer.
253
253
254
254
```json title="contract-call-payload.json"
255
255
// [!code word:stacks_block_hash]
@@ -262,22 +262,24 @@ We can retrieve the `stacks_block_hash` by navigating to the the `apply` arrays
262
262
]
263
263
```
264
264
265
-
There is also also a `timestamp` value returned in the `apply` array. This UNIX time stamp represents the initiation of the Stacks block.
265
+
There is also a `timestamp` value returned in the `apply` array. This UNIX time stamp represents the initiation of the Stacks block.
266
266
267
267
```json title="contract-call-payload.json"
268
268
"timestamp": 1722208524
269
269
```
270
270
271
271
<Callouttype="warn"title="Warning">
272
272
The timestamp returned in this object is not the finalized block time you
273
-
would see in [Stacks Explorer](https://explorer.hiro.so/?chain=testnet), but
274
-
`block_time` returned from the Stacks API [get
273
+
would see in the [Stacks Explorer](https://explorer.hiro.so/?chain=testnet), but
274
+
`block_time` returned from the Stacks API's[get
275
275
block](/stacks/api/blocks/get-block) endpoint.
276
276
</Callout>
277
277
278
278
### Transaction object
279
279
280
-
Because Chainhook is triggered on the block level, we will receive a single response that contains data specific to each `transaction` that matches your predicate's `contract_call` scope. To find this data, we start with the `apply` array element of the `payload` object. The single object that makes up the `apply` array contains a child element, the `transactions` array. Every `transaction` will be represents by a single object within this array. This `transaction` object contains its own children elements which can be seen in the example below.
280
+
Because Chainhook is triggered on the block level, we will receive a single response that contains data specific to each `transaction` that matches your predicate's `contract_call` scope.
281
+
282
+
To find this data, we start with the `apply` array element of the `payload` object. The single object that makes up the `apply` array contains a child element, the `transactions` array. Every `transaction` will be represents by a single object within this array. This `transaction` object contains its own children elements which can be seen in the example below.
281
283
282
284
```json
283
285
{
@@ -297,7 +299,7 @@ Because Chainhook is triggered on the block level, we will receive a single resp
297
299
}
298
300
```
299
301
300
-
Once the `transaction` object is returned, we can begin examining important data elements it contains. The first element, `transaction_identifier`, includes a hash value that uniquely identifies your transaction.
302
+
Once the `transaction` object is returned, we can begin examining the important data elements this object contains. The first element, `transaction_identifier`, includes a hash value that uniquely identifies your transaction.
301
303
302
304
```json title="contract-call-payload.json"
303
305
"transaction_identifier": {
@@ -319,7 +321,7 @@ Utilize the `success` object to assess transaction success and extract the `send
319
321
320
322
Moving forward, examine the `kind` object and its components within your `contract_call`. The data object contains crucial information:
321
323
322
-
-`contract_identifier` specifies the contract your function resides on
324
+
-`contract_identifier` specifies the contract your function resides in
323
325
-`method` identifies the function called
324
326
-`args` lists the arguments passed when invoking this function
0 commit comments