Site icon Chainstack

Integrating Chainstack with OpenClaw bot for Polymarket

Introduction

PolyClaw is an innovative OpenClaw skill (formerly known as Clawdbot, then Moltbot) that brings Polymarket trading and arbitrage capabilities directly to your messenger. Built as a messenger-friendly version of the Polymarket Alphabot developed by Chainstack, PolyClaw enables users to monitor markets, execute trades, and discover arbitrage opportunities through a unified interface.

This tutorial will show you how to set up and use PolyClaw for automated prediction market trading, leveraging LLM to analyze logical relationships between events.

The video below provides a practical overview of PolyClaw’s setup and key features.

Key features of the Polymarket OpenClaw bot

Technical architecture of the OpenClaw bot

PolyClaw operates through a synergy of several APIs and blockchain components:

ComponentDescription
OpenClaw/MoltbotBase platform running the skill, can be hosted on any server (e.g., Mac Mini)
Polymarket Gamma APIUsed for reading market data, identifying trending topics, and retrieving market IDs
Chainstack Polygon RPCHandles on-chain transactions on Polygon mainnet, converting USDC into market tokens
Polymarket CLOB APIManages the off-chain Central Limit Order Book. When placing a bet, USDC is split into YES and NO tokens, and the unwanted side is automatically sold
OpenRouter APIConnects the system to LLMs (free models available) to perform arbitrage opportunity discovery

Installation and setup

Step 1: Install the OpenClaw bot skill

💡 Note: You can also clone directly from the GitHub repository if you prefer working with Git.

PolyClaw is a skill (workflow) for OpenClaw – a customizable AI agent platform. Each OpenClaw instance is unique to the user with their chosen set of skills. Recommended method – installation via ClawHub (official skill marketplace for OpenClaw):

clawhub install polyclawcd ~/.openclaw/skills/polyclawuv sync

Alternative method – manual installation:

cp -r polyclaw ~/.openclaw/skills/cd ~/.openclaw/skills/polyclawuv sync

Step 2: Obtain required credentials for OpenClaw bot access

PolyClaw requires three keys:

  1. Chainstack Polygon RPC endpoint: Sign up at Chainstack (free tier available, sign in with GitHub, X, or Google). Get the RPC URL for Polygon mainnet. Not sure how? We explained it here.
  2. OpenRouter API Key: Create a key at OpenRouter for LLM access
  3. EVM Private Key: Wallet private key in hex format (starts with 0x)

⚠️ IMPORTANT: Keep only small amounts in this wallet. Withdraw funds regularly to a secure wallet. Only trade with funds you can afford to lose.

Step 3: Configure the PolyClaw skill environment

Add the following settings to your openclaw.json file under skills.entries.polyclaw.env:

"polyclaw": {  "enabled": true,  "env": {    "CHAINSTACK_NODE": "https://polygon-mainnet.core.chainstack.com/YOUR_KEY",    "POLYCLAW_PRIVATE_KEY": "0x...",    "OPENROUTER_API_KEY": "sk-or-v1-..."  }}

Step 4: Enable trading (First-Time Setup)

Before your first trade, you must set Polymarket contract approvals (one-time operation, costs approximately 0.01 POL in gas):

uv run python scripts/polyclaw.py wallet approve

This command will submit 6 approval transactions to the Polygon network. You only need to do this once per wallet.

Step 5: Prepare funds for the Polymarket bot

The system requires bridged USDC (USDC.e) on the Polygon network:

How PolyClaw executes trades

Split + CLOB Mechanism

PolyClaw handles Polymarket’s Conditional Token Framework (CTF) automatically. When you buy a position, the skill:

Example of buying YES at $0.65:

Arbitrage logic in the PolyClaw skill

PolyClaw moves beyond traditional trading by searching for logical implications between disparate markets.

How the OpenClaw bot finds logical relationships

The LLM analyzes whether the outcome of Market A logically implies the outcome of Market B. For example, if ‘Candidate X wins the presidency’ logically implies ‘Party Y wins the Senate’, the system identifies this relationship.

Important: Only logically necessary implications are accepted. Simple correlations and ‘likely’ relationships are rejected by the system.

Coverage Tiers

TierCoverageDescription
Tier 1 (HIGH)≥95%Near-arbitrage, minimal risk
Tier 2 (GOOD)90-95%Strong hedging positions
Tier 3 (MODERATE)85-90%Decent but noticeable risk
Tier 4 (LOW)<85%Speculative (filtered by default)

Using the PolyClaw skill in practice

When using PolyClaw through OpenClaw bot, you interact with natural language. For example:

Advanced: Direct CLI Usage (for developers)

You can also interact directly with the skill scripts:

1. Browse trending markets:

uv run python scripts/polyclaw.py markets trending

2. Search markets by keyword:

uv run python scripts/polyclaw.py markets search "election"

3. Check wallet balance:

uv run python scripts/polyclaw.py wallet status

4. Buy a position:

uv run python scripts/polyclaw.py buy <market_id> YES 50

5. View positions:

uv run python scripts/polyclaw.py positions

Complete Workflow Example for PolyClaw skill

💻 Code Examples: For detailed code implementation and advanced examples, see the scripts directory in the GitHub repository.

Troubleshooting

Issue: CLOB order failed / IP blocked by Cloudflare

Polymarket’s CLOB API uses Cloudflare protection that blocks POST requests from many IP addresses. The solution is to use a rotating residential proxy with retry logic.

Recommended setup (IPRoyal or similar):

export HTTPS_PROXY="http://user:pass@geo.iproyal.com:12321"export CLOB_MAX_RETRIES=10

The CLOB client automatically retries with new IPs until finding an unblocked one. Typically succeeds within 5-10 attempts.

Issue: Hedge scan finds 0 results or spurious results

Model quality matters. The default nvidia/nemotron-nano-9b-v2:free works well. If using a different model, some may find spurious correlations (false positives), while others return empty responses. Try explicitly specifying the recommended model:

uv run python scripts/polyclaw.py hedge scan --model nvidia/nemotron-nano-9b-v2:free

Issue: Insufficient USDC.e

Check your balance – you need USDC.e (bridged USDC) on Polygon:

uv run python scripts/polyclaw.py wallet status

Important security warnings

Conclusion

PolyClaw represents a powerful tool for automated prediction market trading, combining blockchain technology and artificial intelligence capabilities. Using Chainstack infrastructure for Polygon network access, this skill opens new possibilities for discovering arbitrage situations based on logical relationships between events.

It’s important to remember that prediction market trading carries risks, and all code is provided ‘as-is’ without warranties. Always conduct your own research and trade responsibly.

Run trades, scan markets, and hedge with logic. All from your messenger.

Useful Resources

Exit mobile version