DApp Development
A Decentralized Application (DApp) combines a smart contract backend with a traditional frontend. The frontend talks to the blockchain through a provider (like MetaMask), sending transactions and reading state from smart contracts.
DApp Architecture
ββββββββββββββββββββββββββββββββββββββββββββββββ
β DAPP ARCHITECTURE β
ββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β βββββββββββββββ ββββββββββββββββββββ β
β β Frontend β β Smart Contract β β
β β React/Vue/ ββββββΊβ (Solidity on β β
β β vanilla JS βββββββ Blockchain) β β
β ββββββββ¬ββββββββ ββββββββββββββββββββ β
β β β
β βΌ β
β βββββββββββββββ β
β β Web3 Libraryβ (ethers.js / web3.js) β
β ββββββββ¬ββββββββ β
β β β
β βΌ β
β βββββββββββββββ β
β β Provider β (MetaMask, WalletConnect) β
β ββββββββ¬ββββββββ β
β β β
β βΌ β
β βββββββββββββββ β
β β Blockchain β (Ethereum / Polygon / ...) β
β βββββββββββββββ β
ββββββββββββββββββββββββββββββββββββββββββββββββ
Frontend with ethers.js
import { ethers } from "ethers";
import contractABI from "./abi.json";
const CONTRACT_ADDRESS = "0x1234...abcd";
async function connectWallet() {
if (!window.ethereum) {
alert("Install MetaMask!");
return;
}
const provider = new ethers.BrowserProvider(window.ethereum);
await provider.send("eth_requestAccounts", []);
const signer = await provider.getSigner();
const contract = new ethers.Contract(
CONTRACT_ADDRESS,
contractABI,
signer
);
return { provider, signer, contract };
}
async function getCount() {
const { contract } = await connectWallet();
const count = await contract.getCount();
console.log("Count:", count.toString());
}
async function increment() {
const { contract } = await connectWallet();
const tx = await contract.increment();
await tx.wait(); // Wait for confirmation
console.log("Incremented!");
}
Project Structure
my-dapp/
βββ contracts/
β βββ MyContract.sol
βββ src/
β βββ App.jsx
β βββ components/
β βββ hooks/
β βββ abi.json
βββ test/
β βββ MyContract.test.js
βββ hardhat.config.js
βββ package.json
βββ .env
Development Tools
Hardhat: Development environment for compiling, testing, and deploying contracts.
Foundry: Fast, Rust-based toolkit for smart contract development.
Remix: Browser-based IDE for writing and deploying Solidity.
MetaMask: Browser wallet that provides the provider interface for DApps.
IPFS: Decentralized storage for frontend assets and NFT metadata.