Skip to content

Instantly share code, notes, and snippets.

Last active April 18, 2023 04:16
  • Star 8 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
pragma solidity ^0.6.0;
contract HotelRoom {
enum Statuses { Vacant, Occupied }
Statuses currentStatus;
address payable public owner;
event Occupy(address _occupant, uint _value);
constructor() public {
owner = msg.sender;
currentStatus = Statuses.Vacant;
modifier onlyWhileVacant {
require(currentStatus == Statuses.Vacant, "Currently occupied.");
modifier costs(uint _amount) {
require(msg.value >= _amount, "Not enough Ether provided.");
receive() external payable onlyWhileVacant costs(2 ether) {
currentStatus = Statuses.Occupied;
emit Occupy(msg.sender, msg.value);
Copy link

Ya Da Best

Copy link

TamiaBJ commented May 24, 2021

I second that^^

Copy link


Copy link

For anyone getting type error
Solidity 0.8 and onwards ""msg.sender"" is not payable anymore, It needs to be casted in payable first,
owner=msg.sender -> owner=payable(msg.sender)

Copy link

@neeleshwark17 thanks for the tip

Copy link


Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment