Skip to main content

Environment & Invocation

Access runtime information about the current call and execution environment.

Invocation

Get information about the current endpoint call:

MethodReturnsDescription
Invocation.ID()IdentifierUnique ID of this invocation
Invocation.Caller()IdentifierImmediate caller (differs from Sender in cross-logic calls)

Sender vs Caller

  • Sender — The actor who initiated the interaction (stays the same through cross-logic calls)
  • Invocation.Caller() — The immediate caller (changes in cross-logic calls)
endpoint CheckCaller() -> (sender Identifier, caller Identifier):
sender = Sender // Original actor
caller = Invocation.Caller() // Immediate caller (could be another logic)

Environment

Access runtime environment data:

MethodReturnsDescription
Environment.Timestamp()U64Current interaction timestamp
Environment.EffortCapacity()U64Total fuel available
Environment.EffortAvailable()U64Remaining fuel
Environment.VolumeCapacity()U64Total storage space
Environment.VolumeAvailable()U64Remaining storage space
endpoint GetEnvInfo() -> (
timestamp U64,
fuel_remaining U64,
invocation_id Identifier
):
timestamp = Environment.Timestamp()
fuel_remaining = Environment.EffortAvailable()
invocation_id = Invocation.ID()

Example: Time-based Logic

coco TimeLock

state actor:
locked_until U64

endpoint dynamic Lock(duration U64):
memory unlock_time = Environment.Timestamp() + duration
mutate unlock_time -> TimeLock.Sender.locked_until

endpoint dynamic Withdraw():
observe locked <- TimeLock.Sender.locked_until:
if Environment.Timestamp() < locked:
throw "Still locked"
// proceed with withdrawal