Integration Guide

How to integrate Yiling Protocol into your application.

Quick Start

1. Connect to the Contracts

import { ethers } from "ethers";

const provider = new ethers.JsonRpcProvider("https://testnet-rpc.monad.xyz");
const contract = new ethers.Contract(CONTRACT_ADDRESS, abi, provider);

2. Create a Market

const tx = await contract.createMarket(
  "Will ETH hit $10k by end of 2026?",  // question
  ethers.parseEther("0.2"),              // alpha (20% stop probability)
  2,                                      // k (last 2 get flat reward)
  ethers.parseEther("0.01"),             // flat reward
  ethers.parseEther("0.1"),              // bond amount
  ethers.parseEther("1.0"),              // liquidity param
  ethers.parseEther("0.5"),              // initial price (50%)
  { value: ethers.parseEther("1.0") }    // fund the market pool
);

3. Submit a Prediction

await contract.predict(
  0,                                     // market ID
  ethers.parseEther("0.72"),             // 72% probability
  { value: ethers.parseEther("0.1") }    // bond
);

4. Check Market Status & Claim

const info = await contract.getMarketInfo(0);
const payout = await contract.getPayoutAmount(0, myAddress);
await contract.claimPayout(0);

Using Foundry

export CONTRACT=YOUR_CONTRACT_ADDRESS
export RPC=https://testnet-rpc.monad.xyz

# Read market count
cast call $CONTRACT "getMarketCount()" --rpc-url $RPC

# Submit prediction (72%)
cast send $CONTRACT "predict(uint256,uint256)" 0 720000000000000000 \
  --value 0.1ether --private-key $KEY --rpc-url $RPC

Using web3.py

from web3 import Web3

w3 = Web3(Web3.HTTPProvider("https://testnet-rpc.monad.xyz"))
contract = w3.eth.contract(address=CONTRACT_ADDRESS, abi=abi)

count = contract.functions.getMarketCount().call()
info = contract.functions.getMarketInfo(0).call()

Integration Patterns

Pattern 1: Direct Interaction — Your frontend or bot calls Yiling contracts directly to create and participate in markets.

Pattern 2: Embedded Resolution — Your protocol uses Yiling as a resolution primitive. Your governance or dispute system calls the contracts to resolve questions.

Pattern 3: AI Agents — Build agents that participate in markets programmatically using any LLM or algorithm.