You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GoQuorum 27.7网络Remix默认EVM版SELFBALANCE报错解决方案咨询

问题:GoQuorum QBFT网络中address(this).balance触发invalid opcode: SELFBALANCE错误

我们运行GoQuorum 27.7版本的QBFT共识网络,在Remix中使用默认EVM版本时,调用涉及address(this).balance的合约函数会报错:invalid opcode: SELFBALANCE;手动选择“petersburg”EVM版本则可正常运行。我们希望找到无需每次部署合约时手动选择“petersburg”EVM版本即可正常运行的解决方法。

涉事合约代码

// SPDX-License-Identifier: MIT

pragma solidity >=0.8.0;

contract TestCalls {

    uint256 public XYSTORED = 0;

    function setBalance() external returns(uint256) {
            XYSTORED = address(this).balance;
            return XYSTORED;
    }

    function withdawlCIC() external {
        payable(msg.sender).transfer(XYSTORED);
        XYSTORED = address(this).balance;
    }

    function emergencyWithdrawl() external {
        payable(msg.sender).transfer(XYSTORED);
    }

    function ViewXXBalance() external view returns(uint256 balance) {
        balance = address(this).balance;
    }
    
}

当前创世区块配置片段

"config": {
                "chainId": 1234,
                "homesteadBlock": 0,
                "eip150Block": 0,
                "eip150Hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
                "eip155Block": 0,
                "eip158Block": 0,
                "byzantiumBlock": 0,
                "constantinopleBlock": 0,
                ..........
}

此前尝试的无效配置

曾在创世配置中添加如下过渡设置,但问题仍未解决:

"transitions": [{
                                "block": 54074,
                                "istanbulBlock": true
                        },
                        {
                                "block": 547122,
                                "petersburgBlock": true
                        }]

解决方案

问题根源

Solidity 0.8.x版本中,address(this).balance会被编译为SELFBALANCE opcode,该 opcode是在Petersburg硬分叉中引入的。如果GoQuorum网络的创世配置未正确启用Petersburg,节点将无法识别该 opcode,从而触发错误。

正确的创世配置修改方式

直接在config根节点添加petersburgBlock: 0,让网络从创世块开始就启用Petersburg特性(无需使用transitions数组,GoQuorum的硬分叉开关直接在config根节点配置)。修改后的配置片段如下:

"config": {
    "chainId": 1234,
    "homesteadBlock": 0,
    "eip150Block": 0,
    "eip150Hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "eip155Block": 0,
    "eip158Block": 0,
    "byzantiumBlock": 0,
    "constantinopleBlock": 0,
    "petersburgBlock": 0,
    "istanbulBlock": 0
}

操作步骤

  1. 修改所有节点的创世配置文件,添加petersburgBlock: 0;
  2. 删除每个节点数据目录下的chaindata等区块链数据文件夹;
  3. 重新初始化所有节点并启动网络。

这样配置后,Remix使用默认EVM版本时会自动匹配网络的硬分叉状态,无需手动选择“petersburg”即可正常编译运行合约。

内容的提问来源于stack exchange,提问作者ShadiAyoub

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.12 04:02:00