celo-poll/scripts/generate-wallet.js
2025-12-08 16:31:30 +03:00

65 lines
2.0 KiB
JavaScript
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* Wallet Generation Script
* Generates a new Celo wallet for the protocol
*
* Usage: npm run wallet:generate
*/
const { Wallet } = require('ethers')
const fs = require('fs')
const path = require('path')
console.log('🔐 Generating new Celo wallet for PollCelo protocol...\n')
// Generate random wallet
const wallet = Wallet.createRandom()
console.log('✅ Wallet generated successfully!\n')
console.log('📋 Wallet Details:')
console.log('─'.repeat(80))
console.log(`Address: ${wallet.address}`)
console.log(`Private Key: ${wallet.privateKey}`)
console.log(`Mnemonic: ${wallet.mnemonic.phrase}`)
console.log('─'.repeat(80))
console.log('\n⚠️ SECURITY WARNING:')
console.log('1. NEVER commit the private key to git')
console.log('2. Add this to your .env.local file (NOT .env)')
console.log('3. Add this to Vercel environment variables')
console.log('4. Keep the mnemonic in a safe place (offline backup)')
console.log('\n📝 Add these to your .env.local file:\n')
console.log(`PROTOCOL_WALLET_ADDRESS=${wallet.address}`)
console.log(`PROTOCOL_WALLET_PRIVATE_KEY=${wallet.privateKey}`)
console.log('\n💰 Fund this wallet:')
console.log('1. Go to https://faucet.celo.org/ (testnet)')
console.log('2. Send some CELO for gas fees')
console.log('3. Get cUSD from Ubeswap or Mento')
console.log('4. Wallet is ready to receive poll payments!')
// Optionally save to file (DANGEROUS - delete after copying)
const saveToFile = process.argv.includes('--save')
if (saveToFile) {
const walletPath = path.join(__dirname, '../.wallet.json')
fs.writeFileSync(
walletPath,
JSON.stringify(
{
address: wallet.address,
privateKey: wallet.privateKey,
mnemonic: wallet.mnemonic.phrase,
createdAt: new Date().toISOString(),
warning: 'DELETE THIS FILE AFTER COPYING TO .env.local!',
},
null,
2
)
)
console.log(`\n⚠️ Wallet saved to ${walletPath}`)
console.log(' DELETE THIS FILE after copying to .env.local!')
}
console.log('\n✅ Done!')