Private Key Setup
For agents to make payments automatically, they need access to a private key. This guide covers secure configuration.
Environment Variables
Store the private key in an environment variable:
For Base (EVM):
# .env file
PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80For Solana:
# .env file
SOLANA_PRIVATE_KEY=4wBqpZM9xwh...your-base58-keyLoading in Code
TypeScript (EVM):
import { privateKeyToAccount } from 'viem/accounts';
const account = privateKeyToAccount(
process.env.PRIVATE_KEY as `0x${string}`
);TypeScript (Solana):
import { Keypair } from '@solana/web3.js';
import bs58 from 'bs58';
const secretKey = bs58.decode(process.env.SOLANA_PRIVATE_KEY!);
const keypair = Keypair.fromSecretKey(secretKey);Security Best Practices
✅ Do
- • Use environment variables
- • Use secrets managers in production
- • Create a dedicated wallet for the agent
- • Fund only what's needed
- • Rotate keys periodically
❌ Don't
- • Never commit private keys to git
- • Never log private keys
- • Never include keys in error messages
- • Don't use your main wallet
- • Don't store more funds than needed
Create a Dedicated Wallet
Generate a new wallet specifically for your agent:
Generate EVM Wallettypescript
import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts';
// Generate a new wallet
const privateKey = generatePrivateKey();
const account = privateKeyToAccount(privateKey);
console.log('Address:', account.address);
console.log('Private Key:', privateKey);
// Save the private key securely!💡 Recommended starting amount: $10-50 USDC depending on expected usage.