Docs/Worker Setup

Worker Setup

Configure and deploy off-chain workers that monitor and execute AutoLoop contracts.


Overview

AutoLoop workers are off-chain Node.js processes that monitor registered contracts and call progressLoop() when ready. They auto-detect contract types (Standard, Hybrid VRF, Full VRF) via ERC-165 and handle VRF proof generation automatically.

Quick Start

git clone https://github.com/LuckyMachines/autoloop-worker.git
cd autoloop-worker
npm install

Create .env from .env-example:

RPC_URL=https://mainnet.infura.io/v3/YOUR_KEY
PRIVATE_KEY=0x_YOUR_WORKER_KEY
NETWORK=mainnet
PORT=3000

Register and start:

npm run register-controller   # costs 0.001 ETH
npm start

Environment Variables

| Variable | Required | Description | |----------|----------|-------------| | PRIVATE_KEY | Yes | Controller wallet private key | | RPC_URL | Yes | RPC endpoint for the target network | | NETWORK | No | Override network from config (mainnet, sepolia, anvil) | | PORT | No | Health server port (default: 3000) |

Per-network keys are also supported:

PRIVATE_KEY_MAINNET=0x...
RPC_URL_MAINNET=https://mainnet.infura.io/v3/YOUR_KEY
PRIVATE_KEY_SEPOLIA=0x...
RPC_URL_SEPOLIA=https://sepolia.infura.io/v3/YOUR_KEY

Config File

controller.config.json is optional when NETWORK env var is set:

{
  "network": "mainnet",
  "allowList": [],
  "blockList": []
}
  • allowList — explicit contracts to monitor (empty = monitor all registered)
  • blockList — contracts to skip

VRF Support

Workers auto-detect contract types and handle each mode:

| Contract Type | Detection | Worker Behavior | |---------------|-----------|-----------------| | AutoLoopCompatible | Default | Standard execution, no VRF | | AutoLoopHybridVRFCompatible | ERC-165 interface | Reads needsVRF flag; VRF proof only when true | | AutoLoopVRFCompatible | ERC-165 interface | VRF proof on every tick |

Before a VRF/Hybrid contract accepts proofs, register the controller's public key on-chain:

vrfContract.registerControllerKey(controllerAddress, pkX, pkY);

Health Endpoint

Workers run an HTTP health server on PORT:

GET /health
{
  "status": "running",
  "uptime": 1234,
  "network": "mainnet",
  "blockNumber": 10374545,
  "loopsMonitored": 3,
  "lastCheck": "2026-03-12T09:07:14.004Z"
}

Cloud Deployment (Railway)

The worker ships with a Dockerfile and railway.toml:

docker build -t autoloop-worker .
docker run --env-file .env autoloop-worker

The entrypoint is npm run cloud-start — registers the controller and starts the worker. The Dockerfile includes a HEALTHCHECK that pings /health.

Scripts

| Command | Description | |---------|-------------| | npm start | Run worker | | npm run register-controller | Register wallet (costs 0.001 ETH) | | npm run registered-auto-loops | List registered contracts | | npm run progress-loop <ADDR> | Manual one-off loop | | npm run cloud-start | Register + start (Docker/Railway) |