Step 5. Create a Rule
Easily create new rules for event handling and management.
NoteEach call incurs a fixed CU charge, plus additional CUs for API operations. See the Compute Units Usage page for details.
Create a Rule
If you have the following items:
- ✅ Webhook target that has undergone a verification process.
- ✅ Variable(s) with values.
, 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 |
---|---|---|
| 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. |
| Required | Type of the variable in the selected protocol. You can find it in the supported protocols and networks endpoint. |
| Required | The variable ID within the condition. Please refer to this page to create a new variable. |
| Required | By default, the value is set to |
| Required | Name of the rule. Each resource should have a unique name. |
| Optional | Description of the rule. |
| Required | Specifies the network for which the rule should be applied. |
| Required | Specifies the protocol for which the rule should be applied. |
| Required | The target where the rule will be applied to send data. Please refer to this page to create a new target. |
| Optional | This is a predefined template other than the Events Unified Format . If no template is provided or if you use the Please refer to this page to create a custom template. |
| Required | Type of condition used in the rule, in this case: |
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 |
---|---|
| An array of the conditions for the rule. Each element is a JSON object referencing a For example:
|
| Type of the variable in the selected protocol. You can find it in the supported protocols and networks endpoint. |
| The variable ID within the condition. Please refer to this page to create a new variable. |
| By default, the value is set to |
| Name of the rule. Each resource should have a unique name. |
| Description of the rule. |
| Specifies the network for which the rule should be applied. |
| Specifies the protocol for which the rule should be applied. |
| The target where the rule will be applied to send data. Please refer to this page to create a new target. |
| This is a predefined template other than the Events Unified Format. If no template is provided or if you use the Please refer to this page to create a custom template. |
| Type of condition used in the rule, in this case: |
Managing Rule
Update an existing rule by replacing it with a new configuration.
NoteA rule must include the chain protocol and network to specify the data to stream, one or more variable-based conditions** to filter relevant events, a target ID that determines where the matched data will be sent, and a template that defines the structure of the streamed payload.
Example Payload
curl --request PUT \
--url https://svc.blockdaemon.com/streaming/v2/rules/{RULE_ID} \
--header 'accept: application/json' \
--header 'authorization: Bearer YOUR_API_KEY' \
--header 'content-type: application/json' \
--data '
{
"name": "Ethereum mainnet demo",
"description": "Ethereum mainnet demo",
"protocol": "ethereum",
"network": "mainnet",
"type": "all",
"isActive": true,
"safeDistance": 0,
"safeTimeout": 0,
"condition_type": "match_var",
"condition": [
{
"variable_type": "source-address",
"variable_id": "<VARIABLE_ID>"
},
{
"variable_type": "destination-address",
"variable_id": "<VARIABLE_ID>"
}
],
"target": "<TARGET_ID>",
"template": "ALL_DATA",
"id": "<RULE_ID>",
"created_at": "2024-02-05T13:29:23.2179Z"
}
'
{
"condition": [
{
"variable_id": "<VARIABLE_ID>",
"variable_type": "source-address"
},
{
"variable_id": "<VARIABLE_ID>",
"variable_type": "destination-address"
}
],
"condition_type": "match_var",
"created_at": "2024-02-05T13:29:23.2179Z",
"description": "Updated desc Ethereum mainnet demo",
"id": "<RULE_ID>",
"isActive": true,
"name": "Ethereum mainnet demo",
"network": "mainnet",
"protocol": "ethereum",
"safeDistance": 0,
"safeTimeout": 0,
"target": "<TARGET_ID>",
"template": "ALL_DATA",
"type": "all",
"updated_at": "2024-02-05T13:41:12.271366Z"
}
Delete a rule by its ID and this action can't be undone, as it stops all event delivery.
Example Payload
curl --request DELETE \
--url https://svc.blockdaemon.com/streaming/v2/rules/{RULE_ID} \
--header 'accept: application/json' \
--header 'authorization: Bearer YOUR_API_KEY'
The status code "204 - No Content" indicates that the request was successful and the rule was deleted.
👋 Need Help?
Contact us through email or our support page for any issues, bugs, or assistance you may need.
Updated 26 days ago