# op_context · Chromia Docs (concept)

> The op_context namespace provides information about the current operation context, including block information, transaction details, and signer verification.

Source: https://docs.chromia.com/rell/language-features/systemlib/namespaces/op_context/

# op\_context

On this page

* [Overview](#overview)
* [Key functions and fields](#key-functions-and-fields)
* [Example: Verify transaction signer](#example-verify-transaction-signer)
* [Example: Access block and operation information](#example-access-block-and-operation-information)
* [Example: Get all operations in a transaction](#example-get-all-operations-in-a-transaction)

The [`op_context`](https://docs.chromia.com/pages/rell-stdlib/-rell-system-library/op_context/) namespace provides information about the current operation context, including block information,
transaction details, and signer verification. For complete API documentation, see the
[`op_context` reference](https://docs.chromia.com/pages/rell-stdlib/-rell-system-library/op_context/) in the Standard
Library.

note

You can only use [`op_context`](https://docs.chromia.com/pages/rell-stdlib/-rell-system-library/op_context/) in an operation or a function called from an operation, but not in a query. Use
[`op_context.exists`](https://docs.chromia.com/pages/rell-stdlib/-rell-system-library/op_context/exists/) to check if the
code is running in an operation context.

## Overview

The [`op_context`](https://docs.chromia.com/pages/rell-stdlib/-rell-system-library/op_context/) namespace includes:

* **Block information** – `block_height`, `last_block_time` for accessing blockchain state
* **Transaction details** – `transaction`, [`op_index`](https://docs.chromia.com/pages/rell-stdlib/-rell-system-library/op_context/op_index/) for information about the current transaction and operation
* **Signer verification** – `get_signers`,
  [`is_signer`](https://docs.chromia.com/pages/rell-stdlib/-rell-system-library/root/is_signer/) for checking
  transaction signatures
* **Operation access** – [`get_all_operations`](https://docs.chromia.com/pages/rell-stdlib/-rell-system-library/op_context/get_all_operations/), [`get_current_operation`](https://docs.chromia.com/pages/rell-stdlib/-rell-system-library/op_context/get_current_operation/) for inspecting transaction operations
* **Event emission** – [`emit_event`](https://docs.chromia.com/pages/rell-stdlib/-rell-system-library/op_context/emit_event/) for communication with Postchain components

## Key functions and fields

* [`op_context.block_height`](https://docs.chromia.com/pages/rell-stdlib/-rell-system-library/op_context/block_height/) –
  Height of the block being built
* [`op_context.last_block_time`](https://docs.chromia.com/pages/rell-stdlib/-rell-system-library/op_context/last_block_time/)
  – Timestamp of the last block in milliseconds
* `op_context.transaction` – The transaction currently being built
* [`op_context.exists`](https://docs.chromia.com/pages/rell-stdlib/-rell-system-library/op_context/exists/) – Check if the
  code is running in an operation context
* [`op_context.op_index`](https://docs.chromia.com/pages/rell-stdlib/-rell-system-library/op_context/op_index/) – Index of
  the operation within the transaction
* [`op_context.get_signers`](https://docs.chromia.com/pages/rell-stdlib/-rell-system-library/op_context/get_signers/) – Get
  all public keys that signed the transaction
* [`op_context.is_signer`](https://docs.chromia.com/pages/rell-stdlib/-rell-system-library/op_context/is_signer/) – Check
  if a specific public key signed the transaction
* [`op_context.get_all_operations`](https://docs.chromia.com/pages/rell-stdlib/-rell-system-library/op_context/get_all_operations/)
  – Get all operations in the current transaction
* [`op_context.get_current_operation`](https://docs.chromia.com/pages/rell-stdlib/-rell-system-library/op_context/get_current_operation/)
  – Get the current operation
* [`op_context.emit_event`](https://docs.chromia.com/pages/rell-stdlib/-rell-system-library/op_context/emit_event/) – Emit
  an event to Postchain components

## Example: Verify transaction signer

Rell

```
operation transfer(to: text, amount: integer) {
    val sender_pubkey = x'036d6caac248af96f6afa7f904f550253a0f3ef3f5aa2fe6838a95b216691468e2';

    // Check if the expected public key signed this transaction
    require(op_context.is_signer(sender_pubkey), "Unauthorized: sender must sign the transaction");

    // Perform transfer logic
    // ...
}
```

## Example: Access block and operation information

Rell

```
operation log_operation() {
    print("Block height: %d".format(op_context.block_height));
    print("Operation index: %d".format(op_context.op_index));
    print("Number of signers: %d".format(op_context.get_signers().size()));
    print("Last block time: %d".format(op_context.last_block_time));
}
```

## Example: Get all operations in a transaction

Rell

```
operation process_batch() {
    val all_ops = op_context.get_all_operations();

    for (op in all_ops) {
        print("Operation: %s".format(op.name));
    }
}
```

warning

You must not use `op_context.transaction.block` because, except `block_height`, its attributes are null, so reading them
gives a run-time error. Use `op_context.block_height` and `op_context.last_block_time` instead.

[View this page on docs.chromia.com](https://docs.chromia.com/rell/language-features/systemlib/namespaces/op_context/)Content mirrored from the live docs
