【问题标题】:Why my Solidity Ethereum Contract ran out of gas?为什么我的 Solidity 以太坊合约的 gas 用完了?
【发布时间】:2021-05-17 10:15:11
【问题描述】:

松露迁移 --reset

正在编译您的合同...

一切都是最新的,没有什么要编译的。

开始迁移...

网络名称:“发展” 网络编号:5777 区块气体限制:672197500 (0x2810eb7c)

1_initial_migration.js

替换“迁移”

交易哈希:0xf41feee2b768ba375d95ded5c40a48e7af3d59554f616738102a2a9805824d77 块:0 秒:0 合约地址:0xe75Ea4aDD9728c9846778a695cE0CF32b66C1c52 块数:1 区块时间戳:1621246185 帐户:0x33b005e2f8d83120b4ab4bDde1bD7Ad704077801 余额:99.99626098 使用的气体:186951 (0x2da47) 汽油价格:20 gwei 发送值:0 ETH 总成本:0.00373902 ETH

保存迁移到链。 保存工件


总成本:0.00373902 ETH

2_deploy_contracts.js

替换“加密男孩”

错误:*** 部署失败 ***

“CryptoBoys”的gas用完了(使用您在网络配置或部署参数中设置的值。)

  • 区块限制:672197500 (0x2810eb7c)
  • 气体发送:6721975 (0x6691b7)

当我写这个函数时,它导致了上面提到的错误

    function getAllTokensMintedByUser(address user) public view returns(CryptoBoy[] memory result){
        
        uint256 k=0;
        result=new CryptoBoy[](totalMintedTokens[user]);
        if(totalMintedTokens[user]!=0){
            for(uint256 i=1; i<=cryptoBoyCounter; i++) {
            
            CryptoBoy memory cryptoboy=allCryptoBoys[i];
            if(cryptoboy.mintedBy==user){
              result[k]=cryptoboy;
              k++;
            }
          }
        }
        
        return result;
      }

【问题讨论】:

标签: ethereum solidity truffle ganache


【解决方案1】:

您的合约可能超过 24KB 的代码限制。

但是,您可以尝试在truffle-config.js 中手动设置用于部署到development 网络的gas 限制:

development : {
 ...
 gas: 6000000
}

【讨论】:

    猜你喜欢
    • 2018-12-09
    • 2019-05-09
    • 2022-08-02
    • 2021-05-27
    • 2019-06-14
    • 2018-10-16
    • 1970-01-01
    • 2016-02-28
    • 2017-08-01
    相关资源
    最近更新 更多