This repository contains both the smart contracts and the frontend for a decentralized platform where households with surplus solar energy can sell it directly to nearby users. The platform enables peer-to-peer energy trading, with buyers and sellers agreeing on prices and transactions being handled securely through blockchain technology.
The project is built, tested, and verified on the Ethereum Sepolia Testnet.
- Overview
- Smart Contract Details
- Technologies Used
- Getting Started
- Prerequisites
- Installation
- Compilation and Deployment
- Testing
- License
This decentralized renewable energy marketplace leverages blockchain technology to facilitate secure and transparent energy trading. Households with surplus solar energy can list their energy for sale, while buyers can browse available energy and purchase it directly. The platform's blockchain-based transactions ensure trust and transparency throughout the process.
The project comprises two main components:
- Smart Contracts: These handle listing, buying, and payment processing for energy transactions.
- Frontend: A user interface built to interact seamlessly with the smart contracts, allowing users to list, browse, and purchase energy easily.
The smart contract currently supports the following functionality:
- Listing Energy: Sellers can list available energy for sale and set their own prices.
- Buying Energy: Buyers can purchase energy listed by sellers.
- Price Negotiation and Agreement: Both parties agree to terms off-chain, while the contract only records the confirmed transactions.
- Automated Payments: Payments are securely handled on-chain as part of the contract’s transaction process.
- ERC20.sol: Token contract that handles purchasing, and payment processing between buyers and sellers.
- DecentralisedResource.sol: Main contract that handles listing, purchasing, and payment processing between buyers and sellers.
The frontend is built to provide a user-friendly interface for interacting with the decentralized marketplace. Key functionalities include:
-
Energy Listing Management: Sellers can add and update their energy listings.
-
Energy Browsing: Buyers can view available energy listings, filtering by criteria such as location and price.
-
Transaction Interaction: Buyers and sellers can connect their wallets and directly interact with the smart contracts to complete transactions.
- React Vite: For building the user interface.
- Ethers.js: To interact with the blockchain and smart contracts.
- Tailwind CSS: For styling and responsive design.
- Solidity: For writing the smart contract.
- Hardhat: Development environment and testing framework for deploying and testing smart contracts.
- React: Frontend development.
- Web3.js/Ethers.js: Blockchain interaction.
- Tailwind CSS: Styling.
Ensure you have the following installed:
- Node.js (v14 or later)
- Hardhat: Smart contract deployment framework
- MetaMask: For interacting with the frontend
- Clone the repository:
git clone https://github.com/your-username/decentralized-resource.git cd decentralized-resource npm install
Compile the Smart Contract:
npx hardhat compile
Configure Deployment Script:
npx hardhat run scripts/deploy.js --network yourNetwork
Replace yourNetwork with the configured network (such as Rinkeby) in your Hardhat config file.
Run Contract Tests: Write and run test cases to ensure all functions work as expected.
npx hardhat test
- Token: Sepolia Token Contract
- DecentralisedResource: Sepolia Resource Contract
Start the frontend application:
cd resource-client
npm run dev
Connect your MetaMask wallet to the Sepolia Testnet and enjoy the experience.