Stacks predicates

A list of predicates for using Chainhook with Stacks. The predicates are specified based on if-this, and then-that constructs.

if_this specifications

Get any transaction matching a given transaction ID, txid.

{
  "if_this": {
    "scope": "txid",
    "equals": "0xfaaac1833dc4883e7ec28f61e35b41f896c395f8d288b1a177155de2abd6052f"
  }
}

The txid mandatory argument requires a 32-byte hex-encoded type.


Get any Stacks block based on matching constraints.

{
  "if_this": {
    "scope": "block_height",
    "equals": 154100
  }
}

The block_height argument admits: equals, higher_than, lower_than, between.

The between operator can be used by providing an array with two values:

{
  "if_this": {
    "scope": "block_height",
    "between": [0, 1000]
  }
}

Get any transaction related to a given fungible token asset identifier:

{
  "if_this": {
    "scope": "ft_event",
    "asset_identifier": "ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.cbtc-token::cbtc",
    "actions": ["burn"]
  }
}

The asset_identifier argument admits an asset identifier to observe, for example: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.cbtc-sip10::cbtc.

The actions argument admits an array of string types constrained to mint, transfer, and burn values, such as ["mint", "burn"].


Get any transaction related to a given non-fungible token asset identifier.

The asset-identifier argument is mandatory and requires a string type that fully qualifies the asset identifier to observe, for example: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.monkey-sip09::monkeys.

The actions argument is also mandatory and accepts an array of string types limited to the values mint, transfer, and burn, such as ["mint", "burn"].

{
  "if_this": {
    "scope": "nft_event",
    "asset_identifier": "ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.monkey-sip09::monkeys",
    "actions": ["mint", "transfer", "burn"]
  }
}

Get any transaction moving STX tokens.

The actions argument is mandatory and accepts an array of string types limited to the values mint, transfer, burn, and lock, such as ["mint", "lock"].

{
  "if_this": {
    "scope": "stx_event",
    "actions": ["transfer", "lock"]
  }
}

Get any transaction emitting a given print events predicate.

The contract-identifier is a mandatory argument that requires a string type, fully qualifying the contract to observe, for example: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.monkey-sip09.

Additionally, you must include either the contains or matches_regex argument:

  • The contains argument accepts a string type, used for matching an event that contains the specified string, for example vault.
  • The matches_regex argument accepts a string type that should be a valid regex, used for matching an event that regex matches with the specified string, such as (?:^|\\W)vault(?:$|\\W).

The following example uses contains argument:

{
  "if_this": {
    "scope": "print_event",
    "contract_identifier": "ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.monkey-sip09",
    "contains": "vault"
  }
}

The following example uses matches_regex argument:

{
  "if_this": {
    "scope": "print_event",
    "contract_identifier": "ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.monkey-sip09",
    "matches_regex": "(?:^|\\W)vault(?:$|\\W)"
  }
}

Get any transaction calling a specific method for a given contract directly.

If the observed method is being called by another contract, this predicate won't detect it.

The contract-identifier is a mandatory argument that requires a string type, fully qualifying the contract to observe, for example SP000000000000000000002Q6VF78.pox.

The method is also a mandatory argument that accepts a string type, used for specifying the method to observe, such as stack-stx.

{
  "if_this": {
    "scope": "contract_call",
    "contract_identifier": "SP000000000000000000002Q6VF78.pox",
    "method": "stack-stx"
  }
}

Get any transaction, including a contract deployment.

The deployer argument is mandatory and accepts a string representing a valid STX address, for example "ST2CY5V39NHDPWSXMW9QDT3HC3GD6Q6XX4CFRK9AG".

{
  "if_this": {
    "scope": "contract_deployment",
    "deployer": "ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM"
  }
}

then_that specifications

HTTP Post block/transaction payload to a given endpoint.

The http_post construct requires a url of type string (for example, http://localhost:3000/api/v1/wrapBtc) and an authorization_header of type string, which is a secret added to the request's authorization header.

{
  "then_that": {
    "http_post": {
      "url": "http://localhost:3000/api/v1/wrapBtc",
      "authorization_header": "Bearer cn389ncoiwuencr"
    }
  }
}

Append events to a file through the filesystem, which is convenient for local tests.

The file_append construct requires a path parameter, which is a string representing the file path on the disk.

{
  "then_that": {
    "file_append": {
      "path": "/tmp/events.json"
    }
  }
}

Additional configurations available

The following additional configurations can be used to improve the performance of chainhook by preventing a full scan of the blockchain:

Ignore any block before the given block:

"start_block": 101

Ignore any block after the given block:

"end_block": 201

Stop evaluating chainhook after a given number of occurrences found:

"expire_after_occurrence": 1

Include decoded Clarity values in the payload:

"decode_clarity_values": true

Include the contract ABI for transactions that deploy contracts:

"include_contract_abi": true