Step 5. Create a Rule

Easily create new rules for event handling and management.

❗️

Note

Each call incurs a fixed CU charge, plus additional CUs for API operations. See the Compute Units Usage page for details.

If you have the following items:

, Then you are ready to create a rule to obtain the data you want.

How it works?

Any transactions that meet the conditions specified in the rule will send events directly to you through the webhook target. This can be done using the Rules endpoint.

Request Payload

curl --location 'https://svc.blockdaemon.com/streaming/v2/rules' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--data '{
    "condition": [
        {
            "variable_type": "address", 
            "variable_id": "3c1c1483-d8e0-4ecb-95a0-1e18a5d03244"
        }
    ],
    "description": "Polkadot mainnet rule",
    "is_active": true,
    "name": "Polkadot mainnet rule",
    "network": "mainnet",
    "protocol": "polkadot",
    "target": "8918a2f1-28d6-4e2f-837b-fb49ec09daaf",
    "condition_type": "match_var"
}'

The request body includes the following parameters:

Field

Required/Optional

Description

condition

Required

An array that defines the conditions for the rule. You can reference multiple variable types.

Transactions that meet these conditions are going to the target.

variable_type

Required

Type of the variable in the selected protocol.

You can find it in the supported protocols and networks endpoint.

variable_id

Required

The variable ID within the condition.

Please refer to this page to create a new variable.

is_active

Required

By default, the value is set to true indicating the rule is active. Set to false to temporarily halt the rule to generate any data.

name

Required

Name of the rule. Each resource should have a unique name.

description

Optional

Description of the rule.

network

Required

Specifies the network for which the rule should be applied.
You can check supported protocols and networks here .

protocol

Required

Specifies the protocol for which the rule should be applied.
You can check supported protocols and networks here.

target

Required

The target where the rule will be applied to send data.

Please refer to this page to create a new target.

template

Optional

This is a predefined template other than the Events Unified Format . If no template is provided or if you use the ALL_DATA value, messages will be delivered in their original form.

Please refer to this page to create a custom template.

condition_type

Required

Type of condition used in the rule, in this case: match_var.

Response Payload

A successful request will return the output below.

{
    "condition": [
        {
            "variable_id": "3c1c1483-d8e0-4ecb-95a0-1e18a5d03244",
            "variable_type": "address"
        }
    ],
    "condition_type": "match_var",
    "created_at": "2024-03-06T14:57:10.019668Z",
    "description": "Polkadot mainnet rule",
    "id": "9e2a6c91-18b1-42a4-864b-b3c4efaa5397",
    "is_active": true,
    "name": "Polkadot mainnet rule",
    "network": "mainnet",
    "protocol": "polkadot",
    "safe_distance": 0,
    "safe_timeout": 0,
    "target": "8918a2f1-28d6-4e2f-837b-fb49ec09daaf",
    "template": "ALL_DATA",
    "type": "all",
    "updated_at": "2024-03-06T14:57:10.019668Z"
}

It includes the following details:

Field

Description

condition

An array of the conditions for the rule. Each element is a JSON object referencing a variable_id and variable_type. This array specifies the events to receive based on the variable types and their corresponding IDs.

For example:

  • Events where the address matches the values of the variable with ID 3c1c1483-d8e0-4ecb-95a0-1e18a5d03244 will trigger either a confirmed_tx or a confirmed_balance.
  • Events where the event_type matches the values of the variable with ID 809f936f-21bb-46a9-bab7-fba90b23b10f will trigger a block event.

variable_type

Type of the variable in the selected protocol.

You can find it in the supported protocols and networks endpoint.

variable_id

The variable ID within the condition.

Please refer to this page to create a new variable.

is_active

By default, the value is set to true indicating the rule is active. Set to false to temporarily halt the rule to generate any data.

name

Name of the rule. Each resource should have a unique name.

description

Description of the rule.

network

Specifies the network for which the rule should be applied.

protocol

Specifies the protocol for which the rule should be applied.

target

The target where the rule will be applied to send data.

Please refer to this page to create a new target.

template

This is a predefined template other than the Events Unified Format. If no template is provided or if you use the ALL_DATA value, messages will be delivered in their original form.

Please refer to this page to create a custom template.

condition_type

Type of condition used in the rule, in this case: match_var.

👋 Need Help?

Contact us through email or our support page for any issues, bugs, or assistance you may need.