Hey everyone!
I’ve made a lot of progress on phase 1 of my dapp. I feel like I’m really close to getting my functions written correctly but I could use some advice if someone wouldn’t mind.
First, I have three functions, makeWager(), acceptWager(), and coinFlip():
function makeWager() payable public returns(bool) {
wager = msg.value;
player1 = msg.sender;
return true;
}
function acceptWager() payable public returns(bool) {
if(msg.value == wager) {
player2 = msg.sender;
return true;
}
}
function coinFlip() public payable {
if(random() == 0) {
payMe(player1);
} else {
payMe(player2);
}
}
If I’ve written them like I think I have, then the first should take in a wager from msg.sender and set them to player 1. The second should set the other msg.sender to player 2 if they offer up the same wager. My thought process was that I could run the first function as accounts[1] on Metamask/Browser, then in main.js I have it set up so that when the user clicks a button, it’ll offer up one ether, and cause the owner to also offer up one ether, then the “coin is flipped”.
main.js:
$("#button_1").click(() => {
makeWager();
acceptWager();
flip();
});
and later
function makeWager() {
contractInstance.methods.makeWager().send({value: web3.utils.toWei(“1”, “ether”)});
}
function acceptWager() {
contractInstace.methods.acceptWager().send({value: web3.utils.toWei(“1”, “ether”), from: owner});
}
function flip() {
contractInstance.methods.coinFlip();
}
with owner having been declared as accounts[0] further up the file.
SO click the button, player1(msg.sender) offers 1 ether, causing player2(owner) to offer 1 ether, and then the flip() function is performed, paying out the 2 ether total to the winner.
In theory. But I’m getting the following error of which I took a screenshot, saying that contractInstance.methods.makeWager() is not a function. I’m not sure how to word this.
I’ll also attach the Github repo for it if that makes this any easier. Thank you!
https://github.com/MBurtonshaw/dapp_project