Custom Webhook Variables

Understand how Custom Webhook variables work and how to use them

With GraphQL, Alchemy’s Custom Webhook is able to leverage the power of variables to dynamically insert values into a webhook query. In particular, users are able to filter data based on both addresses and log topics via Custom Webhook variables!

To use a variable, you must first create it using one of the Custom Webhook API methods that allow you to create, read, update, and destroy Custom Webhook variables!

Variable Types

Custom Webhook variables can either be a set of addresses or bytes32 objects. This allows developers to either define variables for transaction level filters or logs!

Example Address Typed Variables

Variable Name:addressVariable

Variable Value: {0x5c43B1eD97e52d009611D89b74fA829FE4ac56b1, 0x95222290DD7278Aa3Ddd389Cc1E1d165CC4BAfe5, 0x388C818CA8B9251b393131C08a736A67ccB19297 }

Address typed variables can be used in either [external transaction filters](External Transaction Filters) and/or internal transaction filters.

Example Log Topic Typed Variables

Variable Name:logTopicVariable

Variable Value: {0xe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c, 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef, 0xd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d822 }

Log Topic typed variables can be used in only event log filters!

Log Topic typed variables can represent an array of topic0, topic1, or topic2 elements.

How to Use Variables in Custom Webhooks

At the beginning of each GraphQL query where you want to use a variable, you must declare the variable!

query ($addressVariable: [Address!])

query ($addressVariable: [Address!], $logTopicVariable:[Bytes32!]!)

Examples Using A Variable:

Single Variable Custom Webhooks

In this example, we use a variable addressVar which is applied to an external transaction filter, specifically within the from address parameter.

1query ($addressVar: [Address!]) {
2 block {
3 hash
4 number
5 transactions(filter: {addresses: [{from: $addressVar }]}) {
6 hash
7 from {
8 address
9 }
10 to {
11 address
12 }
13 value
14 gas
15 status
16 logs {
17 data
18 topics
19 }
20 }
21 }
22}

Multi-Variable Custom Webhooks

In this example, we use 2 variables addressVar AND logTopic0 with the former being used in an external transaction filter and the former being applied to the event log filter.

1query ($addressVar: [Address!], $logTopic0:[Bytes32!]!) {
2 block {
3 hash
4 number
5 transactions(filter: {addresses: [{to: $addressVar }]}) {
6 hash
7 from {
8 address
9 }
10 to {
11 address
12 }
13 value
14 gas
15 status
16 logs {
17 data
18 topics
19 }
20 }
21 logs(filter: { addresses: [], topics: [$logTopic0, [],[]] }) {
22 topics
23 transaction{
24 hash
25 from {
26 address
27 }
28 to {
29 address
30 }
31 value
32 gas
33 status
34 }
35 }
36 }
37}

FAQ

How many elements can I use within a Custom Webhook variable?

Each Custom Webhook variable can contain up to 10 million elements by default!