Skip to main content
A swarm is several bots driven by one trepa.bots.run call. Each bot has its own Trepa login and wallet; they share one script and exit together. Use this when you want multiple wallets in the same pool (Trepa allows one prediction per account per pool), or when you coordinate different stakes or forecasts from one program. Writing bots covers predict, ctx, and hooks for a single account. Swarms reuse that API; the only structural change is passing more than one credential into Trepa and, when needed, varying behaviour per bot.
Each Trepa account gets one prediction per pool. Running N bots means N accounts, each with its own API key and exported wallet key.

Load several credential pairs

Start by listing every bot’s API key and wallet key. The usual pattern is numbered variables in .env, read by credentialsFromEnv():
The helper loads _1, _2, _3, and so on until it hits a gap. A key without its matching private key throws at startup. You can also pass an explicit array:
Calls on the top-level trepa instance use only the first credential. Inside predict, use ctx.trepa for the bot that is currently acting.

Different behaviour per bot

When bots should not share identical logic, pass a function instead of a plain options object. It receives index (0-based) and count:
When every bot should behave the same, pass a normal options object. Inside predict, ctx.slot repeats index and count if you prefer reading them from ctx.

Per-bot API calls

Swarms matter most when each wallet needs its own portfolio or history. Inside predict, call through ctx.trepa so you never mix wallets:

Optional: master wallet funding

Running many bots usually means funding many wallets. The SDK can pull from one treasury instead of manual top-ups: Set TREPA_MASTER_PRIVATE_KEY so a background task tops up each bot’s stake token and SOL from one treasury wallet (and sweeps excess back). See Master wallet. Next: Master wallet.
Last modified on May 29, 2026