
Viem Integration
Wire up viem private keys, HD mnemonics, and wallet clients for signing and sending Ethereum transactions in TypeScript.
Overview
viem-integration is an agent skill for the Build phase that documents viem account creation, HD wallets, and wallet client wiring for Ethereum signing in TypeScript.
Install
npx skills add https://github.com/uniswap/uniswap-ai --skill viem-integrationWhat is this skill?
- privateKeyToAccount and walletClient setup with chain and HTTP transport
- Mnemonic HD accounts via mnemonicToAccount with default derivation path
- generatePrivateKey flow for new key material and address derivation
- Explicit warnings against Anvil test keys and public example mnemonics in production
- Environment-variable pattern for PRIVATE_KEY in wallet clients
Adoption & trust: 675 installs on skills.sh; 212 GitHub stars; 2/3 security scanners passed (skills.sh audits).
What problem does it solve?
You need to sign or send transactions from your app with viem but are unsure how to load keys, mnemonics, or wallet clients safely.
Who is it for?
TypeScript backends and agents integrating Uniswap or broader EVM flows with viem accounts.
Skip if: Frontend-only wallet connect UX (use wallet connector docs), non-EVM chains, or production key management without HSM/vault practices beyond env vars.
When should I use this skill?
Implementing viem accounts, mnemonics, or wallet clients for EVM transaction signing.
What do I get? / Deliverables
You can implement viem account helpers and a configured walletClient using env-backed keys without defaulting to unsafe test material.
- Account derivation code
- Configured walletClient snippet
- Key-generation pattern for dev-only flows
Recommended Skills
Journey fit
Build/integrations is the canonical shelf because the skill is reference material for connecting application code to Ethereum accounts via viem—not journey-wide process advice. Integrations fits wallet clients, account derivation, and signing patterns that plug into backend or agent tooling against chain RPCs.
How it compares
Integration reference for viem accounts—not a full DEX swap skill or MCP server.
Common Questions / FAQ
Who is viem-integration for?
Developers and solo builders adding programmatic signing and wallet clients to Node or agent projects using viem on EVM networks.
When should I use viem-integration?
During build/integrations when you are implementing private key accounts, mnemonic-derived addresses, or createWalletClient before contract calls or swaps.
Is viem-integration safe to install?
The skill discusses private keys and example test secrets; review the Security Audits panel on this Prism page and never commit real keys to the repo.
SKILL.md
READMESKILL.md - Viem Integration
# Accounts and Keys Reference for private key management, HD wallets, and message signing with viem. ## Private Key Account ### Basic Usage ```typescript import { privateKeyToAccount } from 'viem/accounts'; // ⚠️ Anvil default test key #0 — NEVER use in production! const account = privateKeyToAccount( '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80' ); console.log(account.address); // 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 ``` ### With WalletClient ```typescript import { createWalletClient, http } from 'viem'; import { privateKeyToAccount } from 'viem/accounts'; import { mainnet } from 'viem/chains'; const account = privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`); const client = createWalletClient({ account, chain: mainnet, transport: http(), }); ``` ### Generate New Private Key ```typescript import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts'; const privateKey = generatePrivateKey(); const account = privateKeyToAccount(privateKey); console.log('Private Key:', privateKey); console.log('Address:', account.address); ``` --- ## Mnemonic / HD Wallet ### Create Account from Mnemonic ```typescript import { mnemonicToAccount } from 'viem/accounts'; // ⚠️ NEVER use test mnemonics with real funds! This is a well-known example phrase. const account = mnemonicToAccount( 'legal winner thank year wave sausage worth useful legal winner thank yellow' ); console.log(account.address); // Default path: m/44'/60'/0'/0/0 ``` ### Custom Derivation Path ```typescript import { mnemonicToAccount } from 'viem/accounts'; // Different account indices const account0 = mnemonicToAccount(mnemonic, { addressIndex: 0 }); // m/44'/60'/0'/0/0 const account1 = mnemonicToAccount(mnemonic, { addressIndex: 1 }); // m/44'/60'/0'/0/1 const account2 = mnemonicToAccount(mnemonic, { addressIndex: 2 }); // m/44'/60'/0'/0/2 // Custom account path const account = mnemonicToAccount(mnemonic, { accountIndex: 1, // m/44'/60'/1'/0/0 }); // Full custom path const account = mnemonicToAccount(mnemonic, { path: "m/44'/60'/0'/1/5", }); ``` ### Generate New Mnemonic ```typescript import { generateMnemonic, english, mnemonicToAccount } from 'viem/accounts'; // Generate 12-word mnemonic const mnemonic = generateMnemonic(english); // Generate 24-word mnemonic const mnemonic24 = generateMnemonic(english, 256); const account = mnemonicToAccount(mnemonic); ``` ### Other Languages ```typescript import { generateMnemonic, english, spanish, french, italian, japanese, korean, simplifiedChinese, traditionalChinese, czech, portuguese, } from 'viem/accounts'; const mnemonic = generateMnemonic(spanish); ``` --- ## HD Key Derivation ### From Master Seed ```typescript import { HDKey, hdKeyToAccount } from 'viem/accounts'; // From seed (Buffer/Uint8Array) const hdKey = HDKey.fromMasterSeed(seed); const account = hdKeyToAccount(hdKey); ``` ### From Extended Key ```typescript import { HDKey, hdKeyToAccount } from 'viem/accounts'; // From xpriv/xpub const hdKey = HDKey.fromExtendedKey('xprv9s21ZrQH143K...'); const account = hdKeyToAccount(hdKey); ``` ### Derive Child Keys ```typescript import { HDKey, hdKeyToAccount } from 'viem/accounts'; const masterKey = HDKey.fromMasterSeed(seed); // Derive specific path const childKey = masterKey.derive("m/44'/60'/0'/0/0"); const account = hdKeyToAccount(childKey); // Multiple accounts const accounts = Array.from({ length: 10 }, (_, i) => { const child = masterKey.derive(`m/44'/60'/0'/0/${i}`); return hdKeyToAccount(child); }); ``` --- ## Message Signing ### Personal Sign (EIP-191) ```typescript import { privateKeyToAccount } from 'viem/accounts'; const account = privateKeyToAccount('0x...'); // Sign a message const signature = await account.signMessage({ message: 'Hello, World!', }); // Sign raw bytes const signature = await account.signMessage({ message: { raw: '0x68656c6c6f' }, }); ``` ### Verify Message Si