It's said if we run:

suicide(address recipient);

At the end of the contract, the recipient will receive the amount of Ether owned by the contract.

Question 1: How does the contract (and this function) know where the amount of Ether is?

Question 2: In the 1st example here, they have no "suicide", then how the funding is released to the recipient (or beneficiary)?

"payable" enables a function (and contract) to receive Ether, and it can keep track of the amount it receive by using an array, e.g.

mapping (address => uint) balances;

Question 3: How does the contract claim the money it receives?


Q1) The contract simply has the ether... For example:

Try this.balance

I'm unfamiliar with the exact assembly generated, but I would assume it does the following:

1) recipient.send(this.balance)

2) send kill opcode

It might be that it is a form of "delete" Just like delete xyz[1234] recovers some gas

Q2) Unless a function that sends beneficiary.send(this.balance) funds could essentially be locked inside a contract, there is no "magic" going on, you can write terrible contracts if you want :)

Q3) As a contract receives funds via a payable function, it just has them, it doesn't need to claim it, unless it's dealing with receiving an ERC-20 token, but that's a whole different chapter

  • 1) There's a dedicated opcode SELFDESTRUCT that does everything.
    – Ismael
    Aug 18 '17 at 14:42

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.