Skip to main content

Overview

The Relayer Client routes onchain transactions through Polymarket’s infrastructure, providing gasless transactions for your users. Builder authentication is required to access the relayer.

Gasless Transactions

Polymarket pays all gas fees

Wallet Deployment

Deploy Safe or Proxy wallets

CTF Operations

Split, merge, and redeem positions

Builder API Credentials

Each builder receives API credentials from their Builder Profile:
CredentialDescription
keyYour builder API key identifier
secretSecret key for signing requests
passphraseAdditional authentication passphrase
Security Notice: Your Builder API keys must be kept secure. Never expose them in client-side code.

Installation

npm install @polymarket/builder-relayer-client

Relayer Endpoint

All relayer requests are sent to Polymarket’s relayer service on Polygon:
https://relayer-v2.polymarket.com/

Signing Methods


Authentication Headers

The SDK automatically generates and attaches these headers to each request:
HeaderDescription
POLY_BUILDER_API_KEYYour builder API key
POLY_BUILDER_TIMESTAMPUnix timestamp of signature creation
POLY_BUILDER_PASSPHRASEYour builder passphrase
POLY_BUILDER_SIGNATUREHMAC signature of the request
With local signing, the SDK constructs and attaches these headers automatically. With remote signing, your server must return these headers (see Server Implementation above), and the SDK attaches them to the request.

Wallet Types

Choose your wallet type before using the relayer:
Gnosis Safe-based proxy wallets that require explicit deployment before use.
  • Best for: Most builder integrations
  • Deployment: Call client.deploy() before first transaction
  • Gas fees: Paid by Polymarket
const client = new RelayClient(
  "https://relayer-v2.polymarket.com", 
  137,
  eoaSigner, 
  builderConfig, 
  RelayerTxType.SAFE  // Default
);

// Deploy before first use
const response = await client.deploy();
const result = await response.wait();
console.log("Safe Address:", result?.proxyAddress);
FeatureSafe WalletsProxy Wallets
DeploymentExplicit deploy()Auto-deploy on first tx
Gas FeesPolymarket paysPolymarket pays
ERC20 Approvals
CTF Operations
Send Transactions

Usage

Deploy a Wallet

For Safe wallets, deploy before executing transactions:
const response = await client.deploy();
const result = await response.wait();

if (result) {
  console.log("Safe deployed successfully!");
  console.log("Transaction Hash:", result.transactionHash);
  console.log("Safe Address:", result.proxyAddress);
}

Execute Transactions

The execute method sends transactions through the relayer. Pass an array of transactions to batch multiple operations in a single call.
interface Transaction {
  to: string;    // Target contract or wallet address
  data: string;  // Encoded function call (use "0x" for simple transfers)
  value: string; // Amount of MATIC to send (usually "0")
}

const response = await client.execute(transactions, "Description");
const result = await response.wait();

if (result) {
  console.log("Transaction confirmed:", result.transactionHash);
}

Transaction Examples

Transfer tokens to any address (e.g., withdrawals):
import { encodeFunctionData, parseUnits } from "viem";

const transferTx = {
  to: "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174", // USDCe
  data: encodeFunctionData({
    abi: [{
      name: "transfer",
      type: "function",
      inputs: [
        { name: "to", type: "address" },
        { name: "amount", type: "uint256" }
      ],
      outputs: [{ type: "bool" }]
    }],
    functionName: "transfer",
    args: [
      "0xRecipientAddressHere",
      parseUnits("100", 6) // 100 USDCe (6 decimals)
    ]
  }),
  value: "0"
};

const response = await client.execute([transferTx], "Transfer USDCe");
await response.wait();

Reference

Contracts & Approvals

ContractAddressUSDCeOutcome Tokens
USDCe0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174
CTF0x4d97dcd97ec945f40cf65f87097ace5ea0476045
CTF Exchange0x4bFb41d5B3570DeFd03C39a9A4D8dE6Bd8B8982E
Neg Risk CTF Exchange0xC5d563A36AE78145C45a50134d48A1215220f80a
Neg Risk Adapter0xd91E80cF2E7be2e162c6513ceD06f1dD0dA35296

Transaction States

StateDescription
STATE_NEWTransaction received by relayer
STATE_EXECUTEDTransaction executed onchain
STATE_MINEDTransaction included in a block
STATE_CONFIRMEDTransaction confirmed (final ✅)
STATE_FAILEDTransaction failed (terminal ❌)
STATE_INVALIDTransaction rejected as invalid (terminal ❌)

TypeScript Types

// Transaction type used in all examples
interface Transaction {
  to: string;
  data: string;
  value: string;
}

// Wallet type selector
enum RelayerTxType {
  SAFE = "SAFE",
  PROXY = "PROXY"
}

// Transaction states
enum RelayerTransactionState {
  STATE_NEW = "STATE_NEW",
  STATE_EXECUTED = "STATE_EXECUTED",
  STATE_MINED = "STATE_MINED",
  STATE_CONFIRMED = "STATE_CONFIRMED",
  STATE_FAILED = "STATE_FAILED",
  STATE_INVALID = "STATE_INVALID"
}

// Response from relayer
interface RelayerTransaction {
  transactionID: string;
  transactionHash: string;
  from: string;
  to: string;
  proxyAddress: string;
  data: string;
  state: string;
  type: string;
  metadata: string;
  createdAt: Date;
  updatedAt: Date;
}

Next Steps