> ## Documentation Index
> Fetch the complete documentation index at: https://docs.blocklight.co/llms.txt
> Use this file to discover all available pages before exploring further.

# Operators & Functions

> Operators and functions for building conditions

Combine conditions using these operators and functions.

## 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](/rules/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`                 |

<Note>
  **String Comparisons:** All string comparisons are case-insensitive for addresses and hex values.
</Note>

## Array Methods

When working with arrays (`tx.logs`), use chained methods:

* `.any(condition)` - Check if any element matches
* `.count(condition)` - Count elements matching condition

See [Array Methods](/rules/array-methods) for complete documentation.

## Examples

### Combining Operators

```yaml theme={null}
# Multiple conditions with AND
condition: >
  tx.value > 100 ether and
  tx.to in (monitored_addresses) and
  tx.status == 1

# OR conditions
condition: >
  tx.from == "0x..." or
  tx.to == "0x..."

# NOT condition
condition: >
  not tx.from in (whitelist)

# Function selector check
condition: >
  startswith(tx.input, "0xa9059cbb") and
  tx.value > 0
```

### Using with Arrays

```yaml theme={null}
# Array method with other conditions
condition: >
  tx.logs.any(event_name == "Transfer") and
  tx.value > 100 ether

# Count with comparison
condition: >
  tx.logs.count(event_name == "Transfer" and from != "") > 10 and
  tx.gas_used > 1000000
```

## Next Steps

<CardGroup cols={2}>
  <Card title="Fields" icon="file-lines" href="/rules/fields">
    Essential transaction fields
  </Card>

  <Card title="Array Methods" icon="list" href="/rules/array-methods">
    Working with logs, transfers, and approvals
  </Card>

  <Card title="Macros & Lists" icon="brackets-curly" href="/rules/macros">
    Reusable conditions and address lists
  </Card>

  <Card title="Examples" icon="code" href="/rules/examples">
    Real-world detection rules
  </Card>
</CardGroup>
