Skip to content

Commit ff3b8e8

Browse files
authored
Merge pull request #730 from hirosystems/max-crawford-patch-2
Update observing-contract-calls.mdx
2 parents 1872531 + 3fb5caa commit ff3b8e8

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

content/docs/stacks/chainhook/guides/observing-contract-calls.mdx

+15-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Observing Contract Calls with Chainhook
2+
title: Observing contract calls with Chainhook
33
description: Learn how to use Chainhook to observe a function call for a voting contract.
44
---
55

@@ -29,7 +29,7 @@ In this guide, you will learn how to:
2929

3030
## Create the predicate
3131

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.
3333

3434
For the Stacks blockchain, run the following command to generate a `predicate` template:
3535

@@ -92,7 +92,7 @@ The `contract_call` scope allows Chainhook to observe blockchain data when the s
9292
```
9393

9494
<Callout type="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.
9696
```clarity
9797
(define-public (call-cast-vote)
9898
(cast-vote)
@@ -105,7 +105,7 @@ Finally, define how Chainhook delivers the payload when it is triggered by your
105105
1. `file_append`
106106
2. `http_post`
107107

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.
109109

110110
```json title="contract-call-chainhook.json"
111111
// [!code word:file_append]
@@ -188,7 +188,7 @@ chainhook predicates scan /path/to/contract-call-chainhook.json --testnet
188188
</Step>
189189
<Step>
190190

191-
## Return contract data with the clarity function
191+
## Return contract data with the Clarity function
192192

193193
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.
194194

@@ -244,12 +244,12 @@ Within the `apply` arrays element, the `block_identifer` object gives us the `in
244244
<Callout type="warn" title="Warning">
245245
The hash returned in the `block_identifer` object is not that block hash you
246246
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
248248
block](/stacks/api/blocks/get-block) endpoint. You can use the `apply` array's
249249
metadata object to get the `stacks_block_hash`.
250250
</Callout>
251251

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.
253253

254254
```json title="contract-call-payload.json"
255255
// [!code word:stacks_block_hash]
@@ -262,22 +262,24 @@ We can retrieve the `stacks_block_hash` by navigating to the the `apply` arrays
262262
]
263263
```
264264

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.
266266

267267
```json title="contract-call-payload.json"
268268
"timestamp": 1722208524
269269
```
270270

271271
<Callout type="warn" title="Warning">
272272
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
275275
block](/stacks/api/blocks/get-block) endpoint.
276276
</Callout>
277277

278278
### Transaction object
279279

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.
281283

282284
```json
283285
{
@@ -297,7 +299,7 @@ Because Chainhook is triggered on the block level, we will receive a single resp
297299
}
298300
```
299301

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.
301303

302304
```json title="contract-call-payload.json"
303305
"transaction_identifier": {
@@ -319,7 +321,7 @@ Utilize the `success` object to assess transaction success and extract the `send
319321

320322
Moving forward, examine the `kind` object and its components within your `contract_call`. The data object contains crucial information:
321323

322-
- `contract_identifier` specifies the contract your function resides on
324+
- `contract_identifier` specifies the contract your function resides in
323325
- `method` identifies the function called
324326
- `args` lists the arguments passed when invoking this function
325327

0 commit comments

Comments
 (0)