I want to rewrite

  - bool ok = msg.sender.call.value(amount)();
  - emit WithdrawalEther(msg.sender, amount, ok);


  - (bool ok, bytes memory returnData) = msg.sender.call(abi.encodeWithSignature(???,amount));
  - emit WithdrawalEther(msg.sender, amount, ok);

But I am not sure what a signature string must be given for the part of the three question marks. The original statement is simply a sending of money amounting 'amount', and so if the receiver account is a contract, its fallback function must be called. This is my understanding. Then, my question seems to be what is a signature for fallback function.

The example needs a boolean value to check if sending money succeeds or not. In case it fails, an event with false must be created in the next statement.

The reason for the rewriting is because of this.

I have a solc compiler version 0.5.7 but the Solidity example program that I try to compile has a declaration of pragma 0.4.8.

If I simply change the version number, I will get a compilation error for

 -  bool ok = msg.sender.call.value(amount).()

because the style of the statement seems to be old and it is not supported by the solidity compiler version 0.5.7.

Can you please help me out to resolve this issue?

Thanks in advance.

bool status = msg.sender.send(amount);
emit WithdrawalEther(msg.sender, amount, ok);
  • Thank you for your answer. I missed one constraint on the rewriting. After sending money, I need to check if it succeeds or not. So my example code wants the sending statement to return a boolean value to check this. Your suggestion using transfer(amount) doesn't return false if sending money fails. – user3509406 Apr 15 at 9:52
  • As explained in the Solidity documentation I shared, transfer reverts on failure, so you don't have to worry about it. – Eli Drion Apr 15 at 10:20
  • Yes, I agree with you on the meaning of transfer(). But the use of transfer() in the new program makes a subtle difference from the existing example where it normally ends with an event even if sending money fails. Can we rewrite the original statements into a new one considering the subtle point? – user3509406 Apr 15 at 14:22
  • Edited my answer. – Eli Drion Apr 15 at 14:30
  • Oh, your answer looks very simple, and it seems to be what I am looking for. Thank you so much!!! – user3509406 Apr 15 at 14:33

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.