Automatically claim your rewards from resolved Polymarket prediction markets using gasless transactions via Relayer API.
π If you find this project useful, please consider giving it a star on GitHub!
This is a reference implementation showing how to programmatically claim rewards from Polymarket prediction markets. The script uses the official Polymarket Relayer API to execute transactions without requiring gas fees.
Use this code as a starting point for your own projects! Feel free to integrate it into your trading bots, monitoring systems, or automation workflows.
- β Automatic reward claiming from resolved prediction markets
- β Gasless transactions via Polymarket Relayer API (no MATIC required)
- β GnosisSafe Proxy Wallet support
- β Batch processing of multiple redeemable positions
- β Real-time status updates with transaction confirmation
- β Error handling and retry logic
- β Secure credential management via environment variables
- Python 3.8 or higher
- Polymarket account with Builder API credentials
- Private key for your EOA (External Owned Account)
- Proxy wallet address (where your positions are held)
-
Clone the repository
git clone https://github.com/MixasV/Polymarket-Claimer.git cd Polymarket-Claimer/claimer -
Install dependencies
pip install -r requirements.txt
-
Configure environment variables
Copy the example environment file:
cp .env.example .env
Edit
.envand add your credentials:POLYMARKET_PRIVATE_KEY=your_private_key_here POLYMARKET_PROXY_WALLET=your_proxy_wallet_address BUILDER_API_KEY=your_builder_api_key BUILDER_SECRET=your_builder_secret BUILDER_PASSPHRASE=your_builder_passphrase
-
Run the claimer
python claim_rewards.py
claimer/
βββ claim_rewards.py # Main script for claiming rewards
βββ requirements.txt # Python dependencies
βββ .env.example # Example environment configuration
βββ .env # Your actual configuration (gitignored)
βββ README.md # This file
Main claiming script - This is the core script that handles the entire claiming process.
What it does:
- Loads credentials from
.envfile - Initializes Polymarket Relayer client with SAFE wallet type
- Checks if GnosisSafe wallet is deployed (deploys if needed)
- Fetches all redeemable positions from Polymarket Data API
- Creates
redeemPositionstransactions for each position - Submits transactions via Relayer API (gasless)
- Waits for confirmation and displays results
How to run:
python claim_rewards.pyExpected output:
======================================================================
POLYMARKET REWARDS CLAIMER
======================================================================
Author: MixasV
Contact: https://t.me/onEXv
Repository: https://github.com/MixasV/Polymarket-Claimer
π Proxy Wallet: 0x65f0f0D46109974E47294236ccb2167ed627C57a
π§ Initializing Relayer client...
β
Relayer client initialized (SAFE type)
π Expected Safe: 0x65f0f0D46109974E47294236ccb2167ed627C57a
Deployed: True
π Fetching redeemable positions...
β
Found 1 redeemable position(s):
1. Bitcoin Up or Down - January 12, 9PM ET
Outcome: Down
Value: $15
π¦ Processing: Bitcoin Up or Down - January 12, 9PM ET
π€ Submitting to Relayer API...
β
Transaction submitted: 019bb73b-acff-7e8c-bcf9-5e6aa2277ae4
β³ Waiting for confirmation...
π SUCCESS!
β
Transaction Hash: 0x8d58c8177f3fcd68eb0b01606987a848c1f445e301aa16aaf75cac346a4166d4
π Polygonscan: https://polygonscan.com/tx/0x8d58c8177f3fcd68eb0b01606987a848c1f445e301aa16aaf75cac346a4166d4
======================================================================
β
Successfully claimed 1/1 positions
======================================================================
Lists all Python dependencies required by the claimer.
Installation:
pip install -r requirements.txtTemplate for environment variables. Copy this file to .env and fill in your credentials.
Required variables:
POLYMARKET_PRIVATE_KEY- Your EOA private key (with 0x prefix)POLYMARKET_PROXY_WALLET- Your Proxy Wallet addressBUILDER_API_KEY- Polymarket Builder API keyBUILDER_SECRET- Polymarket Builder secretBUILDER_PASSPHRASE- Polymarket Builder passphrase
.env file to version control! It contains sensitive credentials.
- Apply for Polymarket Builder Program at: https://polymarket.com/settings?tab=builder
- Once approved, you'll receive:
BUILDER_API_KEYBUILDER_SECRETBUILDER_PASSPHRASE
- Go to https://polymarket.com
- Connect your wallet
- Navigate to Settings β Wallet
- Copy your Proxy Wallet address (NOT your EOA address)
Example:
- β EOA:
0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb - β
Proxy Wallet:
0x65f0f0D46109974E47294236ccb2167ed627C57a
From MetaMask:
- Click on your account
- Account Details β Export Private Key
- Enter password and copy the key
Add 0x prefix if not present:
Original: abc123def456...
Correct: 0xabc123def456...
# Your EOA private key (with 0x prefix)
POLYMARKET_PRIVATE_KEY=0xYOUR_PRIVATE_KEY_HERE
# Your Proxy Wallet address (get from Polymarket settings)
POLYMARKET_PROXY_WALLET=0xYOUR_PROXY_WALLET_ADDRESS
# Builder API credentials (get from Polymarket Builder Program)
BUILDER_API_KEY=your_builder_api_key
BUILDER_SECRET=your_builder_secret
BUILDER_PASSPHRASE=your_builder_passphraseβββββββββββββββββββββββββββββββββββββββββββββββββββ
β Python Script (claim_rewards.py) β
βββββββββββββββββββββββββββββββββββββββββββββββββββ€
β 1. Load credentials from .env β
β 2. Initialize RelayClient (SAFE type) β
β 3. Check Safe deployment status β
β 4. Fetch redeemable positions (Data API) β
β 5. Create SafeTransaction objects β
β 6. Sign & submit via Relayer API β
β 7. Poll for transaction confirmation β
βββββββββββββββββββββββββββββββ¬ββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββ
β Polymarket Relayer API β
βββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β’ Validates Builder API credentials β
β β’ Executes transaction on GnosisSafe β
β β’ Pays gas fees (gasless for user) β
β β’ Returns transaction ID β
βββββββββββββββββββββββββββββββ¬ββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββ
β Polygon Blockchain β
βββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β’ CTF Contract (Conditional Token Framework) β
β β’ redeemPositions() function called β
β β’ Winning tokens converted to USDC β
β β’ USDC credited to Proxy Wallet β
βββββββββββββββββββββββββββββββββββββββββββββββββββ
-
Position Discovery
- Query Data API for positions with
redeemable=true - Filter by your Proxy Wallet address
- Query Data API for positions with
-
Transaction Creation
- Encode
redeemPositions(collateralToken, parentCollectionId, conditionId, indexSets)call - Create
SafeTransactionobject with encoded data - Use
OperationType.Callfor standard contract interaction
- Encode
-
Signing & Submission
- Sign transaction with EOA private key
- Submit to Relayer API with Builder credentials
- Relayer validates and forwards to blockchain
-
Execution
- GnosisSafe executes transaction on CTF contract
- Winning outcome tokens are redeemed for USDC
- USDC is credited to your Proxy Wallet
-
Confirmation
- Poll Relayer API for transaction status
- Wait for
STATE_MINEDorSTATE_CONFIRMED - Display Polygonscan link for verification
β DO:
- Store credentials in
.envfile - Add
.envto.gitignore - Use different credentials for testing and production
β DON'T:
- Hardcode credentials in source code
- Commit
.envto version control - Share your private key with anyone
β DO:
- Keep your private key encrypted at rest
- Use hardware wallets for large amounts
- Rotate keys periodically
β DON'T:
- Store private keys in plain text long-term
- Use the same key across multiple applications
- Share private keys via email or chat
β DO:
- Request minimum necessary permissions
- Monitor API usage for anomalies
- Revoke unused credentials
β DON'T:
- Expose Builder API keys in client-side code
- Use production credentials for testing
- Share API keys publicly
Example: Add to existing trading bot
from claim_rewards import get_redeemable_positions, create_redeem_transaction
# In your trading bot's main loop
def check_and_claim_rewards(proxy_wallet: str, relayer_client):
"""Check for claimable rewards and auto-claim"""
positions = get_redeemable_positions(proxy_wallet)
for pos in positions:
redeem_tx = create_redeem_transaction(pos['conditionId'])
response = relayer_client.execute([redeem_tx], f"Auto-claim: {pos['title']}")
result = response.wait()
if result:
print(f"β
Claimed {pos['currentValue']} from {pos['title']}")Run claimer every hour via cron:
# Edit crontab
crontab -e
# Add this line (runs every hour)
0 * * * * cd /path/to/Polymarket-Claimer/claimer && /usr/bin/python3 claim_rewards.py >> /var/log/polymarket-claimer.log 2>&1# Claim only high-value positions (>$100)
positions = get_redeemable_positions(proxy_wallet)
high_value = [p for p in positions if float(p['currentValue']) >= 100]
for pos in high_value:
# Process only valuable positions
...Cause: .env file not configured correctly
Solution:
# Copy example file
cp .env.example .env
# Edit with your credentials
nano .envCause: First time using Relayer with this wallet
Solution: Script will automatically deploy Safe. Wait for deployment confirmation.
Cause: All positions already claimed or no resolved markets
Solution: This is normal. Script will exit gracefully.
Cause: Wrong API key, secret, or passphrase
Solution:
- Verify credentials at https://polymarket.com/settings?tab=builder
- Check for extra spaces or newlines in
.env - Ensure you're approved for Builder Program
Cause: Network congestion or Relayer issues
Solution:
- Wait and retry after a few minutes
- Check Relayer API status
- Verify your transaction on Polygonscan
Enable verbose logging:
import logging
logging.basicConfig(level=logging.DEBUG)| Contract | Address | Purpose |
|---|---|---|
| CTF (Conditional Token Framework) | 0x4d97dcd97ec945f40cf65f87097ace5ea0476045 |
Handles position redemption |
| USDCe (USD Coin) | 0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174 |
Collateral token |
| Endpoint | Purpose |
|---|---|
https://relayer-v2.polymarket.com |
Relayer API for gasless transactions |
https://data-api.polymarket.com/positions |
Position data and redeemability status |
- py-builder-relayer-client - Official Polymarket Relayer client
- py-builder-signing-sdk - Builder authentication and signing
- web3.py - Ethereum/Polygon interaction
- requests - HTTP client for Data API
Contributions are welcome! Here's how you can help:
- Report bugs - Open an issue with detailed reproduction steps
- Suggest features - Share your ideas for improvements
- Submit PRs - Fork, code, and create a pull request
- Improve docs - Help make the documentation clearer
Coding Standards:
- Follow PEP 8 style guide
- Add docstrings to functions
- Include error handling
- Test before submitting
This project is licensed under the MIT License - see the LICENSE file for details.
MIT License Summary:
- β Commercial use allowed
- β Modification allowed
- β Distribution allowed
- β Private use allowed
β οΈ No warranty providedβ οΈ No liability accepted
MixasV
For questions, suggestions, or collaboration opportunities, feel free to reach out!
If this project helped you automate your Polymarket rewards, please:
- β Star this repository on GitHub
- π’ Share it with other Polymarket traders
- π¬ Provide feedback via issues or Telegram
Your support helps maintain and improve this project!
polymarket prediction-markets crypto automation claiming rewards claimer relayer gasless-transactions polygon conditional-tokens ctf gnosis-safe safe-wallet trading-bot defi blockchain ethereum web3 python builder-api
This software is provided as a reference implementation for educational purposes.
Use at your own risk:
- Always test with small amounts first
- Review all transactions before execution
- Keep your private keys secure
- No warranty or guarantees provided
- Author is not responsible for any losses
This is not financial advice. Always do your own research before trading or investing in prediction markets.
Made with β€οΈ by MixasV
β Star this repo β’ π Report Bug β’ π‘ Request Feature