pnp-evm
v0.1.4
Published
EVM SDK for PNP Prediction Markets
Downloads
575
Readme
pnp-evm
The official TypeScript SDK for interacting with the PNP Prediction Market Protocol on EVM-compatible chains (defaulting to Base Mainnet).
This SDK provides a high-level abstraction over the smart contracts (PNPFactory, FeeManager), allowing developers to easily create markets, trade outcome tokens, and redeem winnings.
Features
- 🚀 Easy Integration: Simple methods for
createMarket,buy,sell, andredeem. - 🛡️ Robust: Built-in retry mechanisms and rate-limit handling for public RPCs.
- ⚡️ Base Ready: Pre-configured with official Base Mainnet contract addresses.
- 🔌 Flexible: Works with any EVM chain by providing custom contract addresses.
Installation
cd evm_pnp_sdk
npm install
npm run buildQuick Start
1. Initialize the Client
import { PNPClient } from "pnp-evm";
const client = new PNPClient({
// Optional: Defaults to "https://mainnet.base.org"
rpcUrl: process.env.RPC_URL,
// Required for transactions
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)
// collateralToken: "0x..." // Optional: Defaults to USDC on Base
});
console.log(`Market Created: ${conditionId}`);3. Trade (Buy/Sell)
// Buy "YES" shares
const buyAmount = ethers.parseUnits("10", 6); // 10 USDC
await client.trading.buy(conditionId, buyAmount, "YES");
// Sell "YES" shares
const sellAmount = ethers.parseUnits("5", 18); // 5 Outcome Tokens (18 decimals)
await client.trading.sell(conditionId, sellAmount, "YES");4. Fetch Market Info
const info = await client.market.getMarketInfo(conditionId);
console.log(info);
/* Output:
{
question: "Will ETH hit $5000 in 2025?",
endTime: "173...",
isCreated: true,
isSettled: false,
reserve: "1000000...",
winningToken: "0"
}
*/Configuration
The SDK comes pre-configured for Base Mainnet:
| Contract | Address |
|PO|---|
| Factory | 0x66177AC64968b348393Dd05b1664935947832D9E |
| FeeManager | 0xaA9C0a95b257588b9574fD9BfBf040309073bcA7 |
| USDC | 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913 |
To use a different chain or contracts:
const client = new PNPClient({
rpcUrl: "https://eth-mainnet.alchemyapi.io/...",
privateKey: "...",
contractAddresses: {
marketFactory: "0x...",
usdcToken: "0x...",
feeManager: "0x..."
}
});Development
- Build:
npm run build - Run Example:
export PRIVATE_KEY="your_key" npx ts-node examples/quickstart.ts
Error Handling
The SDK includes custom error parsing for common contract reverts (e.g., Invalid amount, Slippage protection). It also automatically handles "Rate Limit" errors from public RPC nodes by retrying read operations.
