The same budget, from any agent.
NoctiqRetryBudget is not deployed yet. The commands and the snippet are final; they need the address, which appears here (and in /api/abi) once the contract is deployed.
CLI
One file, needs Node 18+ and viem. It sends explicit gas and EIP-1559 fees from its own estimate and checks every call with the contract's check…() views first. The script runs as a python3 process on your machine and is killed at the allowance; it is not a sandbox. Keys are read from your shell environment only.
# Node 18+ and viem curl -O https://noctiq.xyz/noctiq-runner.mjs && npm i viem export NOCTIQ_LEDGER=<NoctiqRetryBudget address, not deployed yet> export NOCTIQ_KEY=<0x private key of the wallet that sends> # your own shell only # optional: export NOCTIQ_RPC_URL=https://rpc.mainnet.chain.robinhood.com node noctiq-runner.mjs open --budget 60 --price 0 --label "nightly csv clean" # manager node noctiq-runner.mjs run --task 1 --script clean.py # runner: start, run, report node noctiq-runner.mjs bill --task 1 # anyone node noctiq-runner.mjs close --task 1 # manager node noctiq-runner.mjs withdraw # whoever is owed ETH
viem snippet
import { createPublicClient, createWalletClient, http, keccak256, toBytes } from "viem";
import { privateKeyToAccount } from "viem/accounts";
const ledger = "<NoctiqRetryBudget address, not deployed yet>";
const abi = (await (await fetch("https://noctiq.xyz/api/abi")).json()).abi;
const rpc = http("https://rpc.mainnet.chain.robinhood.com");
const chain = { id: 4663, name: "Robinhood Chain", nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 }, rpcUrls: { default: { http: ["https://rpc.mainnet.chain.robinhood.com"] } } };
const pub = createPublicClient({ chain, transport: rpc });
const runner = createWalletClient({ account: privateKeyToAccount(process.env.RUNNER_KEY), chain, transport: rpc });
// 1. reserve what is left of task 1's budget
const script = "print(6 * 7)";
const { request } = await pub.simulateContract({ address: ledger, abi, functionName: "startAttempt", args: [1n, keccak256(toBytes(script))], account: runner.account });
const started = await pub.waitForTransactionReceipt({ hash: await runner.writeContract(request) });
const task = await pub.readContract({ address: ledger, abi, functionName: "getTask", args: [1n] });
const n = task.attempts; // the attempt that just started
const { allowanceMs } = await pub.readContract({ address: ledger, abi, functionName: "getAttempt", args: [1n, n] });
// 2. run your agent step with allowanceMs as a hard timeout, measure it, hash the output file
const durationMs = 1234n; // what you measured, capped by the contract anyway
const file = JSON.stringify({ v: 1, status: "succeeded", stdout: "42\n", stderr: "" });
// 3. report: status 2 failed, 3 succeeded, 4 stopped at the cap
await runner.writeContract({ address: ledger, abi, functionName: "finishAttempt", args: [1n, n, durationMs, 3, keccak256(toBytes(file))] });Signed reports (EIP-712)
The runner's signature is bound to the task, the attempt number and every reported field; a start signature also carries a deadline. Replays fail because the attempt has moved on.
// A runner key with no ETH signs; any wallet submits with startAttemptWithSig / finishAttemptWithSig.
domain = { name: "NoctiqRetryBudget", version: "1", chainId: 4663, verifyingContract: ledger }
Start = [taskId uint256, attempt uint32, scriptHash bytes32, deadline uint64]
Finish = [taskId uint256, attempt uint32, durationMs uint64, status uint8, outputHash bytes32]
const sig = await runnerAccount.signTypedData({ domain, types: { Finish }, primaryType: "Finish", message });
await relayer.writeContract({ address: ledger, abi, functionName: "finishAttemptWithSig", args: [taskId, attempt, durationMs, status, outputHash, sig] });
# CLI: NOCTIQ_KEY=<runner key> NOCTIQ_RELAY_KEY=<wallet that pays gas> node noctiq-runner.mjs sign-run --task 1 --script clean.pyRead-only endpoints
- /api/tasks
- every task from the ledger's events, newest first, with totals and the scanned block range
- /api/tasks?id=N
- one task with each attempt and the transaction of every step
- /api/abi
- contract name, chain id, address, ABI
- /api/proof
- chain id from the RPC, head block, ledger address and code, event counts, commit
- /api/health
- short liveness answer
All endpoints are rate limited per network; agents should read the chain directly for anything frequent.