Comparison Operators
| Operator | Description | Example |
|---|---|---|
== | Equal | tx.value == 0 |
!= | Not equal | tx.to != null |
> / >= | Greater than (or equal) | tx.value > 100 ether |
< / <= | Less than (or equal) | tx.gas < 21000 |
and | Logical AND | tx.value > 0 and tx.to != null |
or | Logical OR | tx.value == 0 or tx.gas > 1000000 |
not | Logical NOT | not tx.from in (whitelist) |
in | Membership (see Lists & Macros) | tx.to in (known_dex_routers) |
String Functions
Use these functions for string matching and manipulation.| Function | Description | Example |
|---|---|---|
contains(field, "text") | Check if field contains text | contains(tx.to, "0x742d") |
startswith(field, "prefix") | Check if field starts with prefix | startswith(tx.input, "0xa9059cbb") |
endswith(field, "suffix") | Check if field ends with suffix | endswith(tx.to, "abcd") |
matches(field, "regex") | Check if field matches regex pattern | matches(tx.hash, "^0x[a-f0-9]{64}$") |
len(field) | Get length of field | len(tx.input) > 1000 |
String Comparisons: All string comparisons are case-insensitive for addresses and hex values.
Array Methods
When working with arrays (tx.logs), use chained methods:
.any(condition)- Check if any element matches.count(condition)- Count elements matching condition
Examples
Combining Operators
Using with Arrays
Next Steps
Fields
Essential transaction fields
Array Methods
Working with logs, transfers, and approvals
Macros & Lists
Reusable conditions and address lists
Examples
Real-world detection rules