Step 5. Create a Rule

Easily create new rules for event handling and management.

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" }, 
          {"variable_type":"event_type", "variable_id":"809f936f-21bb-46a9-bab7-fba90b23b10f"}
        ],
        "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:

FieldRequired/OptionalDescription
conditionRequiredAn 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_typeRequiredType of the variable in the selected protocol.

You can find it in the supported protocols and networks endpoint.
variable_idRequiredThe variable ID within the condition.

Please refer to this page to create a new variable.
is_activeRequiredBy default, the value is set to true indicating the rule is active. Set to false to temporarily halt the rule to generate any data.
nameRequiredName of the rule. Each resource should have a unique name.
descriptionOptionalDescription of the rule.
networkRequiredSpecifies the network for which the rule should be applied.
You can check supported protocols and networks here .
protocolRequiredSpecifies the protocol for which the rule should be applied.
You can check supported protocols and networks [here (https://docs.blockdaemon.com/reference/get-supported-protocols-and-networks).
targetRequiredThe target where the rule will be applied to send data.

Please refer to this page to create a new target.
templateOptionalThe template name you use to filter out the eveYou'llu'll receive the messages in their original s when no template is providedtate.

Please refer to this page to create a template.
condition_typeRequiredType 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"
        },
        {
            "variable_id": "809f936f-21bb-46a9-bab7-fba90b23b10f",
            "variable_type": "event_type"
        }
    ],
    "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": "UNIFIED_V1",
    "type": "all",
    "updated_at": "2024-03-06T14:57:10.019668Z"
}

It includes the following details:

FieldDescription
conditionAn 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_typeType of the variable in the selected protocol.

You can find it in the supported protocols and networks endpoint.
variable_idThe variable ID within the condition.

Please refer to this page to create a new variable.
is_activeBy default, the value is set to true indicating the rule is active. Set to false to temporarily halt the rule to generate any data.
nameName of the rule. Each resource should have a unique name.
descriptionDescription of the rule.
networkSpecifies the network for which the rule should be applied.
protocolSpecifies the protocol for which the rule should be applied.
targetThe target where the rule will be applied to send data.

Please refer to this page to create a new target.
templateThe template name you use to filter out the eveYou'llu'll receive the messages in their original s when no template is provided.

Please refer to this page to create a template.
condition_typeType 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.