Skip to content

Instantly share code, notes, and snippets.

@what-the-func
Created March 12, 2020 05:47
Show Gist options
  • Save what-the-func/7381a50259ee17e827ff2e74b41ef3e9 to your computer and use it in GitHub Desktop.
Save what-the-func/7381a50259ee17e827ff2e74b41ef3e9 to your computer and use it in GitHub Desktop.
Escrow Smart Contract
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