Suppose I have a contract:

contract mycontract {
    constructor() payable {}
    function withdraw(uint256 amount) public {  
        // either
        // or
        (bool success, ) = msg.sender.call{value: amount}("");
        require(success, "Transfer failed.");

When I call withdraw(100000000000000), I got my ether balance increased by 99999999973576 or so wei instead of 100000000000000. Is it because of transaction cost? How can I fix this function to receive exactly 100000000000000 wei? And if it's tx cost, why it applied differently to "normal" transaction (like wallet to wallet)? Why tx cost doesn't deduced from contract balance, not from tx amount? Where one can read about it?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.