Skip to main content
This guide walks through the shortest safe path to a first Perps trade. You will set up a Perps account, add collateral, and place a small buy order. You need a Polymarket account with pUSD available before you start. Create one at polymarket.com.
Building directly against the API? Start with Authenticated Sessions, then use Fund Your Account and Trading.
1

Install the SDK

Install the Unified TypeScript SDK with the package manager of your choice.
pnpm add @polymarket/client@beta viem
This page uses Viem for wallet signing. See the TypeScript tooling guide for other wallet library integrations.
2

Create a Secure Client

Create a SecureClient with the wallet and signer that owns the Perps account. Include a Relayer API key so the SDK can submit gasless transactions.
import { createSecureClient, relayerApiKey } from "@polymarket/client";
import { privateKey } from "@polymarket/client/viem";

const client = await createSecureClient({
  wallet: process.env.POLYMARKET_WALLET_ADDRESS!,
  signer: privateKey(process.env.PRIVATE_KEY!),
  apiKey: relayerApiKey({
    key: process.env.RELAYER_API_KEY!,
    address: process.env.RELAYER_API_KEY_ADDRESS!,
  }),
});
Create a Relayer API key from polymarket.com → Settings → API Keys.
3

Fund the Account

Set up the approvals required for Perps collateral deposits, then deposit pUSD from the user’s Polymarket wallet into the Perps account. The minimum Perps deposit is 10 pUSD. Amounts use raw pUSD base units, so 10 pUSD is 10_000_000n.
await client.setupTradingApprovals();

const deposit = await client.depositToPerps({
  amount: 10_000_000n,
});

await deposit.wait();
deposit.wait() confirms that the chain transaction settled. Perps may take a moment to credit the account after that. See Fund Your Account for the full funding workflow.
4

Open a Perps Session

Open a Perps session for private reads and trading.
const session = await client.openPerpsSession();
5

Choose a Market

Fetch the available Perps instruments and choose the market you want to trade.
const instruments = await client.fetchPerpsInstruments();
const instrument = instruments.find(
  (instrument) => instrument.symbol === "SP500-USD",
);

if (instrument === undefined) {
  throw new Error("Instrument not found.");
}
6

Place the Order

Place a long buy order for 1 quantity unit of SP500-USD with an explicit limit price of 100 USD per quantity unit and immediate-or-cancel execution.
import { OrderSide, PerpsTimeInForce } from "@polymarket/client";

const order = await session.placeOrder({
  instrumentId: instrument.id,
  side: OrderSide.BUY,
  quantity: "1",
  price: "100",
  timeInForce: PerpsTimeInForce.IOC,
});

// order.id: PerpsOrderId
The returned order includes the accepted order state. See Trading for direction, order behavior, cancellation, and state reconciliation.