polyoxide-relay
Rust client library for Polymarket Relayer API.
The Relay API enables submitting gasless on-chain transactions through Polymarket's relayer service on Polygon. The relayer pays gas fees on behalf of users, supporting two wallet types:
- Safe wallets -- Gnosis Safe multisig contracts (must be deployed before first use)
- Proxy wallets -- lightweight proxy contracts that auto-deploy on first transaction
More information about this crate can be found in the crate documentation.
Installation
[]
= "0.12"
Or use the unified client:
[]
= { = "0.12", = ["full"] }
Authentication
Relay operations require a private key for EIP-712 transaction signing and one of two authentication schemes for relay submission:
Builder API Credentials (HMAC-SHA256)
use ;
let config = new;
let account = new?;
let client = from_account?;
Relayer API Key (static headers)
use ;
let account = with_relayer_api_key?;
let client = from_account?;
Usage
Builder Pattern
use ;
let config = new;
let account = new?;
let client = builder?
.with_account
.wallet_type
.chain_id // Polygon mainnet (default)
.max_concurrent
.build?;
Or pull settings from environment variables (RELAYER_URL, CHAIN_ID):
let client = default_builder?
.with_account
.build?;
Gasless Redemption
use U256;
let condition_id = ; // your condition ID
let index_sets = vec!;
let response = client
.submit_gasless_redemption
.await?;
println!;
Gasless Redemption with Gas Estimation
let response = client
.submit_gasless_redemption_with_gas_estimation
.await?;
Execute Arbitrary Transactions
use SafeTransaction;
use ;
let tx = SafeTransaction ;
let response = client.execute.await?;
Query Operations (no auth required)
use Address;
// Check Safe deployment status
let deployed = client.get_deployed.await?;
// Fetch current nonce
let nonce = client.get_nonce.await?;
// Query transaction status
let status = client.get_transaction.await?;
println!;
// Measure API latency
let latency = client.ping.await?;
println!;
Wallet Address Derivation
// Derive expected Safe address via CREATE2
let safe_address = client.get_expected_safe?;
// Derive expected Proxy wallet address via CREATE2
let proxy_address = client.get_expected_proxy_wallet?;
Environment Variables
| Variable | Description |
|---|---|
POLYMARKET_PRIVATE_KEY |
Hex-encoded private key for EIP-712 signing |
BUILDER_API_KEY |
Builder API key (HMAC auth) |
BUILDER_SECRET |
Builder API secret (HMAC auth) |
BUILDER_PASS_PHRASE |
Builder API passphrase (HMAC auth, optional) |
RELAYER_API_KEY |
Relayer API key (static auth) |
RELAYER_API_KEY_ADDRESS |
Address associated with relayer API key |
RELAYER_URL |
Custom relayer URL (default: https://relayer-v2.polymarket.com) |
CHAIN_ID |
Target chain ID (default: 137 for Polygon mainnet) |
API Coverage
- Transaction Submission: Sign and submit gasless transactions via Safe or Proxy wallets
- Gasless Redemptions: Redeem CTF positions without holding MATIC
- Gas Estimation: Simulate redemptions against Polygon RPC for accurate gas limits
- Nonce Management: Fetch current nonce from the relayer
- Deployment Check: Verify whether a Safe wallet is deployed on-chain
- Transaction Status: Query the state of submitted relay transactions
- Wallet Derivation: Compute expected Safe and Proxy wallet addresses via CREATE2
- Multi-Send Batching: Automatically batch multiple transactions via Gnosis Safe MultiSend
Supported Chains
| Chain | ID | Notes |
|---|---|---|
| Polygon mainnet | 137 | Full support (Safe + Proxy) |
| Amoy testnet | 80002 | Safe only (Proxy not available) |
License
Licensed under either of MIT or Apache-2.0 at your option.