Skip to content

Instantly share code, notes, and snippets.

@AlwaysBCoding
Last active August 12, 2018 07:33
Show Gist options
  • Save AlwaysBCoding/98689461c5f91751b980355876c76e69 to your computer and use it in GitHub Desktop.
Save AlwaysBCoding/98689461c5f91751b980355876c76e69 to your computer and use it in GitHub Desktop.
Ethereum Ðapp Development - Video 8 | Smart Contracts - Escrow
// package.json
{
"dependencies": {
"web3": "0.17.0-alpha",
"solc": "^0.4.4"
}
}
// Escrow.sol
contract Escrow {
address public buyer;
address public seller;
address public arbiter;
function Escrow(address _seller, address _arbiter) {
buyer = msg.sender;
seller = _seller;
arbiter = _arbiter;
}
function payoutToSeller() {
if(msg.sender == buyer || msg.sender == arbiter) {
seller.send(this.balance);
}
}
function refundToBuyer() {
if(msg.sender == seller || msg.sender == arbiter) {
buyer.send(this.balance);
}
}
function getBalance() constant returns (uint) {
return this.balance;
}
}
@mechanical-turk
Copy link

mechanical-turk commented Jul 16, 2017

The current version of Solidity requires you to put a payable flag at the end of a constructor. If you don't do this, you'll get Error: Cannot send value to non-payable function

Here's the corrected code:

contract Escrow {

  address public buyer;
  address public seller;
  address public arbiter;

  function Escrow (address _seller, address _arbiter) payable {
    buyer = msg.sender;
    seller = _seller;
    arbiter = _arbiter;
  }

  function payoutToSeller () {
    if (msg.sender == buyer || msg.sender == arbiter) {
      seller.send(this.balance);
    }
  }

  function refundToBuyer () {
    if (msg.sender == seller || msg.sender == arbiter) {
      buyer.send(this.balance);
    }
  }

  function getBalance() constant returns (uint) {
    return this.balance;
  }
}

@NathanMaton
Copy link

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