0

I have a contract which is in charge of dispatching ETH to a set of registered address. When I transfer ETH to it, the functionality works well, however when the ETH comes from a miner the ETH are not distributed (the "payable" function is not called).

I) Is this the expected behavior? (Yes I should read the spec)

II) Is there a way to have some code executed within the contract when it receives ETH from a miner

2 Answers 2

1

This behaviour is by the design of the EVM. According to solidity docs

A contract without a receive Ether function can receive Ether as a recipient of a coinbase transaction (aka miner block reward) or as a destination of a selfdestruct. A contract cannot react to such Ether transfers and thus also cannot reject them. This is a design choice of the EVM and Solidity cannot work around it.

So it's not possible for the contract to execute any function when receiving block reward.

To detect receiving of the block reward, you can create a balance variable in the contract and update it inside every payable function. And if the manual balance is not equal to address(this).balance then either a block reward has been received or a self-destructing function in some contract has sent its balance to this contract.

You could then observe the contract balance off-chain and call some function on the contract to invoke your logic.

0

You cannot guarantee that every ETH transfer triggers the code execution of your contract. If you send Ether when selfdestructing a contract of as a block reward, then no code execution is triggered (it will just increase the balance of that account).

This is documented in the Ethereum Yellow Paper. See point 11.3 on page 15 and the SELFDESTRUCT definition on page 38.

If ETH is transferd as part of a call it should always trigger your contract. If this is not the case for you, it would be good to share more information, so that it can be reproduced.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.