UNPKG

polymarket-ctf-sdk

Version:

Interacting with Polymarket Conditional Tokens Framework

123 lines (90 loc) 4.08 kB
# Polymarket CTF SDK > ⚠️ **Warning**: This is NOT an official Polymarket repository. A JavaScript/TypeScript SDK for interacting with the Polymarket Conditional Tokens Framework (CTF), supporting split and merge operations through proxy wallets. ## Features - 🔄 **Split Operations**: Split USDC into "Yes" and "No" outcome tokens - 🔗 **Merge Operations**: Merge "Yes" and "No" outcome tokens back to USDC - 🛡️ **Proxy Wallet Support**: Secure transactions through proxy wallet factory - **Negative Risk Market Support**: Special handling for negative risk markets - 🔧 **TypeScript Support**: Complete type definitions ## Installation ```bash npm install polymarket-ctf-sdk ``` ## Quick Start ### Import SDK ```typescript import { split, merge } from 'polymarket-ctf-sdk'; ``` ### Split Operation Split operation divides USDC into equal amounts of "Yes" and "No" outcome tokens. ```typescript import { split } from 'polymarket-ctf-sdk'; // Split 1 USDC into equal amounts of "Yes" and "No" tokens await split({ splitAmount: "1", // Amount of USDC to split conditionId: "0x8bf53bab21d7dfcd8f6c311c6f78d41678475e9184b6f16f5bbd5a9da3b1508b", // Market condition ID negRisk: false, // Whether it's a negative risk market rpcUrl: "https://polygon-rpc.com", // RPC node URL privateKey: "your-private-key", // Wallet private key gasPrice: 30000000000 // Gas price (optional, default 30 gwei) }); ``` **Parameter Description:** - `splitAmount`: Amount of USDC to split (string format) - `conditionId`: Market condition ID, can be obtained from Polymarket market page - `negRisk`: Whether it's a negative risk market, check market details to determine - `rpcUrl`: Blockchain network RPC node URL - `privateKey`: Wallet private key - `gasPrice`: Gas price (optional, default 30 gwei) ### Merge Operation Merge operation combines "Yes" and "No" outcome tokens back to USDC. ```typescript import { merge } from 'polymarket-ctf-sdk'; // Merge 0.5 "Yes" and 0.5 "No" tokens to get 1 USDC await merge({ mergeAmount: "1", // Amount of tokens to merge (corresponds to final USDC amount) conditionId: "0x8bf53bab21d7dfcd8f6c311c6f78d41678475e9184b6f16f5bbd5a9da3b1508b", // Market condition ID negRisk: false, // Whether it's a negative risk market rpcUrl: "https://polygon-rpc.com", // RPC node URL privateKey: "your-private-key", // Wallet private key gasPrice: 30000000000 // Gas price (optional, default 30 gwei) }); ``` **Parameter Description:** - `mergeAmount`: Amount of tokens to merge, corresponding to final USDC amount - `conditionId`: Market condition ID - `negRisk`: Whether it's a negative risk market - `rpcUrl`: Blockchain network RPC node URL - `privateKey`: Wallet private key - `gasPrice`: Gas price (optional, default 30 gwei) ### Negative Risk Market Example ```typescript // For negative risk markets, set negRisk to true await split({ splitAmount: "1", conditionId: "your-condition-id", negRisk: true, // Negative risk market rpcUrl: "https://polygon-rpc.com", privateKey: "your-private-key" }); ``` ## Important Notes ### How to Determine the negRisk Parameter 1. Visit the Polymarket API to view market details, for example: https://clob.polymarket.com/markets/0x8bf53bab21d7dfcd8f6c311c6f78d41678475e9184b6f16f5bbd5a9da3b1508b 2. Check market details to confirm if it's a negative risk market 3. Set the `negRisk` parameter based on market type ### How to Get My Private Key 1. Log in to Polymarket via email 2. Export private key from user settings page ### Account Funding You can fund your account with USDC through the website interface ### Funding Gas (Matic) Since this directly interacts with contracts, using SDK methods requires gas consumption Methods to fund Matic: 1. Import private key into wallet app (e.g., Metamask) 2. Transfer Matic to this wallet ## License MIT License ## Support If you encounter issues during use, please check the example code or submit an issue.