Prerequisites
- Node.js 18+ installed
- Basic JavaScript/TypeScript knowledge
- An Ethereum wallet (MetaMask)
- API key from Alchemy or Infura
Step-by-Step Guide
- Set Up Your Project
Create a new directory and initialize npm: - Connect to Ethereum
Using viem (recommended for 2026): - Read Blockchain Data
Query account balances: - Send Transactions
Transfer ETH: - Read Smart Contract Data
Query ERC-20 balances:
mkdir my-eth-dapp
cd my-eth-dapp
npm init -y
npm install viem ethersimport { createPublicClient, http } from 'viem'
import { mainnet } from 'viem/chains'
const client = createPublicClient({
chain: mainnet,
transport: http('https://eth-mainnet.g.alchemy.com/v2/YOUR_KEY')
})const balance = await client.getBalance({
address: '0x...'
})
console.log(balance)const hash = await client.sendTransaction({
to: '0x...',
value: parseEther('0.01')
})const readContract = await client.readContract({
address: '0x...', // token address
abi: [...],
functionName: 'balanceOf',
args: ['0x...']
})Popular Libraries in 2026
- viem - Modern, lightweight, TypeScript-first
- ethers - Mature, widely used, great documentation
- web3.js - Legacy library, large community
💡 Best Practice: Use viem for new projects. It's faster, smaller, and designed for modern Ethereum development.
Next Steps
- Learn wagmi for React integration
- Explore DeFi protocols
- Build an NFT marketplace with NFT APIs