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) |
| Batch multiple ops | client.execute(vec![tx1, tx2], "desc") |
| 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
Examples
References
Donate
Ethereum / Polygon: 0xF4c6635dFfB53f21c500c1604EC284f8A8a7150D