Project Number: Project 1 – Decentralised Book Rental
- [Member 1 Name] - [Roll Number 1]
- [Member 2 Name] - [Roll Number 2]
- (Add missing members here)
- Item Listing: Owners list books with a daily rate and deposit, metadata stored via IPFS CID.
- Renting: Renters pay deposit + 1 day fee upfront.
- Returning: Renters return items, switching state to
AwaitingConfirm. - 48-Hour Auto-Refund: If the owner fails to confirm the return within 48 hours, the renter can claim their refund directly.
- Disputes: Renters can raise disputes, and an Arbitrator resolves them, refunding the appropriate party.
- Node.js (v18+)
- npm
- Hardhat
- MetaMask wallet (browser extension)
-
Install dependencies:
npm install
-
Compile Smart Contracts:
npx hardhat compile
-
Run Tests & Coverage:
npx hardhat test npx hardhat coverage -
Deploy Locally (for frontend): First, run a local node:
npx hardhat node
In a separate terminal, deploy the contract:
npx hardhat run scripts/deploy.js --network localhost
Update the
contractAddressinsidefrontend/app.jswith the deployed address. Then openfrontend/index.htmlin your browser.
Optimisation Applied: Replaced string require statements with Custom Errors (e.g., if (...) revert BookRental__InvalidPrice()). We also switched postfix increments (counter++) to prefix increments (++counter).
Before:
- Deployment Cost: ~1,100,000 gas
listItemexecution: ~226,500 gas
After:
- Deployment Cost: 1,064,310 gas
listItemexecution: 225,911 gas
Reasoning: Using custom errors eliminates the need to store revert strings on-chain, which saves deployment gas. It also provides cheaper revert mechanisms during execution because custom errors encode to a 4-byte selector instead of expanding the revert data with a long string. Prefix increments save gas by avoiding the caching of the previous variable state before returning.
We have strictly adhered to the privacy requirements:
- On-Chain: Prices, Statuses, Timestamps, and the IPFS CID (
ipfsCID). - Off-Chain: Book names, descriptions, images, and any personal information are kept strictly on IPFS or an off-chain server.
- Off-chain IPFS CID requires pinning; if unpinned by the host, metadata might become unavailable.
- Testnet deployment commands have not yet been strictly added; currently focusing on Hardhat localhost testing.