Forcing Ether to a contract
A developer can choose to enable or disable the acceptance of value in a contract. This is done by flagging the named/unnamed functions as payable. But, there are ways one can send Ether to the contract by force.
This can affect some of the logic inside a contract, which was written based on the previous assumption. In this recipe, you will learn how to find and avoid such problems in your smart contract.
Getting ready
It's expected that you have a basic understanding of the Ethereum blockchain and solidity before stepping through this recipe.
The Remix IDE (https://remix.ethereum.org) can help you quickly test and deploy the contract. Also, you can use any Ethereum client (geth
, parity
, and so on) and the solc
compiler to run this contract.
How to do it...
- You can sendEtherto a contract even if it does not implement a
payable
function. Generally, sending Ether to a non-payable function will result in a failed transaction. - A developer can easily overlook this and include...