为什么这个智能合约功能在使用 web3 提供商的 Remix IDE 上不起作用?

Why this smart contract function doesn't work on Remix IDE using web3 provider?

使用git,我得到了以太坊源代码并自己构建了它。并连接到 Remix IDE 的 web3 提供者环境。 在下面的代码中,nums() 函数执行得很好,但是 add() 函数超出了 gas 限制。

A.sol


pragma solidity >=0.4.21 <0.6.0;

contract A {
    uint num;
    constructor(uint n) public {
        num = n;
    }

    function add(uint n) public {
        num += n;
    }

    function nums() public view returns (uint) {
        return num;
    }
}

B.sol


pragma solidity >=0.4.21 <0.6.0;

import "./A.sol";

contract B {
    A a;
    constructor(address addr) public {
        a = A(addr);
    }

    function add(uint n) public {
        a.add(n);
    }

    function nums() public view returns (uint) {
        return a.nums();
    }
}

gas limit 设置为 0x2fefd8000,在 Remix IDE 上 运行 时设置为 1000000000。但是没有理由说gas limit超过800000。 你知道为什么吗?

GAS limit设置为3000000,这样就可以正常工作了。

当 gas limit 设置为 :1000000000

时交易失败的原因

Gas 成本高于整个区块允许的交易无法执行,此类交易自动失败。