Ethereum Development
EVM, gas optimization, development tools, and dApp architecture.
Overview
Ethereum is a programmable blockchain for decentralized applications.
Development Stack
| Tool | Purpose |
|---|---|
| Hardhat | Development environment |
| Foundry | Fast testing framework |
| ethers.js | JavaScript library |
| OpenZeppelin | Contract library |
| Alchemy/Infura | Node providers |
Hardhat Configuration
// hardhat.config.js
module.exports = {
solidity: {
version: "0.8.19",
settings: {
optimizer: {
enabled: true,
runs: 200
}
}
},
networks: {
sepolia: {
url: process.env.ALCHEMY_URL,
accounts: [process.env.PRIVATE_KEY]
}
}
};
EVM Basics
// Storage operations (expensive)
uint256 public count; // SSTORE: 20,000 gas
// Memory operations (cheap)
function example() public pure returns (uint256) {
uint256 temp = 100; // MSTORE: 3 gas
return temp;
}
Gas Optimization
// Bad: Multiple storage writes
function bad() public {
count = count + 1;
count = count + 1;
}
// Good: Single storage write
function good() public {
count += 2;
}
// Use calldata instead of memory
function good(string calldata data) public {
// Read-only, cheaper
}
dApp Architecture
Architecture Diagram
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā Frontend (React) ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā¤
ā Web3 Library ā
ā (ethers.js, web3.js) ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā¤
ā Smart Contracts ā
ā (Solidity) ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā¤
ā Ethereum Network ā
ā (Nodes, Miners/Validators) ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
Practice
Build a full-stack dApp with Hardhat and React.