Polymarket_Copy_Bot/generate-api-keys.js
Alexis Bruneteau 13f55b506a Initial commit: Polymarket Copy Trading Bot
- Complete bot implementation with TUI dashboard
- Trade detection and copying from monitored accounts
- Magic Login authentication support
- SQLite database for trade persistence
- Real-time balance tracking and trade execution
- 15-minute window market analysis
- Comprehensive error handling and logging
2025-12-06 19:58:56 +01:00

70 lines
2.6 KiB
JavaScript

const { ClobClient } = require('@polymarket/clob-client');
const { Wallet, JsonRpcProvider, TypedDataEncoder } = require('ethers');
const dotenv = require('dotenv');
dotenv.config();
// Patch the Wallet to add _signTypedData method if it doesn't exist
function patchWallet(wallet) {
if (!wallet._signTypedData) {
wallet._signTypedData = async function(domain, types, value) {
// Use the signTypedData method from ethers v6
return await this.signTypedData(domain, types, value);
};
}
return wallet;
}
async function generateApiKeys() {
try {
const privateKey = process.env.POLYMARKET_PRIVATE_KEY;
const rpcUrl = process.env.NETWORK_RPC_URL;
if (!privateKey) {
console.error('Error: POLYMARKET_PRIVATE_KEY not found in .env');
process.exit(1);
}
console.log('\n🔐 Generating new Polymarket API credentials...\n');
// Create provider and signer (ethers v6 way)
const provider = new JsonRpcProvider(rpcUrl);
let signer = new Wallet(privateKey, provider);
signer = patchWallet(signer);
const signerAddress = signer.address;
console.log(`Signer Address: ${signerAddress}`);
// Create a temporary client without credentials to derive new ones
const tempClient = new ClobClient(
'https://clob.polymarket.com',
137, // Polygon mainnet
signer,
undefined, // No credentials yet
1 // SignatureType.EOA = 1
);
console.log('Calling createOrDeriveApiKey()...\n');
const credentials = await tempClient.createOrDeriveApiKey();
console.log('✓ API Credentials Generated Successfully!\n');
console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
console.log('Add these to your .env file:');
console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n');
console.log(`POLYMARKET_API_KEY=${credentials.key}`);
console.log(`POLYMARKET_API_SECRET=${credentials.secret}`);
console.log(`POLYMARKET_API_PASSPHRASE=${credentials.passphrase}`);
console.log('\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n');
process.exit(0);
} catch (error) {
console.error('Error generating API keys:', error.message);
console.error('\nFull error:', error);
process.exit(1);
}
}
generateApiKeys();