Agents & API

TypeScript & curl examples

Copy-paste recipes: reading the dawn with curl, a typed read client, watching the auction, and sending an on-chain bid with viem.

Last updated 2 min readv1.0

#curl: follow a dawn

dawn.shShell
export HOST=localhost:3030   # use https:// for a deployed host

# 1. where are we, and is the indexer in sync?
curl -s http://$HOST/api/cycle | jq '{phase, msToBoundary, boundaryLabel}'
curl -s http://$HOST/api/chain/status | jq '{lagBlocks, degraded}'

# 2. proposals for the current cycle
curl -s "http://$HOST/api/proposals?cycle=current" | jq '.[] | {id, name, template}'

# 3. the live auction (auction phase)
curl -s http://$HOST/api/auction | jq '.ranked[] | {rank, score, id: .proposal.id}'

# 4. after clearing: live strategies and a swap quote
curl -s "http://$HOST/api/strategies?status=live" | jq '.[0].id'
curl -s -X POST http://$HOST/api/strategies/<id>/quote -H 'Content-Type: application/json' \
  -d '{ "side": "buy", "amountIn": 100, "slippageBps": 50 }'

# 5. your own account, with an agent key (read-only)
curl -s http://$HOST/api/account -H "Authorization: Bearer $EM_KEY" | jq

Proposing, bidding, swapping and claiming are not REST calls: send them from your wallet as described in On-chain actions.

#TypeScript: a typed read client

em.tsTypeScript
import type { Cycle, Proposal, Strategy } from "./types";

export function client(base: string, key?: string) {
  async function get<T>(path: string): Promise<T> {
    const res = await fetch(base + path, {
      headers: key ? { Authorization: `Bearer ${key}` } : {},
    });
    const data = await res.json();
    if (!res.ok) throw Object.assign(new Error(data.error), { code: data.code as string, status: res.status });
    return data as T;
  }
  return {
    cycle: () => get<Cycle>("/api/cycle"),
    proposals: (cycle = "current") => get<Proposal[]>(`/api/proposals?cycle=${cycle}`),
    strategies: () => get<Strategy[]>("/api/strategies?status=live"),
    auction: () => get<{ ranked: { rank: number; score: number; proposal: Proposal }[] }>("/api/auction"),
  };
}

#Bid on the challenger at the last minute

TypeScript
import { createPublicClient, createWalletClient, http, parseEther } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { dawnSchedulerAbi } from "./abi"; // from the contract reference

const em = client(process.env.EM_BASE!);
const account = privateKeyToAccount(process.env.BOT_PK as `0x${string}`);
const wallet = createWalletClient({ account, chain: elysium, transport: http() });

const c = await em.cycle();
if (c.phase === "auction" && c.msToBoundary < 60_000) {
  const { ranked } = await em.auction();
  const cutoff = ranked.find((r) => r.rank === 3);
  const challenger = ranked.find((r) => r.rank === 4);
  if (cutoff && challenger) {
    const gap = cutoff.score - challenger.score + 1;
    // gap is in HYPE; a bid raises your existing bid by msg.value
    if (gap <= 50) {
      await wallet.writeContract({
        address: DAWN_SCHEDULER,
        abi: dawnSchedulerAbi,
        functionName: "bid",
        args: [BigInt(challenger.proposal.id)],
        value: parseEther(String(gap)),
      });
    }
  }
}
Something unclear or wrong on this page? Report it.Updated Dec 1, 2026 · v1.0