Docs/Contracts/Standard

Standard Contract

Pure automation with AutoLoopCompatible — the simplest way to add self-executing logic to your smart contract.


Overview

AutoLoopCompatible is the simplest AutoLoop base contract. It provides pure automation — workers monitor your contract and call progressLoop() whenever shouldProgressLoop() returns true. No randomness, no VRF overhead.

Best for: Periodic tasks, heartbeats, scheduled operations, state machines, turn-based games without randomness.

Integration

Inherit from AutoLoopCompatible and implement two functions:

import "@luckymachines/autoloop/src/AutoLoopCompatible.sol";

contract MyGame is AutoLoopCompatible {
    uint256 public number;
    uint256 public interval;
    uint256 public lastTimeStamp;
    uint256 private _loopID;

    constructor(uint256 _interval) {
        interval = _interval;
        lastTimeStamp = block.timestamp;
    }

    function shouldProgressLoop()
        external view override
        returns (bool loopIsReady, bytes memory progressWithData)
    {
        loopIsReady = (block.timestamp - lastTimeStamp) > interval;
        progressWithData = abi.encode(_loopID);
    }

    function progressLoop(bytes calldata progressWithData) external override {
        uint256 loopID = abi.decode(progressWithData, (uint256));
        require(loopID == _loopID, "stale loop");
        lastTimeStamp = block.timestamp;
        ++number;
        ++_loopID;
    }
}

Key Functions

shouldProgressLoop()

Called by workers on every block to check if your contract is ready for an update.

  • Returns loopIsReadytrue when the loop should execute
  • Returns progressWithData — arbitrary bytes passed to progressLoop(). Always include _loopID to prevent duplicate runs.

progressLoop(bytes calldata progressWithData)

Called by AutoLoop when shouldProgressLoop() returns true. This is where your game logic goes.

  • Always decode and verify _loopID to guard against stale or replayed calls
  • Increment _loopID at the end to advance the loop

Gas Cost

MetricValue
Median gas per tick~90,000
Cost per tick (2026)~$0.008
10-min game @ 1 tick/sec~$5.05

Standard loops are the cheapest option — no VRF proof verification overhead.

When to Use Standard vs Hybrid

Use Standard when your game logic is purely deterministic — timers, counters, state machines, turn progression. If you need randomness even occasionally, use Hybrid VRF instead.