System Events

Beyond smart-contract capabilities

There are two events that are generated by the system, this is represented in Solidity as:

event BlockTick(uint64 indexed blockNumber);
event Schedule(uint256 indexed timestampMillis);

You can subscribe to those events as any other. The system will generate those events for every block and match with any subscriptions.

circle-info

Remember to set the emitter field to SOMNIA_REACTIVITY_PRECOMPILE_ADDRESS. This will make sure that your handler will only respond to system events.

Block Tick Event

If blockNumber is provided then this event will trigger at the specific block. Other wise this will be triggered at every block, ~10 times per second.

This example will tick at every single block:

ISomniaReactivityPrecompile.SubscriptionData
    memory subscriptionData = ISomniaReactivityPrecompile
        .SubscriptionData({
            eventTopics: [BlockTick.selector, bytes32(0), bytes32(0), bytes32(0)],
            emitter: SomniaExtensions.SOMNIA_REACTIVITY_PRECOMPILE_ADDRESS,
            handlerContractAddress: address(this),
            handlerFunctionSelector: ISomniaEventHandler.onEvent.selector,
            /*...*/
    });

Schedule Event

This event is useful for scheduling actions in the future. Few things to remember:

  • The provided timestamp must be in the future, minimum is next second from the current block

  • The subscription to Schedule is one-off and will be deleted after triggering

  • The timestamp is expressed in milliseconds (see https://currentmillis.com/arrow-up-right for handy calculations)

his example will tick on Nov 11 2026 11:11:11.011 :

Last updated