This Solidity smart contract (BookDatabase
) manages a collection of books on the blockchain. It allows users to add, edit, and remove books from the database. Each book is represented by its title, publication year, number of pages, and author.
- Add Book: Add a new book to the database.
- Edit Book: Modify the details of an existing book.
- Remove Book: Delete a book from the database.
- Ownership: Only the contract owner can modify the database.
- Solidity Version: ^0.8.12
- License: MIT
- Initializes the contract and sets the owner to the deployer's address.
function addBook(Book memory newBook) public
- Adds a new book to the database.
function editBook(uint32 id, Book memory newBook) public
- Edits the details of an existing book identified by
id
.
function removeBook(uint32 id) public restricted
- Removes the book with the given
id
from the database.
modifier restricted()
- Restricts access to functions only to the owner of the contract.
To interact with this contract:
- Deploy it on a supported Ethereum network.
- Use a compatible Ethereum wallet (e.g., MetaMask) to play the game by calling the
play
function with the desired choice and the correct amount of ether. - Alternatively, you can use Remix — an online Solidity IDE — to deploy and interact with the contract directly from your web browser.
- This contract was inspired by the need for decentralized book management systems.
This contract is provided as-is with no warranties or guarantees. Use it at your own risk.