ethers-js
Interact with Ethereum and EVM blockchains using ethers.js. Use when a user asks to connect to Ethereum, read blockchain data, send transactions, interact with smart contracts, or build a dApp frontend.
What this skill does
# ethers.js
## Overview
ethers.js is the most popular library for interacting with Ethereum and EVM-compatible blockchains (Polygon, Arbitrum, Base, BSC). It handles wallet connections, contract interactions, transaction signing, and blockchain queries.
## Instructions
### Step 1: Setup
```bash
npm install ethers
```
### Step 2: Read Blockchain Data
```typescript
// lib/ethereum.ts — Read-only blockchain access
import { ethers } from 'ethers'
// Connect to Ethereum (read-only)
const provider = new ethers.JsonRpcProvider('https://eth-mainnet.g.alchemy.com/v2/YOUR_KEY')
// Get ETH balance
const balance = await provider.getBalance('0x742d35Cc6634C0532925a3b844Bc9e7595f2bD18')
console.log(ethers.formatEther(balance)) // "1.234"
// Get current block
const block = await provider.getBlockNumber()
// Get transaction
const tx = await provider.getTransaction('0x...')
```
### Step 3: Interact with Smart Contracts
```typescript
// Read from a contract (no wallet needed)
const USDC_ADDRESS = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'
const ERC20_ABI = [
'function balanceOf(address) view returns (uint256)',
'function decimals() view returns (uint8)',
'function symbol() view returns (string)',
'function transfer(address to, uint256 amount) returns (bool)',
]
const usdc = new ethers.Contract(USDC_ADDRESS, ERC20_ABI, provider)
const balance = await usdc.balanceOf('0x...')
const decimals = await usdc.decimals()
console.log(ethers.formatUnits(balance, decimals)) // "1000.00"
```
### Step 4: Send Transactions
```typescript
// Write to blockchain (needs wallet)
const wallet = new ethers.Wallet(process.env.PRIVATE_KEY!, provider)
const usdcWithSigner = usdc.connect(wallet)
// Transfer USDC
const tx = await usdcWithSigner.transfer(
'0xRecipient...',
ethers.parseUnits('100', 6) // 100 USDC (6 decimals)
)
await tx.wait() // wait for confirmation
console.log('TX hash:', tx.hash)
```
### Step 5: Frontend (MetaMask)
```typescript
// Connect to user's MetaMask wallet
const provider = new ethers.BrowserProvider(window.ethereum)
const signer = await provider.getSigner()
const address = await signer.getAddress()
```
## Guidelines
- ethers.js v6 is current — v5 syntax is different (avoid mixing).
- Never expose private keys in frontend code — use MetaMask/WalletConnect for user wallets.
- Use Alchemy, Infura, or QuickNode as RPC providers — don't run your own node unless needed.
- Always `await tx.wait()` before confirming success — `tx.hash` alone doesn't mean it's mined.
Related in Web Dev
generating-lwc-components
IncludedLightning Web Components with PICKLES methodology and 165-point scoring. Use this skill when the user creates or edits LWC components, builds wire service patterns, or writes Jest tests for LWC. TRIGGER when: user creates/edits LWC components, touches lwc/**/*.js, .html, .css, .js-meta.xml files, or asks about wire service, SLDS, or Jest LWC tests. DO NOT TRIGGER when: Apex classes (use generating-apex), Aura components, or Visualforce.
tanstack-query
IncludedManage server state in React with TanStack Query v5. Set up queries with useQuery, mutations with useMutation, configure QueryClient caching strategies, implement optimistic updates, and handle infinite scroll with useInfiniteQuery. Use when: setting up data fetching in React projects, migrating from v4 to v5, or fixing object syntax required errors, query callbacks removed issues, cacheTime renamed to gcTime, isPending vs isLoading confusion, keepPreviousData removed problems.
document-processor-api
IncludedProcess documents with Nutrient DWS. Use when the user wants to generate PDFs from HTML or URLs, convert Office/images/PDFs, assemble or split packets, OCR scans, extract text/tables/key-value pairs, redact PII, watermark, sign, fill forms, optimize PDFs, or produce compliance outputs like PDF/A or PDF/UA. Triggers include convert to PDF, merge these PDFs, OCR this scan, extract tables, redact PII, sign this PDF, make this PDF/A, or linearize for web delivery.
nutrient-document-processing
IncludedProcess documents with Nutrient DWS. Use when the user wants to generate PDFs from HTML or URLs, convert Office/images/PDFs, assemble or split packets, OCR scans, extract text/tables/key-value pairs, redact PII, watermark, sign, fill forms, optimize PDFs, or produce compliance outputs like PDF/A or PDF/UA. Triggers include convert to PDF, merge these PDFs, OCR this scan, extract tables, redact PII, sign this PDF, make this PDF/A, or linearize for web delivery.
tanstack-query
IncludedManage server state in React with TanStack Query v5. Covers useMutationState, simplified optimistic updates, throwOnError, network mode (offline/PWA), and infiniteQueryOptions. Use when setting up data fetching, fixing v4→v5 migration errors (object syntax, gcTime, isPending, keepPreviousData), or debugging SSR/hydration issues with streaming server components.
accelint-nextjs-best-practices
IncludedNext.js performance optimization and best practices. Use when writing Next.js code (App Router or Pages Router); implementing Server Components, Server Actions, or API routes; optimizing RSC serialization, data fetching, or server-side rendering; reviewing Next.js code for performance issues; fixing authentication in Server Actions; or implementing Suspense boundaries, parallel data fetching, or request deduplication.