Created
March 12, 2020 05:47
-
-
Save what-the-func/7381a50259ee17e827ff2e74b41ef3e9 to your computer and use it in GitHub Desktop.
Escrow Smart Contract
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.6.0; | |
contract Escrow { | |
enum State { AWAITING_PAYMENT, AWAITING_DELIVERY, COMPLETE } | |
State public currState; | |
address public buyer; | |
address payable public seller; | |
modifier onlyBuyer() { | |
require(msg.sender == buyer, "Only buyer can call this method"); | |
_; | |
} | |
modifier onlySeller() { | |
require(msg.sender == seller, "Only seller can call this method"); | |
_; | |
} | |
constructor(address _buyer, address payable _seller) public { | |
buyer = _buyer; | |
seller = _seller; | |
} | |
function deposit() onlyBuyer external payable { | |
require(currState == State.AWAITING_PAYMENT, "Already paid"); | |
currState = State.AWAITING_DELIVERY; | |
} | |
function confirmDelivery() onlyBuyer external { | |
require(currState == State.AWAITING_DELIVERY, "Cannot confirm delivery"); | |
seller.transfer(address(this).balance); | |
currState = State.COMPLETE; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment