Filter Streams

Filter Streams

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']}
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']}

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) 
        },
      ],
    },
  ],
}