Skip to main content

Modifiers, Operators, and Comparators

Updated on
Jun 5, 2023

Overview

Using modifiers, comparators, and operators in QuickAlerts expressions enables users to filter and target specific blockchain events in a highly flexible and precise manner. With the ability to combine multiple tags, operators, and modifiers, QuickAlerts provides a powerful tool for users to monitor and detect important events, transactions, and smart contract interactions that are relevant to them. This flexibility allows users to stay informed and take action quickly, based on the real-time events that are occurring on the blockchain.

Modifiers

These are operators used to modify numeric values, including addition, subtraction, multiplication, division, modulo, bitwise left and right bit shifts, and exponentiation. They can be used to perform complex numeric operations on blockchain data.

Arithmetic + - * / ** %

  • + adds two numeric values together, or concatenates two strings
  • - subtracts one numeric value from another
  • * multiplies two numeric values together
  • / divides one numeric value by another
  • ** raises one numeric value to the power of another
  • % finds the remainder of dividing one numeric value by another
Examples

%: block_number % 1000000 == 0

  • This expression is checking if the block number is divisible by 1000000 without remainder, and if so, the condition is considered true. It uses the modulo operator %, which returns the remainder of dividing the block number by 1000000. If the remainder is 0, then the block number is divisible by 1000000.
  • This expression could be used to trigger an alert every time a block is mined that is a multiple of 1000000. For example, it could be used to alert someone when the Ethereum network reaches a milestone block, such as block number 17,000,000.

**: tx_gasPrice > (1.5**10 * 10**9)

  • This expression uses the ** operator to identify transactions where the gas price is higher than a certain value raised to a power. For instance, let's say a user wants to get notified when the gas price in a transaction is higher than 1.5^10 Gwei (or 15,000,000,000 Gwei) to avoid overspending on gas fees.

Bitwise shifts >> <<

  • >> shifts the bits of a numeric value to the right by a specified number of places
  • << shifts the bits of a numeric value to the left by a specified number of places
Examples

>>: block_difficulty >> 1000000 == 5

  • This expression will trigger a notification if the difficulty of the block is greater than 5 2^1000000. The >> operator performs a bitwise right shift, effectively dividing the left-hand side operand by 2 to the power of the right-hand side operand. In this case, we are shifting the difficulty value to the right by 1000000 bits, which is equivalent to dividing it by 2^1000000. The expression then checks if the result is equal to 5, indicating that the difficulty is greater than 5 2^1000000.
  • This expression might be useful for miners or others interested in tracking blocks with particularly high difficulty levels.

<<: (tx_gasPrice << 1) > tx_maxFeePerGas

  • This expression will check if the gas price specified in the transaction is greater than twice the max fee per gas specified in the same transaction. If this condition is met, it might indicate that the transaction sender is willing to pay a higher gas price than necessary, possibly indicating a high priority or urgency for the transaction.
  • This might be useful to detect for users who want to keep track of high-priority or urgent transactions on the blockchain.

Inversion ! ~

  • ! negates the boolean value of a condition, turning true into false and vice versa
  • ~ inverts the bits of a numeric value
Example

!: !(tx_value < 100**18 && tx_gasPrice > 10**9)

  • This QuickAlerts expression targets transactions where the value being sent is greater than 100 ETH (1 ETH = 10^18 Wei) and the gas price is less than 10 Gwei (1 Gwei = 10^9 Wei). The ! inversion operator is used to negate the logical AND && operator, so the expression will evaluate to true when either condition is false.
  • This expression could be useful for detecting large transactions with relatively low gas prices, which may indicate an opportunity for arbitrage or other types of trading strategies.

Logical Operators

These are operators used to perform logical operations, and can be used to combine multiple conditions and create more complex expressions.

Logical AND/OR && ||

  • && checks if both conditions on the left and right sides of the operator are true
  • || checks if at least one condition on the left or right side of the operator is true

Comparators

These are operators used to compare values, including greater than, greater than or equal to, less than, less than or equal to, equal to, and not equal to. They can be used to check whether a certain value meets a specific condition.

Comparators > < >= <= == !=

  • > checks if the left value is greater than the right value
  • < checks if the left value is less than the right value
  • <= checks if the left value is less than or equal to the right value
  • >= checks if the left value is greater than or equal to the right value
  • == checks if two values are equal
  • != checks if two values are not equal

Regex comparators =~ !~

The left side contains the candidate string, and the right side is the pattern. =~ returns whether or not the candidate string matches the regex pattern given on the right. !~ is the inverted version of the same logic.

Examples

=~: (tx_input =~ '0xa9059cbb[a-fA-F0-9]{64}')

  • This example QuickAlerts expression uses the =~ regex comparator to detect a specific pattern in the tx_input field. '0xa9059cbb[a-fA-F0-9]{64}' is a regular expression pattern that matches the hexadecimal representation of the transfer function of an ERC-20 token, followed by a 64-character hexadecimal string representing the recipient address. This expression will trigger a notification whenever a transaction is mined that calls the transfer function of an ERC-20 token and includes a recipient address in the input data.`
  • You can also use =~ to compare whether or not a field contains a value. For instance, (tx_input =~ '59cbb') would trigger an alert whenever the string '59cbb' appears anywhere in the tx_input field.
  • The regex pattern "0xa9059cbb[a-fA-F0-9]{64}" follows the standard regular expression syntax, where [a-fA-F0-9] means any hexadecimal character and {64} means the preceding pattern should match 64 times. This pattern is commonly used to match the function signature of the ERC-20 transfer function in Ethereum smart contracts.

Other

  • , separator, always paired with parenthesis, creates arrays
  • () groups expressions together to control the order of evaluation
  • in checks the right-hand side array to see if it contains a value that is equal to the left-side value
Example
  • (tx_to in ('0x7a250d5630b4cf539739df2c5dacb4c659f2488d', '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48'))
  • This expression would trigger a notification if a transaction is sent to any of the three addresses listed in the array.
Share this doc