rs-builder-relayer-client
Rust SDK for Polymarket's gasless relayer. Redeem positions, approve tokens, split/merge — zero gas.
30-Second Quickstart
&&
Create .env:
PRIVATE_KEY=0x...
BUILDER_KEY=...
BUILDER_SECRET=...
BUILDER_PASSPHRASE=...
# Optional: Use Alchemy or QuickNode for Direct Fallback. Default polygon-rpc.com is unstable.
POLYGON_RPC_URL=https://...
src/main.rs:
use ;
async
Getting Your Credentials
| Credential | Where |
|---|---|
PRIVATE_KEY |
Your Polygon wallet private key (MetaMask > Account Details > Export) |
| Relayer API key | polymarket.com/settings > Relayer API Keys (anyone) |
No Builder keys? Use AuthMethod::relayer_key("key", "address") instead — same features, simpler setup.
Install
[]
= "0.1"
= "2"
= { = "1", = ["full"] }
= "1"
= "0.15"
= "0.4"
Redeem Example
Add CONDITION_ID=0x... to your .env, then:
use ;
async
API
| Operation | Code |
|---|---|
| Redeem regular position | operations::redeem_regular(condition_id, &[1, 2]) |
| Redeem neg-risk position | operations::redeem_neg_risk_positions(condition_id, &[1, 2]) |
| Approve USDC for exchange | client.setup_approvals() |
| Deploy Safe wallet | client.deploy() |
| Split USDC into tokens | operations::split_regular(cid, &[1, 2], amount) |
| Merge tokens back to USDC | operations::merge_regular(cid, &[1, 2], amount) |
| Execute single/multiple ops | client.execute(vec![tx1], "desc") |
| Execute true multi-send batch | client.execute_batch(vec![tx1, tx2], "desc") |
| Execute chunks sequentially | client.execute_sequential(vec![vec![tx1], vec![tx2]], None, None) |
| Direct on-chain fallback | DirectExecutor::new(rpc_url, wallet, 137)? |
Auth
// Builder API keys (HMAC — enables gasless)
builder
// Relayer API keys (from polymarket.com/settings > API Keys)
relayer_key
Direct Fallback (when relayer returns 429)
Warning: Do not use
https://polygon-rpc.com/as your RPC URL — it frequently causes TLS handshake EOF errors and connection resets, especially under load. Use a dedicated provider instead:
use ;
let rpc_url = var
.expect;
// Safe wallet (signature_type=2, default)
let direct = new?;
// Proxy wallet (signature_type=1, e.g. magic.link)
let direct = new_proxy?;
// Proxy with explicit address (when derived address differs)
let direct = new_proxy_with_address?;
match client.execute.await
Batching & Execution Strategies
Depending on whether you use RelayerTxType::Safe or RelayerTxType::Proxy, the SDK provides several execution models:
-
client.execute/client.execute_batch:- Safe Wallets: Uses official Gnosis
MultiSendcontracts. Multiple operations are packed tightly into a single transaction. Safe is highly durable and recommended for heavy batching (> 2 operations). - Proxy Wallets: While the OpenGSN proxy supports a
(uint8, address, uint256, bytes)[]array structure, the Polymarket relayer bot imposes strict total-transaction gas limits top-level. Batching more than 2 operations with Proxy wallets is highly discouraged and might hit silentrelay hub: internal transaction failureerrors due to gas starvation. The SDK dynamically scales requests up to a hard cap of 400K gas.
- Safe Wallets: Uses official Gnosis
-
client.execute_sequential: Designed purely to circumvent Proxy Relayer bottlenecks when you have e.g. 10 positions to redeem. It executes batches step-by-step, patiently awaitingSTATE_CONFIRMEDto prevent nonce collisions and OpenGSN RelayHub deadlocks across Gelato's relayer pools.
Examples
References
Donate
Ethereum / Polygon: 0xF4c6635dFfB53f21c500c1604EC284f8A8a7150D