book

                Never    
Text
       
// SPDX-License-Identifier: MIT

pragma solidity 0.8.7;

contract MyBookContract {
    struct Mybook {
    	string title;
    	uint256 price;
    	bool sold;
    	address owner;
	}
	Mybook public book;

    address[] public buyers;

    function setBook(string memory _title, uint8 _price) public {
        book.title = _title;
        book.price = _price;
    }

    function getBookDetails() public view returns (string memory, uint256) {
        return (book.title, book.price);
    }

    function buyBook() public payable {
        require(
           msg.value >= book.price * 1000000000000000000,
           "insufficient balance"
       );
        //if (msg.value >= price * 1000000000000000000) {
            book.owner = msg.sender;
            buyers.push(book.owner);

            book.sold = true;
            uint256 bal = msg.value - (book.price * 1000000000000000000);
            if (bal > 0) {
                payable(msg.sender).transfer(bal);
            }
        //}
    }
}

Raw Text