Quick Comparison
Ethers.js
- ⭐ 18k+ GitHub stars
- Smaller bundle size (~80KB)
- Cleaner, more intuitive API
- Better TypeScript support
- Provider/Signer pattern
Web3.js
- ⭐ 17k+ GitHub stars
- Larger bundle size (~500KB)
- More mature ecosystem
- More tutorials available
- Wider compatibility
Ethers.js Example
import { ethers } from 'ethers';
const provider = new ethers.JsonRpcProvider(
'https://eth-mainnet.g.alchemy.com/v2/YOUR_KEY'
);
const balance = await provider.getBalance('0x...');
console.log(ethers.formatEther(balance));
const wallet = new ethers.Wallet('privateKey', provider);
const tx = await wallet.sendTransaction({
to: '0x...',
value: ethers.parseEther('0.01')
});
Web3.js Example
import Web3 from 'web3';
const web3 = new Web3(
'https://eth-mainnet.g.alchemy.com/v2/YOUR_KEY'
);
const balance = await web3.eth.getBalance('0x...');
console.log(web3.utils.fromWei(balance, 'ether'));
const account = web3.eth.accounts.privateKeyToAccount('0x...');
web3.eth.accounts.wallet.add(account);
const tx = await web3.eth.sendTransaction({
from: account.address,
to: '0x...',
value: web3.utils.toWei('0.01', 'ether')
});
When to Use Each
- Choose Ethers.js: New projects, React/Vue apps, smaller bundle size needed
- Choose Web3.js: Legacy projects, need maximum compatibility
Our Recommendation
For most new projects, Ethers.js is the better choice due to its cleaner API and smaller bundle size.