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 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

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