0

I am having an issue that is blocking me for days. And it all comes down to this:

I am using Ganache (TestRPC) for my local blockchain with it's default test accounts. I am connected with Metamask(on Chrome) using the first test account. (balance 100ETH).

I am creating the WithdrawalContract from solidity documentation: http://solidity.readthedocs.io/en/develop/common-patterns.html using 10ETH. Everything fine until now. Contract creation successful, my test account balance is 90ETH and Contract shows in transactions list with 10ETH.

Now I execute the withdraw() that should refund me the 10ETH amount.

Metamask shows transaction as success.

But the amount never makes it to my test account. Account balance is still 90ETH.

What am I missing? Why isn't withdrawal working for me?

PS: I do all this using remix.ethereum.org, using same account for contract creation and withdrawal. I also tried it with truffle but i got the same result.

Razor
  • 719
  • 8
  • 18
  • Can you post the steps you took with the contract? I just tried it and it worked fine. – Adam Kipnis Jan 24 '18 at 01:09
  • I made a video recording with all the steps I went trough from scratch. All apps use default settings: https://youtu.be/dD2fkPxpk_E – Razor Jan 24 '18 at 08:51

2 Answers2

0

can you try using transfer() and see

The code will look something like this

msg.sender.transfer(web3.utils.toWei('10', 'ether'));

msg.sender => the address interacting with the contract at that point of time and also the address that needs to be receiving the money as transfer() is called on that address ( in this case its you)

Dhaval Chheda
  • 4,637
  • 5
  • 24
  • 44
0

I looked at the video from your comment. This is just a simple example contract on the Solidity site and is not written very well. You have to pay closer attention to the code. withdraw() uses the pendingWithdrawals mapping to determine how much the caller is allowed to transfer out of the contract. Only the becomeRichest() method is setting that mapping. The constructor is not.

Deploy the contract without sending any ether. Then call becomeRichest(), this time sending in the ether. Then use withdraw (or, improve the code).

Adam Kipnis
  • 10,175
  • 10
  • 35
  • 48
  • Yes, you are right. I changed the code to also add `msg.sender` and `msg.value` to `pendingWithdrawals` in the `constructor` and it seems to work fine. Also removing and installing Metamask again fixed some invalid address errors I got. Finally, in remix you can use the Javascript VM which does not need Metamask, it is easier for debugging contracts. – Razor Jan 26 '18 at 12:48