pnp-monad
v1.0.1
Published
EVM SDK for PNP Prediction Markets on Monad
Maintainers
Readme
monad-sdk
The official TypeScript SDK for creating and trading prediction markets on Monad.
This SDK provides a high-level abstraction over the on-chain smart contracts (MarketFactory, FeeManager), enabling developers to programmatically create prediction markets, trade outcome tokens (YES/NO), and redeem winnings — all through a clean, typed interface.
Highlights
- One-line market creation — Spin up a fully on-chain prediction market with a single function call. Question, liquidity, deadline — done.
- Built on Monad — Harness 10,000 TPS and sub-second finality. No more waiting around for block confirmations on sluggish L1s.
- Permissionless and composable — Any developer, any agent, any bot can create markets, trade outcomes, and settle positions. No gatekeepers.
- Auto-pilot approvals — The SDK handles ERC20 allowance checks and approvals under the hood. You just say "buy" and it figures out the rest.
- Battle-tested AMM pricing — Built-in CPMM with real-time YES/NO price feeds. Market odds update live with every trade.
- Agent-ready architecture — Designed for AI agents to autonomously create and trade prediction markets.
npm install pnp-monadand let your agent loose. - Type-safe and zero-config — Full TypeScript support with pre-loaded Monad contract addresses. Import, initialize, ship.
- Open source, public npm — Install with
npm install pnp-monad. Fully open, fully auditable, no black boxes.
Installation
npm install pnp-monadQuick Start
1. Initialize the Client
import { PNPClient } from "pnp-monad";
const client = new PNPClient({
// Defaults to the Monad mainnet RPC if omitted
rpcUrl: process.env.RPC_URL,
// Required for any write operations (market creation, trading, redemption)
privateKey: process.env.PRIVATE_KEY,
});2. Create a Market
import { ethers } from "ethers";
const endTime = Math.floor(Date.now() / 1000) + 86400; // 24 hours from now
const { conditionId, receipt } = await client.market.createMarket({
question: "Will ETH hit $5000 in 2025?",
endTime: endTime,
initialLiquidity: "1000000", // 1 USDC (6 decimals)
});
console.log(`Market Created: ${conditionId}`);The createMarket method handles collateral approval automatically if the factory's allowance is insufficient.
3. Trade (Buy / Sell)
// Buy YES outcome tokens with 10 USDC
const buyAmount = ethers.parseUnits("10", 6);
await client.trading.buy(conditionId, buyAmount, "YES");
// Sell 5 YES outcome tokens back for collateral
const sellAmount = ethers.parseUnits("5", 18); // Outcome tokens use 18 decimals
await client.trading.sell(conditionId, sellAmount, "YES");Both buy and sell accept an optional minTokensOut / minCollateralOut parameter for slippage protection.
4. Fetch Market Info
const info = await client.market.getMarketInfo(conditionId);
console.log(info);Returns an object containing:
| Field | Description |
|---|---|
| question | The market's question string |
| endTime | Unix timestamp when trading closes |
| isCreated | Whether the market exists on-chain |
| isSettled | Whether the market has been resolved |
| reserve | Total collateral held in the market |
| collateral | Address of the collateral token |
| winningToken | Token ID of the winning outcome (0 if unsettled) |
5. Get Market Prices
const prices = await client.market.getMarketPrices(conditionId);
console.log(prices.yesPricePercent); // e.g. "70.00%"
console.log(prices.noPricePercent); // e.g. "30.00%"6. Redeem Winnings
After a market is settled, holders of the winning outcome token can redeem their collateral:
const isResolved = await client.redemption.isResolved(conditionId);
if (isResolved) {
await client.redemption.redeem(conditionId);
}Configuration
The SDK ships with default contract addresses for Monad:
| Contract | Address |
|---|---|
| Factory | 0xDD5975B6D29C73e9e68FF128c1B5B4244986CF66 |
| FeeManager | 0x9ac2dc5fB9a6b95CA9dEa27063f10e09e55fEfFa |
| Collateral | 0x350035555E10d9AfAF1566AaebfCeD5BA6C27777 |
To override the defaults (e.g. for a different chain or custom deployment):
const client = new PNPClient({
rpcUrl: "https://your-rpc-url.com",
privateKey: "...",
contractAddresses: {
marketFactory: "0x...",
usdcToken: "0x...",
feeManager: "0x...",
},
});Development
- Build the SDK:
npm run build - Run the example script:
export PRIVATE_KEY="your_hex_private_key" npx ts-node examples/quickstart.ts
Error Handling
The SDK includes custom error parsing for common contract reverts such as InvalidMarketEndTime, MarketTradingStopped, InvalidAddress, and InvalidTokenId. Read operations automatically retry on RPC rate-limit errors with exponential backoff (up to 5 attempts).
