SecureClient, and understanding the three-layer auth model that protects your orders and on-chain funds.
Set the environment variable
The SDK reads your private key from thePOLYMARKET_PRIVATE_KEY environment variable. Export it in your shell before running any example or binary:
Build a SecureClient
SecureClient is the authenticated entry point for all trading and account operations. Call .build().await and the SDK will sign the derivation request on your behalf:
setup_trading_approvals submits the one-time on-chain approval transactions that allow the CLOB exchange to settle your orders. You only need to call this once per wallet.
How authentication works
The SDK operates across three distinct layers, each with its own signing mechanism:L1 — API key derivation
When you call
.build(), the SDK performs an EIP-712 signature with your private key to derive — or retrieve — a CLOB API credential set (key, secret, and passphrase). This happens once and does not require a blockchain transaction.L2 — HMAC-signed REST requests
Every authenticated REST call (placing orders, reading account data) is signed with HMAC using your derived API credentials. Your private key is never sent over the wire.
Proxy and email wallets
If your Polymarket account was created through the Magic (proxy) wallet flow — for example via email login — you need two extra builder options:.funder(proxy_address)— sets the address that holds your USDC and outcome tokens, when it differs from the signing wallet..signature_type(...)— selects the EIP-712 signing variant that matches your wallet type.
Reuse credentials to skip re-derivation
Deriving credentials requires an HTTPS round-trip on everybuild() call. In production you should persist the returned ApiCredentials and pass them back on subsequent starts:
.credentials(...) is provided, the SDK skips the derivation request entirely and uses the cached values directly, reducing startup latency and avoiding unnecessary API calls.
