Burn all redeemable conditional tokens in return for collateral on Polymarket for Proxy Wallet using Polymarket Relayer Client for gasless redemption.
Start the server to expose an HTTP endpoint that the Go backend can call:
# Install dependencies (first time only)
npm install
# Start the server
npm run server
# or
npm startThe server will start on port 3000 (or the port specified in PORT environment variable).
GET /health- Health check (no authentication required)POST /redeem- Redeem positions (requires API key authentication)
The /redeem endpoint requires API key authentication. Include the API key in one of these ways:
- Header:
X-API-Key: your-api-key - Header:
Authorization: Bearer your-api-key
{
"userAddress": "0x..."
}Success:
{
"success": true,
"message": "Successfully redeemed 2 position(s)",
"txHash": "0x...",
"transactions": [...]
}Error:
{
"success": false,
"error": "Error message"
}Create a .env file with the following variables:
PORT- Server port (default: 3000)API_KEY- API key for authenticating requestsRELAYER_URL- Polymarket relayer URLCHAIN_ID- Polygon chain ID (137 for mainnet)RPC_URL- Polygon RPC endpointPROXY_WALLET- Your Polymarket proxy wallet addressPK- Private key for the walletBUILDER_API_KEY- Polymarket Builder API keyBUILDER_SECRET- Polymarket Builder API secretBUILDER_PASS_PHRASE- Polymarket Builder API passphraseUSDC_ADDRESS- USDC token address on PolygonCTF_ADDRESS- Conditional Token Framework address
Run the redeem script directly (uses PROXY_WALLET from environment):
npm run redeemTo use this service from the Go backend, set these environment variables in your Go backend .env:
# Base URL (without endpoint path - the code will append /redeem automatically)
REDEEM_PROXY_URL=http://localhost:3000
REDEEM_PROXY_API_KEY=your-api-key-hereImportant: REDEEM_PROXY_URL should be the base URL only (e.g., http://localhost:3000), not the full endpoint path. The Go client will automatically append /redeem or /health as needed.
The Go backend will automatically use the proxy service if REDEEM_PROXY_URL is configured, otherwise it will fall back to direct CLOB client usage.