Polymarket
The world’s largest prediction market platform.
Builder Program
Official builder program documentation.
Polymarket builder code example repo
Official Next.js example with Privy authentication and Polymarket trading.
Getting started
1
Create a Privy app
Sign up at dashboard.privy.io and create an app.
2
Get builder credentials
Obtain your builder API key, secret, and passphrase from
Polymarket.
3
Get a Polygon RPC URL
Use any Polygon mainnet RPC provider (Alchemy, Infura, or a public RPC).
Setup
To get started, you’ll need to set up:- Privy authentication — Handles login and provisions embedded wallets
- Builder signing endpoint — Keeps your builder credentials secure server-side
- Polymarket clients — RelayClient for Safe operations, ClobClient for trading
.env.local:
npm run dev and open localhost:3000.
Integration steps
Step 1: Set up authentication
First, wrap your app withPrivyProvider and use Privy’s hooks to handle login. When users authenticate, Privy automatically provisions an embedded wallet:
Step 2: Configure the builder signing endpoint
Next, set up a server-side API route to keep your builder credentials secure. The example includes this atapp/api/polymarket/sign/route.ts.
This endpoint generates HMAC signatures for the RelayClient and ClobClient:
Step 3: Deploy a Safe wallet
Polymarket uses Gnosis Safe wallets for trading. Thehooks/useSafeDeployment.ts hook handles this.
First, derive the Safe address from the user’s EOA (this is deterministic—the same EOA always gets the same Safe):
Step 4: Get user API credentials
User API Credentials authenticate requests to the CLOB. Thehooks/useUserApiCredentials.ts hook handles this.
For new users, create credentials:
Step 5: Set token approvals
Before trading, the Safe must approve Polymarket’s contracts. Thehooks/useTokenApprovals.ts hook batches all approvals into a single transaction.
USDC.e (ERC-20) approvals for:
- CTF Contract:
0x4d97dcd97ec945f40cf65f87097ace5ea0476045 - CTF Exchange:
0x4bFb41d5B3570DeFd03C39a9A4D8dE6Bd8B8982E - Neg Risk Exchange:
0xC5d563A36AE78145C45a50134d48A1215220f80a - Neg Risk Adapter:
0xd91E80cF2E7be2e162c6513ceD06f1dD0dA35296
- CTF Exchange:
0x4bFb41d5B3570DeFd03C39a9A4D8dE6Bd8B8982E - Neg Risk Exchange:
0xC5d563A36AE78145C45a50134d48A1215220f80a - Neg Risk Adapter:
0xd91E80cF2E7be2e162c6513ceD06f1dD0dA35296
Step 6: Place an order
With the session initialized, place orders through the CLOB client:Troubleshooting
Privy authentication failed
Privy authentication failed
Verify
NEXT_PUBLIC_PRIVY_APP_ID is set correctly. Check that your domain is allowed in the
Privy dashboard.Failed to initialize relay client
Failed to initialize relay client
Check builder credentials in
.env.local. Verify the /api/polymarket/sign endpoint is
accessible.Safe deployment failed
Safe deployment failed
Ensure the Polygon RPC URL is valid. The user must approve the signature via Privy.
Token approval failed
Token approval failed
The Safe must be deployed first. Verify the builder relay service is operational.
Orders not appearing
Orders not appearing
Verify the trading session is complete and the Safe has a USDC.e balance. Wait 2-3 seconds for
CLOB sync.

