Package Exports
- polymarket-ctf-sdk
Readme
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
npm install polymarket-ctf-sdkQuick Start
Import SDK
import { split, merge } from 'polymarket-ctf-sdk';Split Operation
Split operation divides USDC into equal amounts of "Yes" and "No" outcome tokens.
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 pagenegRisk: Whether it's a negative risk market, check market details to determinerpcUrl: Blockchain network RPC node URLprivateKey: Wallet private keygasPrice: Gas price (optional, default 30 gwei)
Merge Operation
Merge operation combines "Yes" and "No" outcome tokens back to USDC.
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 amountconditionId: Market condition IDnegRisk: Whether it's a negative risk marketrpcUrl: Blockchain network RPC node URLprivateKey: Wallet private keygasPrice: Gas price (optional, default 30 gwei)
Negative Risk Market Example
// 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
- Visit the Polymarket API to view market details, for example: https://clob.polymarket.com/markets/0x8bf53bab21d7dfcd8f6c311c6f78d41678475e9184b6f16f5bbd5a9da3b1508b
- Check market details to confirm if it's a negative risk market
- Set the
negRiskparameter based on market type
How to Get My Private Key
- Log in to Polymarket via email
- 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:
- Import private key into wallet app (e.g., Metamask)
- Transfer Matic to this wallet
License
MIT License
Support
If you encounter issues during use, please check the example code or submit an issue.