For a fully on-chain game, a mechanism is needed to drive the game logic automatically. However, current on-chain contracts can only be triggered by user transactions. To address this, a Tick solution is required to enable the scheduled execution of transactions by the system.
Synchronize block time from Layer 1 (L1).
The Sequencer, based on L1's time, triggers a Tick transaction periodically. This transaction includes an offset time and needs to be on the Data Availability (DA) layer.
Provide a Tick system contract to store a list of user contracts that need to be triggered by the Tick.
The VM needs to handle Tick Transactions, executing them based on the ticked list stored in the contract state.
How to define a tick contract
static register based
module mygame::my_module{
fun init(ctx: &mut StorageContext){
rooch_framework::tick::register(module: mygame::my_module, interval: 10 seconds)
}
fun tick(ctx: &mut StorageContext){
}
}
For a fully on-chain game, a mechanism is needed to drive the game logic automatically. However, current on-chain contracts can only be triggered by user transactions. To address this, a Tick solution is required to enable the scheduled execution of transactions by the system.
How to define a tick contract