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

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.现在,当我按下withdrawMoney() function 和另一个地址时。 Who will pay the gas fee?谁来支付燃气费? is it the address that has deployed the smart contract?是部署智能合约的地址吗? or is it the smart contract itself?还是智能合约本身?

The fee for the internal transaction to.transfer(getBalance());内部交易的费用to.transfer(getBalance()); is included in the total fee paid by the user executing the withdrawMoney() function.包含在执行withdrawMoney() function的用户支付的总费用中。

It's currently not possible to split the fee to multiple payers (eg the user paying for the main transaction, and the contract paying for the internal transaction).目前无法将费用分摊给多个付款人(例如,用户为主要交易付款,而合约为内部交易付款)。

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

相关问题 计算交易汽油费 - Calculate Transaction Gas Fee 智能合约gas成本 - smart contract gas cost 我如何在私人连锁店免费发送交易 - How can I send transaction with no gas fee on private chain 为什么在私有以太坊区块链上部署智能合约需要消耗gas费,而调用不需要? - Why does the deployment of smart contracts on the private Ethereum blockchain need to consume gas fee, while the invocation does not? Chainlink vrf v2 请求 gas 费用金额 - Chainlink vrf v2 request gas fee amount 在以太坊中支付挖矿费不是和向银行支付费用类似吗? - Isn't paying a mining fee in Ethereum similar to paying a fee to banks? 如果一个智能合约从另一个智能合约读取数据,是否需要消耗 gas? - If one smart contract reads data from another smart contract, does it costs gas? 从 mai.net(以太坊)上的其他智能合约调用 function 部署合约是否可行(就 gas 成本而言)? - Is it feasible (In terms of gas cost) to call a function of deployed contract from other smart contract on mainnet (ethereum)? "合约代码无法存储,请检查您的gas限制:以太坊智能合约部署失败:" - The contract code couldn't be stored, please check your gas limit : Ethereum Smart Contract Deployment Failed: 无法将智能合约部署到 Polygon,Gas 估计错误,内部 JSON-RPC 错误 - Unable to deploy smart contract to Polygon, Gas estimation error, Internal JSON-RPC error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM