# Writing handlers

The handler functions act as a bridge between the raw on-chain data and the structured, queryable format required by the database.&#x20;

By writing custom logic in these handlers, developers can tailor the indexing process to meet their specific requirements, ensuring that the indexed data is organized and formatted in a meaningful way for efficient querying and analysis.

***

### Input Context

Each handler function receives an input object containing all the relevant on-chain information related to the event or function call that triggered the handler. The content and structure of this input object vary depending on the type of handler (event or function) and the specific blockchain data being indexed.

* IEventContext
* IFunctionContext

***

### Database CRUD Operations in Handlers

Within the handler functions, you can perform various Create, Read, Update, and Delete (CRUD) operations on the indexed data stored in the database. The `@blockflow-labs/sdk` library provides utility functions to facilitate these operations

***

### Using BigNumber.js

Smart contract generally deals in large integers like uint256 which is not handled by javascript properly. Hence it is recommended to use BigNumber libraries like ethers.js and BigNumber.js.  These libraries are particularly useful when working with `uint256` values.

To use BigNumber.js in your subgraph project, you can import it into your handler files:

```typescript
import BigNumber from "bignumber.js";
```

Once imported, you can create BigNumber instances and perform various operations on them:

```typescript
const amount = new BigNumber(value).plus("1000");
```

BigNumber.js provides a wide range of methods for performing arithmetic operations, comparison, formatting, and more, allowing you to handle large integers accurately and efficiently. You can check out the library [here](https://www.npmjs.com/package/bignumber.js/v/4.0.4).


---

# Agent Instructions: 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:

```
GET https://docs.blockflow.network/cli/writing-handlers.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
