I am trying to play with very simple contract on testnet (ropsten). My contract code is as follows.
contract Bank11{
mapping(address=>uint) userBalances;
function getUserBalance(address user) constant returns(uint) {
return userBalances[user];
}
function addToBalance() payable {
userBalances[msg.sender] = userBalances[msg.sender] + msg.value;
}
function withdrawBalance() {
uint amountToWithdraw = userBalances[msg.sender];
if (msg.sender.call.value(amountToWithdraw)() == false) {
throw;
}
userBalances[msg.sender] = 0;
}
}
No problem when I try with run on remix. (Javascript VM Mode) But I've got error every time when I try to call withdrawBalance.
transaction to Bank11.withdrawBalance errored: gas required exceeds allowance or always failing transaction.
I set Gas limit, 3000000. What am I doing wrong??
msg.sender.call.value(amountToWithdraw)()
supposed to be?