Skip to content

Solidity smart contract for managing a library. Allows the owner to add books, toggle availability, and retrieve book details. Fully tested with Hardhat.

Notifications You must be signed in to change notification settings

simob75/exercise-1-basic-struct-implementation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📚 Solidity Library Smart Contract

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.


🚀 Features

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


📜 Smart Contract Overview

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 seeall tests passing.

---

🌍 Future PlansUpload smart contract to GitHub (Done!)
⏳ Build a React frontend using ethers.jsDeploy contract to a testnetHost 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

About

Solidity smart contract for managing a library. Allows the owner to add books, toggle availability, and retrieve book details. Fully tested with Hardhat.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published