Skip to content

State Machine

Modelling a process

A deterministic state machine is a computational framework where each subsequent state and its output are precisely determined by its current state coupled with the incoming input, adhering to specific transition rules. This framework guarantees predictable and unambiguous transitions between states.

graph LR A[Start] --> B[State 1] B --> C[State 2] A --> D[State 3]

State machines in Stackr

Stackr uses state machines to model the process of a user's interaction with the application.

A typical state machine in Stackr consists of the following components:

machines.ts
import { StateMachine } from "@stackr/sdk/machine";
 
const machine = new StateMachine({
  id: "counter",
  stateClass: CounterState,
  initialState: genesisState.state,
  on: transitions,
  hooks
});
  • id: A unique identifier for the state machine.
  • stateClass: A class that defines the states of the state machine.
  • initialState: The initial state of the state machine.
  • on: A set of transition rules that define how the state machine transitions between states.
  • hooks (optional): A set of hooks functions that runs before or after (based on configuration) execution of all actions of block.

More on each of these components in the following sections.

State machines are independent of the Rollup

It is important to note that state machines are independent of the Rollup. A rollup contains state machines and orchestrates their interactions, but the state machines themselves are standalone entities.