0

I have this simple contract used with remix.

pragma solidity^0.4.24;

contract test{ mapping (address => uint) balances; function Deposit() public payable{ balances[msg.sender] += msg.value; } function Withdraw() public{ msg.sender.transfer(balances[msg.sender]); balances[msg.sender] = 0; } function CheckBalance() view public returns(uint){ return balances[msg.sender]; } }


I can send the payable amount through remix, and the balance shows accordingly. The transaction will also show the correct value in wei. But withdrawing will result in a transaction of 0 wei.

The balance is deducted in the contract, but no transfer has occured to the msg.sender.

Thanks for help!

  • I just ran this in remix and it works as intended. Btw you have a vulnerability to reentrancy attacks in your Withdraw function. – Jaime Aug 13 '18 at 14:16
  • Perhaps i don't know how to use remix properly? You had the proper value in the withdraw function? I am using ganache-cli now. I'll try the code out again with the test nets – HelloGaro Aug 13 '18 at 14:24
  • I sent one ether and I withdraw one ether. Just be sure that you are withdrawing with the same address that you deposited. Do you have this in a testnet (ropsten maybe?) If so, please post here the address of your deployed contract – Jaime Aug 13 '18 at 14:27
  • Oh. it works on Ropsten. Guess it's a ganache problem? Thanks for the headsup about the reentrancy attacks. I will mark answered when I figure out why ganache is having problems with this. Thanks Jaime! – HelloGaro Aug 13 '18 at 14:34
1

Ahh. I had my payable wei value wrong in Remix. There wasn't enough 0s. Check your 0s and units guys!

Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.