import { createWalletClient, http, parseEther } from 'viem';import { privateKeyToAccount } from 'viem/accounts';import { base } from 'viem/chains';const account = privateKeyToAccount('0xYourPrivateKey');const client = createWalletClient({ account, chain: base, transport: http('https://mainnet.base.org'),});const hash = await client.sendTransaction({ to: '0xRecipientAddress', value: parseEther('0.001'),});console.log(`Sent, view at https://basescan.org/tx/${hash}`);
Never hardcode or expose a private key. '0xYourPrivateKey' is a placeholder. Load the key from an environment variable or a secrets manager, keep it server-side, and never commit it to source control.
Transactions confirm in under a second on Base thanks to Flashblocks, and typically cost a fraction of a cent in gas.