# Wallet rules `wallet`

- Section: Webhooks (TTF API reference)
- Source: https://ttf.bot/developers/docs/#webhook-wallet
- The whole reference as one text: https://ttf.bot/developers/docs/llms-full.txt

`POST` to your endpoint, with the header `X-TTF-Event: wallet`.

Rule types: `wallet_activity`

Sent when a `wallet_activity` rule fired on a `wallet` event.

## Delivery rules

TTF sends an HTTPS POST with a JSON body to your endpoint when a rule fires (and when you press Test in the dashboard). Answer any 2xx within 10 seconds (queue the work on your side); anything else, a timeout or a redirect is retried after 1 min, 5 min, 30 min, 2 h and 12 h. Delivery is AT LEAST ONCE: dedupe on X-TTF-Delivery (= body.id). Deliveries are not ordered: order by created_ms / event.ts. Verify X-TTF-Signature over the RAW body before you trust it. Deliveries come from changing proxy addresses: never allowlist IPs, verify the signature.

## Headers

| Header | Type | Meaning | Example |
| --- | --- | --- | --- |
| `X-TTF-Event` | string | The event type of the body's `event`: price, trending, wallet, signal or ping. | `wallet` |
| `X-TTF-Event-Id` | string | The event id (a ULID). One event can fire several of your rules: each is its own delivery. | `01JDZ8Q7X3M4N5P6Q7R8S9T0WC` |
| `X-TTF-Delivery` | string | The delivery id (a ULID) = body.id, THE SAME on every retry and re-send: drop duplicates on it. | `01JDR4Q7Z2N8M5K3X9V6B4C2HA` |
| `X-TTF-Attempt` | integer | 1 for the first try, then 2, 3, ... (at most 6 attempts over about 15 hours). | `1` |
| `X-TTF-Timestamp` | integer | Unix SECONDS when this attempt was signed (every retry is signed afresh). Refuse it when more than 300 s away from your clock (replay window). | `1795000000` |
| `X-TTF-Signature` | string | v1=\<hex>: HMAC-SHA256(key = your endpoint secret "whsec_...", message = X-TTF-Timestamp + "." + the raw body bytes), lower-case hex. During the 24 h after a secret rotation: "v1=\<new>,v1=\<old>". Compare in constant time; accept if any value matches. | `v1=0000000000000000000000000000000000000000000000000000000000000000` |
| `User-Agent` | string | Always TTF-Webhooks/1.0. | `TTF-Webhooks/1.0` |

## Signature

| Field | Value |
| --- | --- |
| algorithm | HMAC-SHA256 |
| format | v1=\<64 lower-case hex>[,v1=\<hex>] |
| header | X-TTF-Signature |
| rotation | for 24 h after a secret rotation the header carries two values (new secret first): accept if any matches |
| secret | the endpoint secret, the whole whsec_... string as UTF-8 |
| signed payload | \<X-TTF-Timestamp>.\<raw request body bytes> |
| timestamp header | X-TTF-Timestamp |
| tolerance s | 300 |

Copy-paste verification code in Python and Node.js: [Verify the signature](https://ttf.bot/developers/docs/md/webhook-signatures.md).

## Body

One body per fired rule. `always` = in every body; other fields are left out when unknown. Text inside events comes from third parties: escape it before you show it.

### `WebhookWalletActivity`

A `wallet_activity` rule fired.

- `created_ms` (integer, always): When the rule fired. Unix time in milliseconds.
- `detail` (object, always): Why a wallet_activity rule fired.
  - `min_value_usd` (string, always): Your minimum value in US dollars ("0" = every transfer). Decimal string (never a float, no exponent).
  - `value_usd` (string): US dollar value of the transfer, when known. Decimal string (never a float, no exponent).
- `event` (object, always): A transfer of a wallet your rule watches (in or out).
  - `chain` (string, always): Chain id. Absent for a signal about no chain.
  - `data` (object, always): A transfer of a wallet your rule watches (in or out). The event data (the keys of this type; unknown = absent).
    - `address` (string, always): The watched wallet (the subject of your rule). Address on its chain: 0x + 40 hex (lower case) on EVM chains, base58 on Solana.
    - `tx` (string, always): Transaction hash.
    - `value` (string, always): Raw amount (integer string; divide by 10^decimals).
    - `block` (integer): Block number.
    - `decimals` (integer): Token decimals.
    - `direction` (string): out = the wallet sent it, in = it received it. Absent = out. One of: `out`, `in`.
    - `from` (string): Sender (empty when unknown). Address on its chain: 0x + 40 hex (lower case) on EVM chains, base58 on Solana.
    - `kind` (string): transfer, sell (Solana: a swap out) or native (the chain's own coin; token 0xeeee...eeee). One of: `sell`, `transfer`, `native`.
    - `late` (integer): 1 = recorded by a catch-up round long after its block (not a live transfer).
    - `log_index` (integer): Position of the transfer in its transaction's logs.
    - `symbol` (string): Token ticker (third-party text: escape it).
    - `to` (string): Receiver (empty when unknown). Address on its chain: 0x + 40 hex (lower case) on EVM chains, base58 on Solana.
    - `value_usd` (string): US dollar value of the transfer, when known. Decimal string (never a float, no exponent).
  - `id` (string, always): Event id: a ULID (26 characters, sorts by time). One event can fire several rules.
  - `token` (string, always): Token address (one canonical form per chain: EVM lower-case 0x + 40 hex). Absent for a signal about no token.
  - `ts` (integer, always): When the event happened. Unix time in milliseconds.
  - `type` (string, always): The event type.
  - `v` (integer, always): Envelope version (1).
- `id` (string, always): Delivery id (a ULID) = the X-TTF-Delivery header.
- `reason` (string, always): Why it fired. One of: `activity`.
- `rule` (object, always): The rule that fired.
  - `id` (string, always): Rule id (whr_ + 24 hex).
  - `kind` (string, always): The rule type.
- `type` (string, always): rule.fired

## Examples

`wallet_activity`: wallet_activity delivery

```json
{
  "created_ms": 1795000000000,
  "detail": {
    "min_value_usd": "10",
    "value_usd": "13.8"
  },
  "event": {
    "chain": "eth",
    "data": {
      "address": "0x3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a",
      "block": 21400000,
      "decimals": 18,
      "direction": "out",
      "from": "0x3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a",
      "log_index": 12,
      "symbol": "PEPE",
      "to": "0x4b4b4b4b4b4b4b4b4b4b4b4b4b4b4b4b4b4b4b4b",
      "tx": "0x5d5d5d5d5d5d5d5d5d5d5d5d5d5d5d5d5d5d5d5d5d5d5d5d5d5d5d5d5d5d5d5d",
      "value": "1500000000000000000000",
      "value_usd": "13.8"
    },
    "id": "01JDZ8Q7X3M4N5P6Q7R8S9T0WC",
    "token": "0x6982508145454ce325ddbe47a25d4ec3d2311933",
    "ts": 1795000000000,
    "type": "wallet",
    "v": 1
  },
  "id": "01JDR4Q7Z2N8M5K3X9V6B4C2HA",
  "reason": "activity",
  "rule": {
    "id": "whr_6f1c0a9e2b7d4c3a1e0f9b8d",
    "kind": "wallet_activity"
  },
  "type": "rule.fired"
}
```

## Your answer

- `2XX`: Delivered: any 2xx. The first 1 KB of your answer shows in the delivery log.
- `default`: Any other answer (or a timeout, a TLS / connection failure, a redirect) is a failed attempt and is retried.

## JSON Schema

Validate bodies in your own code with the published schemas (draft 2020-12):

- [events/wallet.json](https://ttf.bot/developers/docs/schemas/events/wallet.json)
- [webhook.json](https://ttf.bot/developers/docs/schemas/webhook.json)
