【问题标题】:Ethereum web3js method call fail以太坊 web3js 方法调用失败
【发布时间】:2018-09-28 13:13:11
【问题描述】:

我有一个简单的solidity智能合约,方法如下:

function foo(uint a) public {
    b =  bytes32(1);
        emit Event(a, b);
        emit Event2(a, b);
    }

(完整代码在这里:https://remix.ethereum.org/#optimize=false&version=soljson-v0.4.25+commit.59dbf8f1.js

并使用 web3.js 代码调用它:

contract = testContract.at('xxxAddress')   

// contract.foo(6); // Failed, Why?

//Success
contract.foo.sendTransaction(6, {from: eth.accounts[1]},function(error, result) {
            console.log("Got err:", error, ", result: ", result) 
    }
);

但是,为什么简单的 contract.foo(6) 失败了?哪位高手能解释一下吗?

【问题讨论】:

    标签: ethereum web3js


    【解决方案1】:

    对修改区块链的函数的调用需要作为交易发送,因为它需要 gas 才能运行。这就是为什么您需要发送交易而不仅仅是调用函数的原因。你可以在here找到更多相关信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-22
      • 2018-04-29
      • 2018-07-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-28
      • 2019-01-17
      • 2019-04-07
      相关资源
      最近更新 更多