Chain and block context
The example useseth 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 integervalue. - A target table with compatible columns, including an integer-compatible
value. - A BlockDB
Blockobject from a source notification or your application’s input-readiness flow.
Submit the block computation
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 withNormalTableWriteHandler(targetTable=target_table). The function still receives the context its computation needs. See configuration reference.
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:
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.Handle failures
- Correct missing source fields or target columns before repeating the computation.
- Inspect
PLUGIN_FAILEDseparately from function failure. - If a connection ends after submission, check the original task and write state before creating new work.