0

I called a fund function and sent 0.55 ether to this contract. Now called withdraw function and all the ethers in the contract came back to my metamask account. But in the screenshot below you can see the withdraw function, in the value section it is showing 0. It should show 0.55. enter image description here CAN SOMEONE TELL ME WHY?

2
  • Can you please share contract address if verified, Or contract code. Aug 16, 2022 at 9:55
  • @AbhijeetGawai 0xB501EfBDAF10Db01e3861ffbEd1a2799BF43a3B6
    – amit
    Aug 16, 2022 at 10:59

1 Answer 1

2

In Withdraw() actually 0.55 eth is sent to your wallet. You can click on transaction or click here to see it.

But why in this screenshot it is not shown? Lets understand step by step.

First Lets Understand why while calling fund() 0.55 eth is shown

fund() is a payable function. So, When you called fund(), you sent msg.value parameter here as 0.55e18. That why it is showing 0.55 eth as parameter in screenshot. And thus 0.55 eth is transferred to smart contract. Remember in this screenshot, only msg.value parameter is shown.

This msg.value parameter referes to how much ether is sent by user. Below call will make it clear to you.

FundMe.fund({"from":account,"value":Wei(0.55e18)}) , This is call you have made. Here "value" is msg.value which is 0.55 eth

Now Lets Understand why 0.55 eth not shown in withdraw()

Here withdraw() is also payable function which is not needed.

Here Fund.wihtdraw({"from":account}) this is your call. Here you havent passed any msg.value because you are not sending any ether to smart contract from your account. That why it shows 0 eth.

Though, Smart Contract have sent 0.55 eth to your wallet. Your call still has msg.value parameter as 0.

Remember, The values in screenshot is just msg.value parameter. It only means how much ether is transferred from your wallet to smart contract.

I hope this helps.

3
  • 1
    If you have any doubt regarding please ask, i will provide more information. Aug 17, 2022 at 7:50
  • Thank you for solving my doubt! Also so the withdraw function will still work if I remove payable from it?
    – amit
    Aug 17, 2022 at 11:58
  • Yes, It will work. Because you are not passing msg.value parameter while calling withdraw function. Aug 17, 2022 at 17:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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