Created
December 7, 2017 22:35
-
-
Save NathanMaton/e4d812a318a9383ee918b35efc7f6083 to your computer and use it in GitHub Desktop.
This file contains 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
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; | |
} | |
} | |
commands: | |
var Web3 = require('web3') | |
var web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545')) | |
var account1 = web3.eth.accounts[0] | |
var account2 = web3.eth.accounts[1] | |
var balance = (acct) => {return web3.fromWei(web3.eth.getBalance(acct),'ether').toNumber() } | |
var solc = require('solc') | |
//add source then do following | |
var source = `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; | |
} | |
}` | |
//now compile | |
var compiled = solc.compile(source) | |
var bytecode = compiled.contracts[":Escrow"].bytecode | |
var abi = JSON.parse(compiled.contracts[":Escrow"].interface) | |
var escrowContract = web3.eth.contract(abi) | |
//add buyer, seller, arbiter | |
var buyer = account1 | |
var seller = account2 | |
var arbiter = web3.eth.accounts[2] | |
//deploy contract | |
var deployed = escrowContract.new(seller,arbiter, { | |
from: buyer, | |
data: bytecode, | |
gas: 4700000, | |
gasPrice:5, | |
value: web3.toWei(5,'ether') | |
}, (error,contract) => { | |
console.log(error,contract) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
do these commands work for deployment of the smart contract from metamask?