Skip to main content

Installation

npm install @polymarket/clob-client ethers

Quick Start

1. Setup Client

import { ClobClient } from "@polymarket/clob-client";
import { Wallet } from "ethers"; // v5.8.0

const HOST = "https://clob.polymarket.com";
const CHAIN_ID = 137; // Polygon mainnet
const signer = new Wallet(process.env.PRIVATE_KEY);

// Create or derive user API credentials
const tempClient = new ClobClient(HOST, CHAIN_ID, signer);
const apiCreds = await tempClient.createOrDeriveApiKey();

// See 'Signature Types' note below
const signatureType = 0;

// Initialize trading client
const client = new ClobClient(
  HOST, 
  CHAIN_ID, 
  signer, 
  apiCreds, 
  signatureType
);
This quick start sets your EOA as the trading account. You’ll need to fund this wallet to trade and pay for gas on transactions. Gas-less transactions are only available by deploying a proxy wallet and using Polymarket’s Polygon relayer infrastructure.
Wallet TypeIDWhen to Use
EOA0Standard Ethereum wallet (MetaMask)
Custom Proxy1Specific to Magic Link users from Polymarket only
Gnosis Safe2Injected providers (Metamask, Rabby, embedded wallets)

2. Place an Order

import { Side } from "@polymarket/clob-client";

// Place a limit order in one step
const response = await client.createAndPostOrder({
  tokenID: "YOUR_TOKEN_ID", // Get from Gamma API
  price: 0.65, // Price per share
  size: 10, // Number of shares
  side: Side.BUY, // or SELL
});

console.log(`Order placed! ID: ${response.orderID}`);

3. Check Your Orders

// View all open orders
const openOrders = await client.getOpenOrders();
console.log(`You have ${openOrders.length} open orders`);

// View your trade history
const trades = await client.getTrades();
console.log(`You've made ${trades.length} trades`);

Complete Example

import { ClobClient, Side } from "@polymarket/clob-client";
import { Wallet } from "ethers";

async function trade() {
  const HOST = "https://clob.polymarket.com";
  const CHAIN_ID = 137; // Polygon mainnet
  const signer = new Wallet(process.env.PRIVATE_KEY);

  const tempClient = new ClobClient(HOST, CHAIN_ID, signer);
  const apiCreds = await tempClient.createOrDeriveApiKey();

  const signatureType = 0;

  const client = new ClobClient(
    HOST,
    CHAIN_ID,
    signer,
    apiCreds,
    signatureType
  );

  const response = await client.createAndPostOrder({
    tokenID: "YOUR_TOKEN_ID",
    price: 0.65,
    size: 10,
    side: Side.BUY,
  });

  console.log(`Order placed! ID: ${response.orderID}`);
}

trade();

Troubleshooting

You forgot to call createOrDeriveApiKey(). Make sure you initialize the client with API credentials:
const creds = await clobClient.createOrDeriveApiKey();
const client = new ClobClient(host, chainId, wallet, creds);
Ensure you have:
  • USDC in your funder address for BUY orders
  • Outcome tokens in your funder address for SELL orders
Check your balance at polymarket.com/portfolio.
You need to approve the Exchange contract to spend your tokens. This is typically done through the Polymarket UI on your first trade. Or use the CTF contract’s setApprovalForAll() method.
Your funder address is the Polymarket proxy wallet where you deposit funds. Find it:
  1. Go to polymarket.com/settings
  2. Look for “Wallet Address” or “Profile Address”
  3. This is your FUNDER_ADDRESS

Next Steps