Hi @dan-i, thanks for this - I don’t think that was the issue and I’m not getting any errors on my console - just that the transaction fails. I’ve placed my edited flipCoin function and main.js code below:
> function flipCoin(uint256 CoinSide, uint256 value) public payable returns (bool){
Bet memory newBet;
newBet.coinSide = CoinSide;
newBet.betValue = value;
bettings[msg.sender] = newBet;
//Contract's balance
balance += msg.value;
uint256 headsOrTails = random();
uint256 toTransfer = value;
if (headsOrTails == CoinSide) {
require(balance >= 2 * toTransfer);
balance = balance - 2 * toTransfer;
msg.sender.transfer(2 * toTransfer);
result = true;
} else {
result = false;
}
return (result);
}
````Preformatted text`
var web3 = new Web3(Web3.givenProvider);
var contractInstance;
var address;
$(document).ready(function () {
window.ethereum.enable().then(function (accounts) {
contractInstance = new web3.eth.Contract(
abi,
"0x79C75e810FDA59171E6E482fDd876117F94FC762",
{ from: accounts[0] }
);
console.log(contractInstance);
address = accounts[0];
});
$("#bet_button").click(flip); //inputData
});
function flip() {
if ($("#bet_input").val() < 0.1) {
alert("Minimum Bet Amount is 0.1 ETH");
return;
}
var bet = 0;
var radioValue = $("input[name='sides']:checked").val();
var betValue = $("#bet_input").val();
if (radioValue) {
if (radioValue == "heads") {
bet = 1;
}
}
var config = {
from: address,
value: web3.utils.toWei(betValue.toString(), "ether"),
gas: 100000,
};
contractInstance.methods
.flipCoin(bet, betValue)
.send(config)
.on("transactionHash", function (hash) {
console.log(hash);
})
.on("confirmation", function (confirmationNr) {
console.log(confirmationNr);
})
.on("receipt", function (receipt) {
console.log(receipt);
});
}