September 8, 2026·1 min read·Dr. Alex Vance, Head of Smart Contracts
Building Autonomous Trading and Arbitrage Bots with the PredictWin Smart Contract
Complete developer tutorial with ethers.js and viem: listen to on-chain market events, calculate real-time parimutuel odds, and execute programmatic trades.
developersbotsethersjstypescripttutorial
1. The Automation Imperative
While human traders sleep, crypto markets operate around the clock. By interacting directly with the PredictWinV2 contract on Robinhood Testnet via RPC, developers can build low-latency algorithmic trading bots that monitor price shifts and execute predictions automatically.
2. Connecting via Ethers.js v6
import { ethers } from "ethers";
const RPC_URL = "https://rpc.testnet.chain.robinhood.com";
const CONTRACT_ADDRESS = "0xaE9D5D86405120510Ef8692E3065B60B7EEB9fa8";
const PREDICT_WIN_ABI = [
"function getMarket(uint256 marketId) external view returns (tuple(uint256 id, string tokenAddress, string tokenSymbol, string tokenName, uint256 targetPriceUsd, uint256 expiryTimestamp, uint256 poolYes, uint256 poolNo, address creator, uint8 status, uint8 outcome))",
"function predictFromBalance(uint256 marketId, uint256 eventId, uint8 side, uint256 amount) external",
"function userBalance(address user) external view returns (uint256)",
"event Predicted(uint256 indexed marketId, address indexed user, uint8 side, uint256 amount)"
];
const provider = new ethers.JsonRpcProvider(RPC_URL);
const wallet = new ethers.Wallet(process.env.BOT_PRIVATE_KEY!, provider);
const contract = new ethers.Contract(CONTRACT_ADDRESS, PREDICT_WIN_ABI, wallet);
3. Executing Trades Directly from Internal Balance
Because the bot pre-funds its internal balance with deposit(), execution requires zero token approvals and incurs no token transfer overhead:
const tx = await contract.predictFromBalance(marketId, 0, 1, ethers.parseEther("0.05"));
await tx.wait();
console.log("Automated trade successfully executed on Robinhood Testnet!");