繁体   English   中英

哪个地址支付gas费用? 而且,智能合约可以自己支付gas费吗?

[英]Which address is paying the gas fee? And, can the smart contract pay the gas fee by itself?

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());
        }
    }
}

我已经部署了一个带有一些地址的智能合约,可以说。 我用接收钱的方法向智能合约发送了一些以太币。 现在,当我按下withdrawMoney() function 和另一个地址时。 谁来支付燃气费? 是部署智能合约的地址吗? 还是智能合约本身?

内部交易的费用to.transfer(getBalance()); 包含在执行withdrawMoney() function的用户支付的总费用中。

目前无法将费用分摊给多个付款人(例如,用户为主要交易付款,而合约为内部交易付款)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM