> For the complete documentation index, see [llms.txt](https://docs.otherside.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.otherside.xyz/odk-docs/odk-plugin/nfts-tokens/token-handlers.md).

# Token Handlers

**Token Handlers** are objects that react to token changes inside the ODK wallet. They live on the wallet component of the Morpheus player character and define what happens when a token is **added, removed, or updated** — such as triggering a quest, showing some UI, or playing a VFX.

The system is modular, data-driven, and highly extendable via Blueprints.

***

### 🔩 Where Token Handlers Live

Token Handlers are configured on the player's wallet component:\
📍 `BPMC_ODK_WalletComponent`\
Found on: `BPM_ODK_PlayerCharacterBase` or your project’s subclass.

Inside the component, you’ll find a map:

```cpp
Map<string, BP_ODKFilterSet>
```

Each entry defines a **filter set** with an arbitrary name and the handler that should respond if a token passes that filter.

***

#### Example Use Case:

* Filters for tokens with `type == "quest"`
* Handler: `BP_ODKTokenHandler_Quest` - Shows Quest UI information

***

### 🧪 How Filtering Works

Each filter in the filter set must implement the function:

```cpp
IsRelevantToken(TokenData) → bool
```

This function inspects the token metadata and determines if it matches your logic.

If ALL **of the filters return `true`**, the **assigned Token Handler is activated**.

***

### 🧰 Built-in Example Filters

You can find reusable example filters in the plugin:

#### 🧾 `BP_ODKTokenFilter_TokenType`

* Checks the `type` field in token metadata
* Accepts a **whitelist of strings**
* Example: match `type == "quest"` or `type == "achievement"`

***

#### 🧮 `BP_ODKTokenConditionGroup`

* Used to **group filters together** in more advanced logic
* Contains:

  * `Filters[]`: array of AND'd filters - All filters must pass
  * `OR Filter`: a single filter that acts as an OR condition.

  The OR filter is a single filter because it allows nesting of `ConditionGroups`, allowing complex condition trees

**Example:**

```plaintext
( TokenType == "quest" ) 
  OR 
( ConditionGroup
    (TokenType == "achievement")
            AND
    (ChainID == "33139")
)
```

***

### 🛠 Creating Your Own Filters

To create custom filters:

1. Inherit from `BP_ODKTokenFilterBase`
2. Implement `IsRelevantToken`
3. Add any parameters you want to expose (e.g. tags, substrings, reward keys)

Custom filters give you full control over how tokens are routed, enabling:

* Campaign-specific logic
* Filtering by metadata fields like XP, group, or even token balance

***

### 🎯 Creating Your Own Token Handlers

Handlers inherit from `BP_ODKTokenHandlerBase` and define what happens when a relevant token event occurs.

Each handler receives the `TokenUpdate` function containing the filtered token and the update type (Add, Update, Remove etc)

Token handlers allow for custom logic for a filtered token, for example:

For all tokens with "type" "quest"

* Fire off UI or sound
* Trigger Task Flows

For all tokens with "type" "badge"

* Start cinematics
* Queue unlocks
* Animate overlays

***

### ✅ Best Practices

* Use meaningful filter set names (`"quest notifications"`, `"achievement unlocked"`)
* Reuse modular filters (e.g. shared `TokenType` filters)
* Keep filters lightweight — heavy logic should live in handlers
* Avoid putting too much logic inside `IsRelevantToken` — keep it as a pass/fail gate

***

### 🧵 Summary Flow

```plaintext
1. Token is added/removed/updated
2. Each Filter Set checks if the token matches its filter(s)
3. If matched → corresponding Token Handler is triggered
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.otherside.xyz/odk-docs/odk-plugin/nfts-tokens/token-handlers.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
