Skip to main content

Module context

Module context 

Source
Expand description

Execution context accessors for contract runtime information.

This module provides functions to query the current execution context, including caller information, block data, and call parameters.

§Available Context

  • Caller: Who invoked this contract
  • Owner: Who deployed/owns this contract
  • Contract ID: This contract’s address
  • Block data: Current height and timestamp
  • Call value: Native tokens sent with the call
  • Calldata: Function selector and arguments

§Example

use truthlinked_sdk::context;

fn handle_execute() -> Result<()> {
    let caller = context::caller()?;
    let owner = context::owner()?;
     
    // Only owner can call this function
    if caller != owner {
        return Err(Error::new(ERR_UNAUTHORIZED));
    }
     
    let height = context::block_height()?;
    let value = context::call_value()?;
     
    // Process transaction...
    Ok(())
}

Functions§

block_height
Returns the current block height.
block_timestamp
Returns the current block timestamp (Unix seconds).
call_value
Returns the amount of native tokens sent with this call.
calldata
Returns the raw calldata (function selector + arguments).
caller
Returns the account ID of the transaction sender.
contract_id
Returns this contract’s account ID.
owner
Returns the account ID of the contract owner.
set_return_data
Sets the return data for this contract call.

Type Aliases§

AccountId
Type alias for 32-byte account identifiers.