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

# Compute per block

> Transform EVM trace rows into derived records at the same block.

Process a ready source block to derive records for a target table. This example selects value-bearing trace rows and preserves integer values.

## Chain and block context

The example uses `eth` as the function's chain argument. The same `block` object selects the source block and the target write context. If you add EVM reads, pass `block.id` explicitly to the function and its `EVM` instance.

## Prerequisites

* A connected block deployment and readable BlockDB source data.
* A source schema with `id`, `tx_id`, `from_addr`, `to_addr`, and a decimal integer `value`.
* A target table with compatible columns, including an integer-compatible `value`.
* A BlockDB `Block` object from a source notification or your application's input-readiness flow.

## Submit the block computation

```python theme={null}
from blockx import (
    SOURCE_ROW, BlockTableCallConfig, BlockTableWriteHandler,
    Function, TaskBuilder,
)

source_code = """
def _(chain_id, record):
    value = int(record.get("value") or 0)
    if value <= 0 or not record.get("tx_id"):
        return None
    return {
        "id": record["id"],
        "chain_id": chain_id,
        "tx_id": record["tx_id"],
        "from_addr": record["from_addr"],
        "to_addr": record["to_addr"],
        "value": value,
    }
"""


def submit_block(block, source_table, target_table):
    task = TaskBuilder.build(
        BlockTableCallConfig(block=block, triggerSources=[{
            "table": source_table,
            "func": Function(source_code=source_code),
            "params": ["eth", SOURCE_ROW],
        }]),
        BlockTableWriteHandler(targetTable=target_table, block=block),
    )
    result = task.submit(timeout=120)
    if not result.task_result.success:
        raise RuntimeError(result.task_result.failure_code)
    return task.task_id, result.handler_result
```

Call `submit_block` with your ready block and source and target table names. The caller determines when dependencies are readable. Keep that readiness check outside the function execution itself.

## Choose a normal-table output

If the result belongs in a keyed table without block write context, replace the handler with `NormalTableWriteHandler(targetTable=target_table)`. The function still receives the context its computation needs. See [configuration reference](/reference/task-configuration).

For conditional updates, use a comparable column in your target schema. This handler keeps the larger `value` when an existing row has the same `id`:

```python theme={null}
from blockx import NormalTableWriteHandler


def increasing_value_handler(target_table):
    return NormalTableWriteHandler(
        targetTable=target_table,
        condition=("value", "UpdateIfLarger"),
    )
```

Pass `increasing_value_handler(target_table)` as the second argument to `TaskBuilder.build`. Use `UpdateIfSmaller` to retain the smaller value instead. The equivalent dictionary form is `condition={"column": "value", "policy": "UpdateIfLarger"}`. The condition column cannot be `id`; omitting `condition` uses an unconditional upsert. A conditional upsert does not make the entire task or its other effects idempotent.

## Confirm completion

Record the task identifier, source block, target table, and writer result. Block writes are submitted asynchronously. Confirm the target block's storage completion and read conditions before downstream computation; see [execution semantics](/concepts/execution-semantics).

## Handle failures

* Correct missing source fields or target columns before repeating the computation.
* Inspect `PLUGIN_FAILED` separately from function failure.
* If a connection ends after submission, check the original task and write state before creating new work.

## Continue reading

* [Backfill historical bundles](/guides/bundle-backfill)
* [Write EVM data functions](/guides/write-functions)
* [Query results and handle failures](/guides/results-and-failures)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.