Skip to content

Deploy a Forecasting Agent

In the next five minutes, you can deploy the forecasting agent template (built with the ElizaOS framework) on Railway, customize it, and publish its forecasts to Ethereum so it:

In the next guide, you can have it automatically submit a $1 wager based on its forecasts.

One‑Click Deploy

Deploy on Railway

Environment Variables

For setup details on your API keys and private key, see Get Started: OpenRouter setup and Private key generation.

Core Configuration

VariableDefaultRequiredNotes
OPENROUTER_API_KEYYesYour OpenRouter API key for model access
EVM_PRIVATE_KEY or ETHEREUM_PRIVATE_KEYYesPublishes forecasts to EAS; required for visibility/leaderboard and trading
EVM_PROVIDER_URLhttps://arb1.arbitrum.io/rpcNoArbitrum RPC endpoint (consider paid provider for reliability)

Autonomous Mode

VariableDefaultNotes
AUTO_MODE_ENABLEDtrueStart in autonomous mode on launch
AUTO_MODE_INTERVAL300000Loop interval in milliseconds (5 minutes default)
AUTO_MODE_MIN_CONFIDENCE0.6Minimum confidence threshold (0-1) for predictions
AUTO_MODE_BATCH_SIZE5Number of markets to process per cycle

Parlay Trading (Optional)

VariableDefaultNotes
ENABLE_PARLAY_TRADINGfalseEnable $1 automated wagers on parlays based on forecasts
PARLAY_WAGER_AMOUNT1000000000000000000Wager amount in USDe (18 decimals: $1 = 1,000,000,000,000,000,000)
MIN_TRADING_CONFIDENCE0.6Only trade when prediction confidence exceeds this threshold
MAX_TRADING_SLIPPAGE5Maximum acceptable slippage percentage for trades

Customize Your Agent

We strongly recommend using an LLM-powered code editor to customize your agent.

Eject to your GitHub and pull locally

First, connect the deployed service to your own repository so you can edit and push changes. Second, make sure your github account is connected and authorized. You can find this at Account Settings → Account → Account Integrations → Configure Railway App. If you don't have the railway app configured on your account it will not let you eject to your github account.

  1. In Railway, open your service → Source → Eject → choose your GitHub org → Eject service
  2. Clone the newly created repo and set up locally:
git clone <your-new-repo-url> your-forecast-agent
cd your-forecast-agent
# install deps (choose your tool)
bun install # or: pnpm install / npm install
cp .env.example .env
# Required: OpenRouter API key for LLM access
# OPENROUTER_API_KEY=<your-openrouter-api-key>
 
# Required: Private key for on-chain attestations
# EVM_PRIVATE_KEY=<your-ethereum-private-key>
 
# Optional: Enable automated trading
# ENABLE_PARLAY_TRADING=true
  1. Push changes; enable Autodeploy in Railway so pushes redeploy automatically.

Edit Your Agent's Code

You’ll customize prompts and model selection. The template/Eliza runtime handles formatting, routing, and output normalization.

  1. Edit prompts/persona in src/character.ts:

    • Update name, bio, lore, style, etc — this is your system prompt
    • Add domain context and instructions for producing a single percent chance (0–100%) for Yes/No markets
  2. Choose/override the model:

    • Set environment in Railway (recommended):
      • Preferred: OPENAI_BASE_URL=https://openrouter.ai/api/v1, set OPENAI_API_KEY to your OpenRouter key, and choose a model id (e.g. openai/gpt-4o-mini)
      • Direct providers: You may instead use OpenAI/Anthropic keys with their native SDKs, but OpenRouter unifies models and billing
    • If the template pins a model in code, update the LLM provider in src/index.ts to your desired model/provider
  3. Verify outputs and iterate quickly:

    • Keep structured logs on; each run should show the chosen market, your percent forecast, and (if enabled) the EAS attestation hash
    • Tighten prompts or switch models to improve calibration and stability
  4. Quick edge ideas:

    • Constrain output to a single number with units, e.g., "62%"
    • Lower temperature for stability; compare small models for cost vs. quality
    • Add lightweight retrieval (e.g., headlines) if supported by the template
    • Track a rolling window of forecasts to see variance and bias
  5. Wire invocation behavior in src/index.ts:

    • Ensure your forecasting action/provider is registered so it can run on a schedule or on command
    • Keep logs enabled to inspect inputs/outputs and iterate quickly
  6. Tune market selection:

    • Default: queries Sapience for open markets, sorts by soonest endTimestamp, and picks the next closing market; de-duplicates by group when present
    • Tweak: filter by topic/category via environment, pin a specific market or group, or swap the selection provider/action in src/index.ts
    • Logs include marketId, groupId (if present), and endTimestamp so you can verify behavior

Run Locally

Local development (example with Bun):

# after Eject, clone your repo (replace with your URL)
git clone <your-new-repo-url> your-sage-bot
cd your-sage-bot
bun install
cp .env.example .env
# Required: OpenRouter API key for LLM access
# OPENROUTER_API_KEY=<your-openrouter-api-key>
 
# Required: Private key for on-chain attestations
# EVM_PRIVATE_KEY=<your-ethereum-private-key>
 
# Required: Enable automated trading
# ENABLE_PARLAY_TRADING=true
bun run dev

Looking to deploy manually? See the Railway CLI guide: Deploy with the CLI.

Enable Automated Parlay Trading

Your forecasting agent can automatically place $1 wagers on parlays based on its predictions:

  • Predictions >50% → Buy YES tokens
  • Predictions <50% → Buy NO tokens

Setup Parlay Trading

  1. Enable Trading by setting the environment variable:

    ENABLE_PARLAY_TRADING=true
  2. Configure Trading Parameters (optional):

    # Wager amount in USDe (18 decimals)
    PARLAY_WAGER_AMOUNT=1000000000000000000  # $1 default
     
    # Only trade when prediction confidence exceeds threshold
    MIN_TRADING_CONFIDENCE=0.6   # 60% default
     
    # Maximum acceptable slippage
    MAX_TRADING_SLIPPAGE=5       # 5% default
  3. Ensure Wallet Funding: Your ETHEREUM_PRIVATE_KEY wallet needs USDe on Arbitrum for trading.

How It Works

After each forecast attestation, if trading is enabled:

  1. Confidence Check: Only trades if prediction confidence > MIN_TRADING_CONFIDENCE
  2. Direction: Buys YES tokens for >50% predictions, NO tokens for <50%
  3. Auction Process: Connects to Sapience WebSocket, participates in parlay auctions
  4. Execution: Approves USDe and calls PredictionMarket.mint() with best bid
  5. Logging: Reports trade execution with transaction hash

⚠️ Risk Warning: Automated trading involves financial risk. Start with small amounts and monitor performance.

Alternative: Manual Trading

For more control, see the Trading Bots guide for custom trading implementations.