A professional-grade tool for managing multiple Privy wallets and consolidating USDC tokens across the Base network. Built with both Python and JavaScript implementations, this tool provides secure, efficient wallet management with advanced features like smart account abstraction and gas optimization.
This project solves a common problem in DeFi: managing multiple wallets and consolidating funds efficiently. When you're running multiple wallets (for testing, user onboarding, or operational purposes), it becomes tedious to manually transfer funds between them or consolidate balances.
Key Use Cases:
- Fund Consolidation: Sweep all USDC from multiple wallets into a single destination
- Balance Monitoring: Check USDC balances across all your Privy wallets
- Bulk Transfers: Transfer specific amounts between wallets programmatically
- Wallet Management: List and manage all wallets in your Privy app
The project consists of two implementations:
- Simple & Reliable: Basic Web3.py integration with Privy API
- Easy to Deploy: Minimal dependencies, works out of the box
- Good for: Quick scripts, automation, or when you need something simple
- Advanced Features: Smart account abstraction, gas optimization
- Production Ready: Uses modern Web3 libraries and best practices
- Modular Design: Clean separation of concerns for easy maintenance
- Good for: Production deployments, when you need enhanced security
βββ config.js # Configuration constants and settings
βββ clients.js # Web3 client initialization and setup
βββ walletOperations.js # Core wallet management functions
βββ cli.js # Command-line interface (main entry point)
βββ package.json # Dependencies and scripts
- β Multi-Wallet Management: Handle unlimited number of Privy wallets
- β USDC Operations: Check balances, transfer specific amounts, sweep all funds
- β Base Network Support: Optimized for Base mainnet (Ethereum L2)
- β CLI Interface: Easy-to-use command line tools
- π Smart Account Abstraction: Enhanced security through Kernel smart accounts
- β‘ Gas Optimization: Pimlico bundler and paymaster integration
- π‘οΈ Rate Limiting: Built-in protection against API rate limits
- π Transaction Monitoring: Real-time transaction status and hashes
- ποΈ Modular Architecture: Clean separation of concerns for maintainability
Before using this tool, you'll need:
-
Privy App Setup
- A Privy app with App ID and Secret
- Server wallets configured in your Privy dashboard
-
API Keys
- Privy App ID and Secret
- Pimlico API key (for JavaScript version)
-
Network Access
- Access to Base mainnet RPC endpoint
- Internet connection for API calls
# Clone the repository
git clone <your-repo-url>
cd privy-test
# Install Python dependencies
pip install web3 requests
# Set your Privy credentials in sweep_to_wallet.py
# Update privy_app_id and privy_app_secret variables# Install Node.js dependencies
npm install
# Set your credentials in config.js
# Update PRIVY_APP_ID, PRIVY_APP_SECRET, and PIMLICO_API_KEYIn config.js, replace the placeholder credentials:
const PRIVY_APP_ID = "your_actual_app_id";
const PRIVY_APP_SECRET = "your_actual_app_secret";const PIMLICO_API_KEY = "your_actual_pimlico_api_key";# Using npm scripts (recommended)
npm run wallets
# Direct node command
node cli.js wallets# Using npm scripts
npm run balance -- 0x1234...
# Direct node command
node cli.js balance_usdc 0x1234...# Using npm scripts
npm run transfer -- 100.5 abc123 0x5678...
# Direct node command
node cli.js transfer_usdc 100.5 abc123 0x5678...# Using npm scripts
npm run sweep -- 0x9999...
# Direct node command
node cli.js transfer_all_wallets_all_usdc 0x9999...# List wallets
python3 sweep_to_wallet.py wallets
# Check balance
python3 sweep_to_wallet.py balance_usdc 0x1234...
# Transfer specific amount
python3 sweep_to_wallet.py transfer_usdc 100.5 abc123 0x5678...
# Sweep all USDC
python3 sweep_to_wallet.py transfer_all_wallets_all_usdc 0x9999...- Uses Privy App ID and Secret for API authentication
- Creates secure headers for all API requests
- Maintains session state for wallet operations
- Fetches all wallets from your Privy app
- Displays wallet IDs, addresses, and chain types
- Validates wallet accessibility and permissions
- Connects to Base mainnet USDC contract
- Handles decimal precision (6 decimals for USDC)
- Builds and sends transactions through Privy's infrastructure
- Creates Viem accounts from Privy wallets
- Converts to Kernel smart accounts for enhanced security
- Uses Pimlico for gas optimization and bundling
- config.js: Centralized configuration management
- clients.js: Clean client initialization and setup
- walletOperations.js: Focused business logic
- cli.js: Simple command-line interface
- β No Private Keys Stored: Uses Privy's secure wallet infrastructure
- β API-Based Operations: All operations go through Privy's secure APIs
- β Smart Account Abstraction: Enhanced security in JavaScript version
- β Rate Limiting: Built-in protection against abuse
- β Modular Design: Easier to audit and maintain security
β οΈ API Key Exposure: Keep your Privy and Pimlico keys secureβ οΈ Network Security: Ensure you're on Base mainnet, not testnetβ οΈ Transaction Verification: Always verify transaction hashes and addresses
Before running on mainnet, test with small amounts on Base Sepolia:
- Update RPC URL to Sepolia endpoint in
config.js - Use test USDC contract address
- Test with minimal amounts
- Verify all operations work as expected
The tool includes built-in validation:
- Balance checks before transfers
- Wallet existence verification
- Transaction parameter validation
For production, use environment variables:
export PRIVY_APP_ID="your_app_id"
export PRIVY_APP_SECRET="your_app_secret"
export PIMLICO_API_KEY="your_pimlico_key"- All operations are logged to console
- Transaction hashes are displayed for tracking
- Error handling includes detailed error messages
- Global error handlers for uncaught exceptions
"Failed to fetch wallet"
- Check your Privy App ID and Secret in
config.js - Verify the wallet ID exists in your app
- Ensure your app has the necessary permissions
"Insufficient balance"
- Verify the source wallet has enough USDC
- Check if the balance includes gas fees
- Ensure you're on the correct network
"Transaction failed"
- Check gas prices and network congestion
- Verify the destination address is valid
- Ensure the wallet has enough ETH for gas
Add more verbose logging by modifying the console.log statements or adding debug flags.
This is a professional tool, so contributions should follow enterprise standards:
- Code Quality: Follow existing patterns and add comprehensive comments
- Testing: Test all changes on testnet before mainnet
- Documentation: Update README and inline comments
- Security: Review all changes for security implications
- Architecture: Maintain the modular structure and separation of concerns
This project is licensed under the ISC License - see the package.json file for details.
This tool is for professional use only. Always:
- Test thoroughly on testnets before mainnet use
- Verify all addresses and amounts before executing
- Keep your API keys secure and never commit them to version control
- Monitor transactions and verify their success
For issues or questions:
- Check the troubleshooting section above
- Review Privy and Pimlico documentation
- Verify your configuration and credentials
- Test with minimal amounts first
Built with β€οΈ for the DeFi community
This tool demonstrates professional-grade wallet management practices and should be used responsibly in production environments.