Skip to content

๐ŸŒโ›“๏ธ Proof-of-concept showing a compact integration between a React (Vite) frontend and an ERC20 minting contract. Uses React for UI, Vite for fast builds, ethers.js for contract interaction, MetaMask for wallet support, and Solidity for on-chain logic.

License

Notifications You must be signed in to change notification settings

dherranzf/SmartContract-WebIntegration-POC

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

16 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŒโ›“๏ธ PoC React + Ether.JS โ€” Mint Frontend and Smart Contract Integration

A technology-focused proof-of-concept demonstrating a compact, production-minded integration between a React (Vite) frontend and an ERC20-compatible minting contract. This repo highlights why specific technologies were chosen โ€” React for component-driven UI, Vite for fast iterative development, ethers.js for robust and portable contract interaction, MetaMask for standard wallet integration, and Solidity for on-chain logic.

๐ŸŒ LIVE WEB: https://poc-react-ether.vercel.app/

๐Ÿ“‘ Table of contents

โš™๏ธ Features

  • Modern UI for minting tokens.
  • MetaMask connection and account detection.
  • Automatic switch to the configured chain (VITE_BASE_CHAIN_ID) and ability to add the chain if missing.
  • Token balance reading from the contract with formatted display.
  • Modular services: walletService, networkService, mintService, tokenService.

๐Ÿ“ Architecture and design

  1. Separation of concerns: network, wallet, token and mint logic are implemented in independent services under src/services.
  2. Reactive UI: React components (MainMint) consume state and asynchronous services.

Main flow

  • User connects their wallet โ†’ switch to configured network โ†’ read token balance โ†’ mint tokens using mintService.

๐ŸŽจ Technology stack

  • React + Vite
    • Component-driven UI library that simplifies state management and reactive rendering. Chosen for fast development and ease of composing the mint UI.
    • Development build tool with extremely fast hot module replacement (HMR) and a minimal configuration surface. Ideal for prototyping and iterative frontend work.
  • JavaScript
    • Primary language for the frontend. Familiar, lightweight and supported by the entire web ecosystem. JSX enables a concise component syntax in React.
  • ethers.js
    • Lightweight, well-maintained Ethereum library used for provider abstraction, signing transactions and contract interaction. The code includes compatibility with ethers v5 and v6 helper APIs to increase portability.
  • MetaMask (window.ethereum)
    • Ubiquitous browser wallet provider for end-user key management. Using MetaMask keeps the demo aligned with how typical web3 users interact with dApps.
  • Modern CSS and lightweight components
    • Simple, fast styling approach used for the demo UI. The styles aim for a modern, low-cost visual design without a heavy UI framework.
  • Solidity (contracts)
    • Language for on-chain smart contracts (ERC20-compatible mint contract). Solidity is the standard for Ethereum-compatible chains and is referenced here as the contract implementation target.
  • Node.js + npm
    • Tooling runtime to install dependencies and run the Vite dev server. Standard for modern JavaScript projects.
  • .env (Vite env variables)
    • Stores runtime configuration such as VITE_CONTRACT_ADDRESS and VITE_BASE_CHAIN_ID so the app can be deployed to different environments without code changes.

๐Ÿ—‚๏ธ Project structure

src/
โ”œโ”€โ”€ components/
โ”‚   โ””โ”€โ”€ MainMint.jsx          # Main UI
โ”œโ”€โ”€ services/
โ”‚   โ”œโ”€โ”€ walletService.js     # Wallet connection and account management
โ”‚   โ”œโ”€โ”€ networkService.js    # Network switching / adding chain
โ”‚   โ”œโ”€โ”€ mintService.js       # Mint logic (ethers + contract)
โ”‚   โ””โ”€โ”€ tokenService.js      # Balance reading and formatting
โ”œโ”€โ”€ resources/
โ”‚   โ””โ”€โ”€ contractABI.js       # Contract ABI used in the demo
โ”œโ”€โ”€ App.jsx
โ”œโ”€โ”€ main.jsx
โ”œโ”€โ”€ styles/
โ”‚   โ””โ”€โ”€ main.css
โ””โ”€โ”€ index.css

๐Ÿ“– Usage and running locally

  1. Clone the repository and enter the project folder:

    git clone cd Solidity-WebIntegration-POC

  2. Install dependencies:

    npm install

  3. Create a .env file at the project root with these variables (an example .env is included in the demo):

    VITE_CONTRACT_ADDRESS=0x... # contract address to use VITE_BASE_CHAIN_ID=0x2105 # chainId in hex format (e.g. Base)

  4. Start the dev server:

    npm run dev

  5. Open the app in the browser (Vite will show the URL). Connect MetaMask and use the "Mint Token" button to test the functionality.

Notes:

  • If MetaMask does not detect the configured network, the app will request a chain switch or addition.
  • On-chain operations require gas funds on the selected network.

๐Ÿงช Testing and debugging

  • Check the browser console for connection or transaction errors.
  • Ensure VITE_CONTRACT_ADDRESS points to a contract that implements the functions used (balanceOf, decimals, mint).

๐Ÿ” Examples Using

Example 1 Example 2 Example 3 Example 4

๐Ÿ”ฎ Future improvements

  • Support for multiple networks via a UI selector.
  • Improved error handling and transaction feedback (toasts, transaction list/state).
  • Backend integration to store events and enable historical queries.

๐Ÿ“œ License

This project is licensed under the GPL-3.0 License. See the LICENSE file for details.

About

๐ŸŒโ›“๏ธ Proof-of-concept showing a compact integration between a React (Vite) frontend and an ERC20 minting contract. Uses React for UI, Vite for fast builds, ethers.js for contract interaction, MetaMask for wallet support, and Solidity for on-chain logic.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published