Payable Keyword in Solidity

Use Payable as Keyword, not function name

First, payable is a modifier that can be added to a function. It's impossible to have payable() as a function name as it is a reserved keyword. You may use payable only in addition to existing functions like:

function deposit() payable {};
function register(address sender) payable {};
function () payable {}

Receive Ether from Call Transactions

Second, Payable allows a function to receive ether while being called as stated in docs.It's manadatory from solidity 0.4.x. If you try to send ether using call:"ETH_TO_BE_SENT")("ADDITIONAL_DATA")

to a function without a payable modifier, 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:

function () payable {};

But you may have more than one payable annotated functions that are used to perform a different tasks.

Example: How to register deposit to your contract:

function deposit() payable {
deposits[msg.sender] += msg.value;

Blockchain | Data Science | Cosmonaut


Blockchain | Data Science | Cosmonaut