Discover innovative ways to automate and secure your daily transactions
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; // Automated Rent Payment Smart Contract contract RentPayment { address payable public landlord; address public tenant; uint public rentAmount; uint public dueDate; uint public gracePeriod; bool public active; event RentPaid(address tenant, uint amount, uint timestamp); event ContractTerminated(uint timestamp); constructor( address payable _landlord, address _tenant, uint _rentAmount, uint _dueDate, uint _gracePeriod ) { landlord = _landlord; tenant = _tenant; rentAmount = _rentAmount; dueDate = _dueDate; gracePeriod = _gracePeriod; active = true; } // Automated monthly rent payment function payRent() public payable { require(active, "Contract is not active"); require(msg.sender == tenant, "Only tenant can pay rent"); require(msg.value == rentAmount, "Incorrect rent amount"); require(block.timestamp <= dueDate + gracePeriod, "Payment is late"); landlord.transfer(msg.value); emit RentPaid(tenant, msg.value, block.timestamp); // Update due date for next month dueDate += 30 days; } function terminateContract() public { require(msg.sender == landlord || msg.sender == tenant); active = false; emit ContractTerminated(block.timestamp); } }