Send blockchain transactions with the viem package using either a seed phrase or private key signer. Use when the user asks to transfer native tokens, send onchain transactions, or sign-and-broadcast with viem.
viemRPC_URLSEED_PHRASE or PRIVATE_KEY (exactly one signer source per send)RPC_URL, chain, to, amountEthseedPhrase or privateKeyrpcUrlchain (for example mainnet, sepolia, or custom chain object)toamountEth (human readable amount)mnemonicToAccountprivateKeyToAccountpublicClient and walletClient.to with isAddress.parseEther(amountEth).walletClient.sendTransaction.import { createPublicClient, createWalletClient, http, parseEther, isAddress } from 'viem'
import { sepolia } from 'viem/chains'
import { mnemonicToAccount } from 'viem/accounts'
const account = mnemonicToAccount(process.env.SEED_PHRASE!)
const publicClient = createPublicClient({ chain: sepolia, transport: http(process.env.RPC_URL!) })
const walletClient = createWalletClient({ account, chain: sepolia, transport: http(process.env.RPC_URL!) })
const to = '0xabc...'
if (!isAddress(to)) throw new Error('Invalid recipient address')
const hash = await walletClient.sendTransaction({
account,
to,
value: parseEther('0.001'),
})
import { createPublicClient, createWalletClient, http, parseEther, isAddress } from 'viem'
import { sepolia } from 'viem/chains'
import { privateKeyToAccount } from 'viem/accounts'
const account = privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`)
const publicClient = createPublicClient({ chain: sepolia, transport: http(process.env.RPC_URL!) })
const walletClient = createWalletClient({ account, chain: sepolia, transport: http(process.env.RPC_URL!) })
const to = '0xabc...'
if (!isAddress(to)) throw new Error('Invalid recipient address')
const hash = await walletClient.sendTransaction({
account,
to,
value: parseEther('0.001'),
})
parseEther for human-to-wei conversion.isAddress.action: sendchain: chain id/name usedaddress: sender wallet addresstxHash: transaction hash after broadcast, else nullstatus: success | failed | needs_confirmationnext_step: one clear follow-up action