I have read many examples of payable functions, but I didn't understand any of them. Also, they talked about modifier in payable. My questions are:
- What exactly does payable() function do?
- Does this function take arguments?
ethereum-wallet-dappsolidity
I have read many examples of payable functions, but I didn't understand any of them. Also, they talked about modifier in payable. My questions are:
- What exactly does payable() function do?
- Does this function take arguments?
Best Answer
First,
payable
is a modifier that can be added to a function. What you are most likely misinterpreting is a use case like:It's impossible to have
payable()
as a function name as it is a reserved keyword. You may usepayable
only in addition to existing functions like:Second,
payable
allows a function to receive ether while being called as stated in docs. It's mandatory to include thepayable
keyword from Solidity 0.4.x. If you try to send ether using call, as follows:to a function without a
payable
keyword, the transaction will be rejected.Usually, there is a no name function to accept ether to be sent to a contract which is called a fallback function:
But you may have more than one
payable
annotated functions that are used to perform different tasks, like registering a deposit to your contract: