1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; contract SimpleWordAgreement { string private constant correctWord = "hola"; mapping(address => string) public words; address payable public party1; address payable public party2; bool public party1Set; bool public party2Set; constructor(address payable _party1, address payable _party2) { party1 = _party1; party2 = _party2; } function setWordByParty1(string memory _word) public { require(msg.sender == party1, "Not a valid party"); words[party1] = _word; party1Set = true; } function setWordByParty2(string memory _word) public { require(msg.sender == party2, "Not a valid party"); words[party2] = _word; party2Set = true; } function verifyAndTransfer() public { require(party1Set && party2Set, "Both parties must set their words"); require(keccak256(bytes(words[party1])) == keccak256(bytes(correctWord)), "Party 1 did not enter the correct word"); require(keccak256(bytes(words[party2])) == keccak256(bytes(correctWord)), "Party 2 did not enter the correct word"); require(address(this).balance > 0, "Contract has no funds"); party2.transfer(address(this).balance); } function deposit() public payable { require(msg.sender == party1, "Only party1 can deposit funds"); } } |