This is a decentralized application (dApp) built to explore how smart contracts talk to a web frontend. I built this to understand the "bridge" that connects blockchain logic to a user-friendly interface.
The main purpose of this project was to master three core concepts:
- Understanding ABIs: Learning that an ABI (Application Binary Interface) is the essential "instruction manual." It tells our JavaScript exactly which functions exist on the blockchain and what data they need.
- Working with ethers.js: Using this library as the engine to connect to MetaMask, sign transactions, and handle the math for sending ETH.
- Real-World Interaction: Moving beyond just reading data to actually sending "payable" transactions (sending 2 ETH per coke) to the network.
- The Smart Contract: This is an ABC project. The Vending Machine logic was sourced from the ABC official Gitbook. It manages inventory and handles the purchase math.
- The Frontend: A clean, simple HTML/JS setup that doesn't require complex frameworks, making it easier to see the underlying logic.
- The Connection: We use
ethers.jsto create a "Contract Object" in the browser, which lets us trigger thepurchasefunction with a button click.
The VendingMachine contract manages a coke inventory:
getVendingMachineBalance()— returns current stockrestock(uint amount)— owner-only, adds to inventorypurchase(uint amount)— payable, costs0.00001 ETHper unit
Deployed on Sepolia at 0xB266590c076742C52D790786D16aAED5F1665685.
- The Bridge: Without the ABI, the website is "blind" to the contract.
- Wallet Integration: Learned how to request account access and use a "Signer" to authorize blockchain actions.
- Wei vs ETH: Gained experience using utility functions to convert human-readable ETH into the "Wei" units that the blockchain requires.
