Skip to main content
Fund the Perps account with pUSD before placing orders. Deposits move pUSD from the user’s Polymarket wallet into the Perps account. Withdrawals move available pUSD back to the authenticated wallet.

Deposit Collateral

Deposit pUSD when the account needs collateral for opening or maintaining Perps positions.
1

Create a Secure Client

Create a SecureClient for the wallet that will fund the Perps account. If you already have a Polymarket wallet, pass it as wallet and include a Relayer API key so the SDK can submit gasless transactions. If you are creating a wallet programmatically, use a Builder API key so the SDK can create the Deposit Wallet for that signer.
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!,
  }),
});
2

Set Up Deposit Approvals

Set up the approvals required for Perps collateral deposits. The SDK skips work that is already complete.
await client.setupTradingApprovals();
3

Deposit Collateral

Deposit pUSD from the user’s Polymarket wallet into the Perps account. Make sure the wallet has pUSD before depositing. The minimum Perps deposit is 10 pUSD. Amounts use raw pUSD base units, so 10 pUSD is 10_000_000n.
const deposit = await client.depositToPerps({
  amount: 10_000_000n,
});

const receipt = await deposit.wait();
// receipt.transactionHash: TxHash
deposit.wait() confirms that the chain transaction settled. Perps may take a moment to credit the account after that.
4

Verify the Deposit

Open a Perps session and read account state after the deposit settles.
const session = await client.openPerpsSession();

try {
  const portfolio = await session.fetchPortfolio();
  const deposits = await session.listDeposits().firstPage();
} finally {
  await session.close();
}
Use portfolio.withdrawable to check available collateral and deposits.items to reconcile deposit history.

Withdraw Collateral

Withdraw pUSD when the account has available collateral that should return to the authenticated wallet.
Request a withdrawal to the authenticated wallet. Amounts use raw pUSD base units, so 10 pUSD is 10_000_000n.
const withdrawalId = await client.withdrawFromPerps({
  amount: 10_000_000n,
});
The SDK signs the withdrawal request with the Polymarket account signer and returns the Perps withdrawal ID.To track the withdrawal, open a Perps session and list withdrawals.
const session = await client.openPerpsSession();

try {
  const withdrawals = await session.listWithdrawals().firstPage();
} finally {
  await session.close();
}
For more details on authenticated sessions, see Authenticated Sessions.

Review Funding History

Use deposit and withdrawal history to reconcile collateral movements after your integration submits funding requests. See Authenticated Sessions for how to create an authenticated session for private account history reads.
List deposit or withdrawal history from an authenticated Perps session.
import type { PerpsDeposit } from "@polymarket/client";

const session = await client.openPerpsSession();

try {
  const deposits: PerpsDeposit[] = [];

  for await (const page of session.listDeposits()) {
    deposits.push(...page.items);
  }
} finally {
  await session.close();
}