0

I am curious about situation when there is no 'payable' in the contract. If a contract doesn't have 'payable', then is this mean that the contract cannot receive eth or crypto?

2 Answers 2

0

That is not exactly true. The keyword payable when used in the function of a contract allows the function to receive Ethers. In this way, the contract receives Ethers too. But this is not the only way to send Ethers to a contract.

Imagine there is no function with the keyword payable. For such cases, you add a receive function in the contract. The only work of a receive function is to receive Ethers. Use it like this:

// Receive Function
receive() external payable {}
0

The selfdestruct function is able to send funds to another contract, no matter if it has any payable function. This can in fact be used to attack the contract by altering its accounting.

https://solidity-by-example.org/hacks/self-destruct/

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.