Skip to main content
Version: 2.2

Filters

In some cases you might want to filter the data you receive from the webhook. You can do this by adding a filter to the stream.

FilterFunctionNoteExampleDemo
oreither ... or ...Need at least 2 filters{ "or" : [ {..filter1}, {...filter2} ]}Monitor for Burn/Mint Tokens
andall filters must satisfyNeed at least 2 filters{ "and" : [ {..filter1}, {...filter2} ]}Monitor ENS Name Registrations
eqchecks for equality{ "eq": ["value", "1000"] }
nechecks for inequality{ "ne": ["address", "0x...325"] }
ltvalue is less thanValue must be a number{ "lt": ["amount", "50"] }
gtvalue is greater thanValue must be a number{ "gt": ["price", "500000"] }
ltevalue is less than or equal toValue must be a number{ "lte": ["value", "100"] }
gtevalue is greater than or equal toValue must be a number{ "gte": ["value", "100"] }Monitor for Burn/Mint Tokens
invalue is in arrayMust provide an array{ "in": ["city": ["berlin", "paris"]]}Monitor specific NFTs
ninvalue is not in arrayMust provide an array{ "nin": ["name": ["bob", "alice"]]}

In some cases you might want to filter the data you receive from the webhook. You can do this by adding a filter to the stream. Important: You must add a (valid!) ABI of the event you want to filter! Otherwise the stream will not work.

Special variables that can be used in a filter

  • moralis_streams_contract_address - for identifying current contract address that emits an event, example {eq: ['moralis_streams_contract_address', '0x0000000000000000000000000000000000000000']} (note: the address has to be in lowercase)
  • moralis_streams_chain_id - for identifying current chain for current event, example {eq: ['moralis_streams_chain_id', '0x1']}
  • moralis_streams_possibleSpam - for filtering on possibleSpam (read more about possibleSpam here) events, example {eq: [moralis_streams_possibleSpam: "false"]} to filter out events that are possible spam
Special VariableInfoExample
moralis_streams_contract_addressFor identifying current contract address that emits an event (note: the address has to be in lowercase){eq: ['moralis_streams_contract_address', '0x0000000000000000000000000000000000000000']}
moralis_streams_chain_idFor identifying current chain for current event{eq: ['moralis_streams_chain_id', '0x1']}
moralis_streams_possibleSpamFor filtering on possibleSpam (read more about possibleSpam here) events{eq: [moralis_streams_possibleSpam: "false"]}

Here is an example of applying different filters for different contract addresses

moralis_streams_contract_address variable name can be used to identify current contract address that emits current event

Note: the address is in lowercase

Example:

const filter = {
or: [
{
and: [
{
eq: ["moralis_streams_contract_address", "0x1"],
},
{
gte: ["value", 1000000000], // Example of USDT (6 Decimals)
},
],
},
{
and: [
{
eq: ["moralis_streams_contract_address", "0x2"],
},
{
gte: ["value", 1000000000000000000000], // Example of BUSD (18 Decimals)
},
],
},
],
};

Steps to add filter via Admin panel

  1. Go to streams page, add contract address(eg:USDC - 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48) to create a stream, add the following ABI and select Transfer(address,address,uint256) topic.
[
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "from",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "to",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "value",
"type": "uint256"
}
],
"name": "Transfer",
"type": "event"
}
]

Your screen will look like below::

  1. Let's create the following filter example with UI: This will filter all transfers with value greater than 5000 USDC and less than 50000 USDC.
{
"and": [{ "gt": ["value", "5000000000"] }, { "lt": ["value", "50000000000"] }]
}

decimals on USDC contract is 6

  • 5000 USDC value will be 5000000000
  • 50000 USDC value will be 50000000000
  1. Click on Select topic to filter and add your topic.

  2. Click on Choose variable and select value from the list

  3. Replace Equal with Greater than and Enter 5000000000 in the input field

  4. Click on Add filter and select Less than filter from the list.

  5. Click on Choose variable and select value from the list and Enter 50000000000 in the input field

  6. Click on Or and replace it with And

  7. Now click on Update and you have successfully added your filter.

Steps to add complex filters using Admin Panel

  1. Go to streams page, add contract address(eg:USDC - 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48) to create a stream, add the following ABI and select Transfer(address,address,uint256) topic.
[
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "from",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "to",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "value",
"type": "uint256"
}
],
"name": "Transfer",
"type": "event"
}
]

Your screen will look like below::

  1. Let's create the following filter example with UI: This will filter all transfers where the from or the to is the zero address and the amount is greater or equal to 10000 USDC.
{
"or": [
{
"and": [
{ "eq": ["from", "0x0000000000000000000000000000000000000000"] },
{ "gte": ["value", "10000000000"] }
]
},
{
"and": [
{ "eq": ["to", "0x0000000000000000000000000000000000000000"] },
{ "gte": ["value", "10000000000"] }
]
}
]
}
  • A zero address(0x0000000000000000000000000000000000000000) in from equals to Mint and in to equals to burn.

  • decimals in USDC contract is 6

    • 10000 USDC value will be 10000000000
  1. Click on Select topic to filter and add your topic.

  2. Click on the delete icon.

  3. Click on Add filter and select And filter from the list.

  4. Click on Choose variable and select from from the list and enter 0x0000000000000000000000000000000000000000 in the input field.

  5. Click on the inner Add filter and select Greater than and equal to filter from the list.

  6. Click on Choose variable and select value from the list and enter 10000000000 in the input field.

  7. Now click on the outer Add filter and select And filter from the list.

  8. Click on Choose variable and select to from the list and enter 0x0000000000000000000000000000000000000000 in the input field.

  9. Click on the inner Add filter and select Greater than and equal to filter from the list.

  10. Click on Choose variable and select value from the list and enter 10000000000 in the input field.

  11. Now click on Update and you have successfully added your filter.