I am trying to work out when ETH is needed and hence when the modifier payable is needed in a function. I read through the "documentation" and various jumbled up references to payable, but I cannot see any clear statement about when ETH is needed and when payable therefore is needed.

I assume that payable is needed when a state variable is modified. Is there any other condition requiring ETH and hence the word payable to be stated?

From what I know now -

State Variable Update - ETH needed - payable specified

Other variable actions (eg local, or reading only) - no ETH needed - payable not specified.


payable is only necessary when you want a transaction that calls a function to accept eth as payment. If payable is omitted, the only change is that calls to the function that are transferring eth will fail. Calls to functions with payable don't fail if eth is sent during the call.

| improve this answer | |
  • Has someone a code example? Does this mean that Ethereum dapps are free to use in terms of blockchain costs if only state variables are updated or read? – Trevor Lee Oakley Feb 18 '18 at 5:29
  • No, the sender of the tx still has to pay transaction fees. This is completely separate from payable and the amount of wei sent in a transaction – flygoing Feb 18 '18 at 5:32
  • OK, I had thought payable referred to txn fees. – Trevor Lee Oakley Feb 18 '18 at 5:41

A contract only needs ETH if it will keep and eventually transfer the ETH.

Contracts can execute code because the sender of the transaction pays for all the execution.

A contract only needs payable on the functions that it wants to receive ETH at. A contract can also receive ETH during its creation, only if the constructor is payable.

payable was added to Solidity to avoid ETH being accidentally sent and permanently stuck in contracts that did not have a way to withdraw the ETH.

| improve this answer | |

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.