> For the complete documentation index, see [llms.txt](https://docs.blockflow.network/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.blockflow.network/cli/building-blocks/setting-up-handlers.md).

# Setting up Handlers

The handlers take data from a particular source and transform it into entities that are defined within your schema. Handlers are written in  [TypeScript](https://www.typescriptlang.org/docs/handbook/typescript-in-5-minutes.html).

For each handler that is defined in `studio.yaml` under `triggers`, create an exported function of the same name in `src/handlers` folder.&#x20;

> ```sh
> blockflow codegen
> ```

Use above command to generate boilerplate code in `path` specified in `studio.yaml`

***

### Handlers boilerplate&#x20;

Based on the trigger-type `contract/function` or `contract/event` code vary.

* Function Handler Code

```typescript
import { IFunctionContext, IBind, ISecrets } from "@blockflow-labs/utils";

/**
 * @dev Function::approve(address _spender, uint256 _value)
 * @param context trigger object with contains {functionParams: {_spender ,_value }, transaction, block}
 * @param bind init function for database wrapper methods
 */
export const approveHandler = async (
  context: IFunctionContext,
  bind: IBind,
  secrets: ISecrets,
) => {
  // Implement your function handler logic for approve here

  const { functionParams, transaction, block } = context;
  const { _spender, _value } = functionParams;
};
```

* Event Handler Code

```typescript
import {
  IEventContext,
  IBind,
  Instance,
  ISecrets,
} from "@blockflow-labs/utils";

/**
 * @dev Event::Transfer(address from, address to, uint256 value)
 * @param context trigger object with contains {event: {from ,to ,value }, transaction, block, log}
 * @param bind init function for database wrapper methods
 */
export const TransferHandler = async (
  context: IEventContext,
  bind: IBind,
  secrets: ISecrets,
) => {
  // Implement your event handler logic for Transfer here

  const { event, transaction, block, log } = context;
  const { from, to, value } = event;
};
```

To read more about handlers code use this doc. &#x20;


---

# 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.blockflow.network/cli/building-blocks/setting-up-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.
