0
pragma solidity ^0.8.1;

contract SendMoney{
    uint public publicBalance;
    uint public lockedUntil;

    function receiveMoney() public payable{
        publicBalance += msg.value;
        lockedUntil = block.timestamp + 1;
    }

    function getBalance() public view returns(uint){
        return address(this).balance;
    }

    function withdrawMoney() public{
        if(lockedUntil < block.timestamp){
            address payable to  = payable(msg.sender);
            to.transfer(getBalance());
        }
    }

    function withdrawMoneyTo(address payable _to) public{
        if(lockedUntil < block.timestamp){
            _to.transfer(getBalance());
        }
    }
}

I have deployed a smart contract with some address lets say. I sent some ether to the smart contract with the method receive money. Now, when i press on withdrawMoney() function with some another address. Who will pay the gas fee? is it the address that has deployed the smart contract? or is it the smart contract itself?

Javeed
  • 7
  • 1
  • 1
    A contract cannot pay for gas fees. Take a look at this https://ethereum.stackexchange.com/questions/38479/how-to-make-someone-else-pay-for-gas for some tricks, also search for metatransactions. – Ismael Jan 15 '22 at 17:55
  • If you want to work around this look at tools like https://docs.opengsn.org/ – Richard Jan 15 '22 at 20:09
  • There is also quite some research/ work on this: https://ethereum-magicians.org/t/eip-3074-auth-and-authcall-opcodes/4880 and https://ethereum-magicians.org/t/erc-4337-account-abstraction-via-entry-point-contract-specification/7160 – Richard Jan 15 '22 at 20:11

1 Answers1

1

The gas fee for any smart contract interaction is paid by the EOA (Externally Owned Account) that calls it. Even if the smart contract makes another transaction (as an internal transaction), it's considered to be part of the original transaction called by the EOA, so the EOA will have to pay the gas for the entire transaction.

pbsh
  • 2,441
  • 1
  • 6
  • 24
  • If I make a swap with a certain token and the contract collect part of the transaction as fees and then transfers these fees to ten different wallets (hypothetical situation), I'm the one paying fo all these transfers? – Integral Mar 26 '24 at 05:21
  • 1
    Yes. That's correct. – pbsh Mar 27 '24 at 12:36