I’m going through this tutorial - https://www.youtube.com/watch?v=rd0TTLjQLy4
Everything seems to work fine. After clicking Play Heads / Play Tails I’m getting a Metamask confirmation and after confirming, I’m getting the smart contract receipt. The problem is that regardless of the amount in the number input, the transaction price is always equal to just the gas fee. I’m sure that I’m getting the amount from the input correctly because it’s showing up in the console log.
Here’s my code:
Moralis.initialize("************"); // Application id from moralis.io
Moralis.serverURL = "************"; //Server url from moralis.io
async function login() {
try {
user = await Moralis.User.current();
if(!user) {
user = await Moralis.Web3.authenticate();
}
console.log(user);
alert("User logged in")
document.getElementById("login_button").style.display = "none";
document.getElementById("game").style.display = "block";
} catch (error) {
console.log(error);
}
}
async function flip(side) {
let sideNumber;
let amount = document.getElementById("amount").value;
if(side == "heads") {
sideNumber = 0;
} else {
sideNumber = 1;
}
window.web3 = await Moralis.Web3.enable();
let contractInstance = new web3.eth.Contract(window.abi, '0xf09274736c50a7497D84940b9FF14A140Ef3333C');
contractInstance.methods.flip(sideNumber).send({value: amount.toString(), from: ethereum.selectedAddress})
.on('receipt', function(receipt) {
console.log(receipt.events.bet.returnValues.win);
})
}
document.getElementById("login_button").onclick = login;
document.getElementById("heads_button").onclick = function(){flip("heads")};
document.getElementById("tails_button").onclick = function(){flip("tails")};
And a screenshot: