Consider the contract:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
contract Test {
address payable public owner;
constructor() {
owner = payable(msg.sender);
}
function deposit() public payable {}
function withdraw() public {
require(msg.sender == owner, "Owner issue");
owner.transfer(address(this).balance);
}
}
Withdrawing from this contract costs around 34,900 gas.
I found out that if I use payable(msg.sender) instead of the owner, it costs less gas, around 34,700.
payable(msg.sender).transfer(address(this).balance);
I am not completely understanding why is this happening. Won't sending ETH to an already payable address will cost less than casting an address to payable then sending? Any answer would be helpful.