A simple Solidity smart contract that allows the owner to add books and toggle their availability.
Users can retrieve book details but cannot modify them.
✔ Owner can add books to the library
✔ Users can fetch book details by ID
✔ Owner can toggle book availability
✔ Access control ensures only the owner can modify the library
✔ Fully tested with Hardhat ✅
This smart contract is written in Solidity (^0.8.28
) and tested using Hardhat.
It stores books using a mapping(uint => Book)
, where each book has:
- A
title
- An
author
- A
boolean isAvailable
to track availability
Example:
struct Book {
string title;
string author;
bool isAvailable;
}
---
📌 Contract Functions
This contract includes the following functions:
addBook(string title, string author): Owner adds a new book to the library.
getBook(uint _id): Retrieves a book's details (title, author, availability).
toggleAvailability(uint _id): Owner can change a book's availability.
---
🛠 Tech Stack
Solidity ^0.8.28
Hardhat
ethers.js
Chai (for testing)
---
📌 Installation & Running Locally
Clone the Repository
git clone https://github.com/simob75/solidity-library-contract.git
cd solidity-library-contract
Install Dependencies
npm install
Compile the Smart Contract
npx hardhat compile
Run Tests
npx hardhat test
You should see ✅ all tests passing.
---
🌍 Future Plans
✅ Upload smart contract to GitHub (Done!)
⏳ Build a React frontend using ethers.js
⏳ Deploy contract to a testnet
⏳ Host frontend on Vercel/Netlify
---
🏆 Acknowledgments
Special thanks to Hardhat, ethers.js, and Chai for making Solidity development easier! 🚀
---
📩 Connect
💬 Questions? Feel free to reach out or open an issue!
🐙 GitHub: simob75