Overview
The linking flow has two steps for EOA wallets, and three steps for Safe wallets that need allowances:- Prepare - Server generates an EIP-712 payload for the user to sign
- Complete - User signs the payload, server derives Polymarket credentials
- Set Allowances (Safe wallets only) - Sign and submit allowance transaction
Streamlined Flow for Fresh Safes: When a Safe is deployed during
/link-complete, the response includes safeTxPayload and allowancesToSet. You can sign the messageHash directly and call /link-set-allowances - no need to call /link-set-allowances-prepare.When to Use Direct Endpoints vs SDK
SDK Examples
The SDK handles the two-step flow automatically with a singlelinkUser() call.
EOA Wallet (Privy Embedded)
Safe Wallet (External Wallets)
Direct Endpoint Examples
Use the direct endpoints when you need control over the signing step, such as in TEE environments or mobile apps with on-device signing.Endpoint URLs
Headers
All requests require:Step 1: Prepare Session
POST /v1/polymarket/link-prepare
Request the EIP-712 payload that the user needs to sign.
Success Response:
safeInfo):
safeDeployPayload):
When walletType: "safe", autoDeploySafe: true, and the Safe is not yet deployed, the response includes an additional EIP-712 payload for deploying the Safe wallet:
When
safeDeployPayload is present, you must sign both eip712Payload (for credentials) and safeDeployPayload (for Safe deployment), then include both signatures in the /link-complete request.Step 2: Sign the EIP-712 Payload(s)
Sign theeip712Payload using your wallet. The exact method depends on your environment:
safeDeployPayload was returned in the prepare response, you must also sign it to authorize Safe deployment:
Step 3: Complete Session
POST /v1/polymarket/link-complete
Submit the signature to derive Polymarket credentials.
Success Response:
safeAddress):
deploymentSignature was provided and the Safe was deployed during this request:
Streamlined Flow: When
safeTxPayload is present, you can sign safeTxPayload.messageHash directly using signMessage (eth_sign) and call /link-set-allowances without calling /link-set-allowances-prepare. This is possible because freshly deployed Safes have nonce=0.Set Allowances (Safe Wallets Only)
For Safe wallets, USDC allowances must be set before trading. There are two ways to set allowances:- Streamlined Flow (recommended for fresh Safes): When
/link-completereturnssafeTxPayload, sign themessageHashdirectly and call/link-set-allowances - Standard Flow: Call
/link-set-allowances-prepareto get the SafeTx payload, then sign and submit
Streamlined Flow (Fresh Safes)
When the Safe was just deployed (nonce=0),/link-complete returns safeTxPayload with the messageHash to sign:
Standard Flow (Existing Safes)
For Safes that already exist (not freshly deployed), use/link-set-allowances-prepare to get the SafeTx payload.
Step 1: Prepare Allowances (Standard Flow)
POST /v1/polymarket/link-set-allowances-prepare
Get the SafeTx payload that the user needs to sign.
Success Response:
If
allowancesToSet is empty, all allowances are already set. You can skip the signing and submission steps.Step 2: Sign the SafeTx Hash
Sign themessageHash from the prepare response using eth_sign (personal sign). This is different from EIP-712 signing - you sign the hash directly as a message.
Step 3: Submit Allowances
POST /v1/polymarket/link-set-allowances
Submit the signature to execute the allowance transactions on-chain.
Success Response:
Complete Direct Endpoint Example
Full example for TEE/mobile environments:Safe Wallet with Auto-Deploy Example (Privy)
Full example for Safe wallets that need to be deployed using Privy managed wallets:Health Check
GET /v1/polymarket/link-health
Check the link service status.
Error Handling
Error Codes
Error Response Example
Handling Errors
Session Lifecycle
- Incomplete sessions expire after 10 minutes
- Completed sessions are kept for 30 minutes (for
/v1/polymarket/link-set-allowances) - Each session can only be completed once via
/v1/polymarket/link-complete - After successful
/v1/polymarket/link-complete, the session remains available for/v1/polymarket/link-set-allowances - If a session expires, call
/v1/polymarket/link-prepareagain to start a new session
Security Considerations
- Store credentials securely - Encrypt
apiSecretandapiPassphraseat rest - Session IDs are single-use - Cannot replay
/v1/polymarket/link-completewith same sessionId - Signature verification - Server verifies the signature matches the wallet address
- No private keys transmitted - Only the signature is sent to the server