â SOLVED â
I am stuck with the very last part that has to work on my Dapp, its a button to allow the player to withdraw all his money he won from the coinflip. This is the solidity code:
function UserWithdrawMoney() public {
uint toTransfer = result[msg.sender].userEarnings;
balance -= toTransfer;
result[msg.sender].userEarnings = 0;
msg.sender.transfer(toTransfer);
}
And again, I am literally sitting for over 2 hours to find the correct web3.js code to call this function, but nothing works⌠This should actually work if im not mistaken?
function giveUserMoneyBack(){
contractInstance.methods.UserWithdrawMoney().send();
}
// or something else I tried, since send() takes a JSON object as an argument:
function giveUserMoneyBack(){
var userBalance = contractInstance.methods.seeEarnings().call();
then(contractInstance.methods.UserWithdrawMoney().send({value: userBalance}));
}
But it does not open metamask and it doesnt reset the earnings of the user to 0 ⌠does anybody got tips? It is correctly connected to the button, I tested alert(âhiâ); in the JS function and it works when I press the button. So it has to be that there is a specific way to write the web3.js code, so that the user receives a transaction from the contract. In remix my solidity code is working btw.
update: i forgot to update the abi after i changed my smart contract and deployed it ^^