Skip to main content

Observing logic and user's state

observe reads the value in the storage, either on logic or on user (actor). The syntax is

observe logicname.<Logic/actor_identifier>.Field>

Storage is always linked to a logic, but it can be logic's own state (when the second argument is Logic) or on an actor (user or some other logic) if the second argument is an identifier.

Field is a field name in the storage, but for complex values elements need to be accessed by individual values, e.g. class field, map value by key etc.

For registered users, actor_identifier can be replaced by username, so we don't need to write the complete identifier like 0x3354b6f98a3920ee671c0982c37439f98995104330a771c9d457372ad8da1a13. Sender is the identifier of the current default.sender.

observe Flipper.Logic.value
observe ContextFlipper.Sender.value
observe ContextFlipper.default_user.value
observe.ContextFlipper.0x3354b6f98a3920ee671c0982c37439f98995104330a771c9d457372ad8da1a13.value
observe MapLogic.Logic.mapValue[""]

Note that MOI uses atomic storage that reduces the need to transfer large amounts of data from the blockchain, but it also means once can't access complete maps - only individual keys. E.g., in the example above, this would return only the number of keys, not the complete map:

observe MapLogic.Logic.mapValue

Storage Key

Atomic storage means accessing data in the storage using storage key. In the examples above using observe command, we've observed the values through a human-readable identifier of the field. But we can also manually create storage key using storagekey command.

storagekey slotnum idx(u64) fld(u8) key(0xMapKey or 0xUserAddress) Generates a storage key based on the provided fields. The sequence can include multiple instances of the same field, depending on how deeply nested the storage field is.

 storagekey 0 idx(7898) fld(99) key(0x79d587de4a2c72b55771d291b8ad6c9ffdcaa5cba12c958090da1799eb906f5d)

0xe5ccdbc6965dda819adbc0cab34037e668a5351360baebc85a494bc0ec175327

With such storage key, we can directly observe a value

observe MyLogic.Logic.0xe5ccdbc6965dda819adbc0cab34037e668a5351360baebc85a494bc0ec175327