async function main() {
try {
console.log('\n1. Creating source wallet...');
await input({ message: 'Press Enter to generate source wallet...' });
const sourceWallet = await generateWallet();
console.log('Source Address:', sourceWallet.address);
await input({ message: 'Press Enter to continue...' });
console.log('\n2. Creating destination wallet...');
await input({ message: 'Press Enter to generate destination wallet...' });
const destinationWallet = await generateWallet();
console.log('Destination Address:', destinationWallet.address);
await input({ message: 'Press Enter to continue...' });
console.log('\n3. Saving wallet information...');
const backupFile = await savePrivateKeyBackup(sourceWallet, destinationWallet);
console.log('Backup saved to:', backupFile);
console.log('\n4. Fund your source wallet:');
console.log('Get testnet ETH from: https://www.alchemy.com/faucets/world-chain-sepolia');
console.log('Get testnet USDC from: https://faucet.circle.com');
console.log('Source Wallet Address:', sourceWallet.address);
await input({ message: 'Press Enter after funding your wallet...' });
console.log('\n5. Checking wallet balances...');
const publicClient = createPublicClient({
chain: worldchainSepolia,
transport: http()
});
let ethBalance, usdcBalance;
let isFunded = false;
while (!isFunded) {
ethBalance = await publicClient.getBalance({ address: sourceWallet.address });
usdcBalance = await publicClient.readContract({
address: USDC_CONTRACT,
abi: USDC_ABI,
functionName: 'balanceOf',
args: [sourceWallet.address]
});
console.log('ETH Balance:', formatEther(ethBalance), 'ETH');
console.log('USDC Balance:', Number(usdcBalance) / 10 ** USDC_DECIMALS, 'USDC');
if (ethBalance === 0n || usdcBalance === 0n) {
console.log('\nPlease fund your wallet with testnet ETH and USDC before proceeding.');
await input({ message: 'Press Enter after funding your wallet...' });
} else {
isFunded = true;
}
}
console.log('\n6. Ready to transfer USDC to Destination Address:', destinationWallet.address);
const amount = await input({
message: 'Enter amount of USDC to transfer:',
validate: (value) => {
const num = Number(value);
if (isNaN(num) || num <= 0) return 'Please enter a valid positive number';
if (num > Number(usdcBalance) / 10 ** USDC_DECIMALS) return 'Insufficient USDC balance';
return true;
}
});
const amountInDecimals = BigInt(Math.floor(Number(amount) * 10 ** USDC_DECIMALS));
const walletClient = createWalletClient({
account: privateKeyToAccount(sourceWallet.privateKey),
chain: worldchainSepolia,
transport: http()
});
console.log('\nExecuting transfer...');
const hash = await walletClient.writeContract({
address: USDC_CONTRACT,
abi: USDC_ABI,
functionName: 'transfer',
args: [destinationWallet.address, amountInDecimals]
});
console.log('\nTransfer successful!');
console.log('Transaction Hash:', hash);
console.log('View on Explorer:', `https://sepolia.worldscan.org/tx/${hash}`);
} catch (error) {
console.error('\nError:', error.message);
}
}
main();