1

There are multiple methods to withdraw the ETH balance of a contract to the owners' wallet:

function withdrawal() external {
    payable(owner).transfer(address(this).balance);
}

function withdrawal() external {
    (bool sent,) = payable(owner).call{value: address(this).balance}("");
    require(sent, "Failed");
}

I've noticed a lot of articles mentioning that the '.call' version is the recommended one these days.

I do understand that this might be true if sending ETH from one contract to another, due to the fact that a .call is not limited by 2300 gas.

But if the matter of this function is to just send the contract ETH balance to a wallet, where no additional tasks are executed, wouldn't be the .transfer version the better choice? It would automatically limit the gas, as well as reverts on failure, which doesn't require an additional success check...

...or would there be any other reason why .call would be preferred over .transfer in this situation?

1 Answer 1

4

You are right.

But the thing is, even the gas cost of opcodes can be increased in the upgraded version and it is evident in EIP1884 during Istanbul hard fork, where gas cost for sload increased.

keeping that in mind using call is a better option. Read this article by Consensys, it discusses the same thing. https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/

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.