Connect Web Apps to Blockchain
Web3.js is a JavaScript library that allows web applications to interact with the Ethereum blockchain.
Frontend (React / HTML) → Web3.js → Ethereum Blockchain
Send transactions Read blockchain data Interact with smart contracts Connect wallets (MetaMask)
npm install web3
import Web3 from "web3";
const web3 = new Web3(window.ethereum);
await window.ethereum.request({ method: "eth_requestAccounts" });
const balance = await web3.eth.getBalance(address); console.log(balance);
web3.eth.sendTransaction({
from: account,
to: receiver,
value: web3.utils.toWei("0.01", "ether")
});
contract.methods.setData(10).send({ from: account });
contract.methods.getData().call();