2

If I receive ether in a payable function on a my smart contract, is there any way to tell if the msg.sender is also capable of receiving ether short of sending a few wei back to the sender to see if it fails or not? (which is an expensive "fail safe" I think) Assume for example, I am collecting a deposit which should be returned if the requested service can't be performed.

It seems as if any address can be converted to an address payable, but that doesn't tell you whether or not the address is a contract that has no payable fallback function. In that case I'd like to revert the transaction so the value isn't collected in the first place.

1 Answer 1

1

For a contract to have Ethers, it typically needs to have a payable function of some sort. I say typically, because there are exceptions.

So if a contract sends you Ethers, it probably has a payable function itself also. But that still doesn't guarantee that you could use that function: maybe it can be used only be certain addresses, for example.

So you can't be sure whether a contract with Ethers has a payable function, and even if you could, you can't be sure what that function is and whether you could call it.

So, as far as I can tell, there is no way to know whether a certain contract is capable of receiving Ethers. Even with your 'fail safe' method you can't be sure whether the receiver has code that conditionally refused your send or whether it can't accept Ether at all.

1
  • That's interestingly problematic. To be more precise, I'd really like to know whether the contract has receive method that would accept eth sent via something like (success, ) = senderAddress.call({value: somevalue}(""). Typically I would expect callers to be EOA's, but I gather trying to filter function calls by whether or not the sender is EOA is discouraged (and not wholly reliable).
    – GGizmos
    Commented Mar 8, 2022 at 5:17

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.