ethereum - 调用外部契约(Contract)抛出错误 : VM Exception while processing transaction: revert

标签 ethereum solidity smartcontracts truffle

我已经部署了 ScoreStore 合约来测试 RPC,它运行良好。这是 ScoreStore 合约:

pragma solidity ^0.4.4;
contract ScoreStore 
{
    mapping(string => int) PersonScores;

    function SetScore(string name, int score) {
        if(PersonScores[name]>0){
            throw;
        }
        else{
            PersonScores[name] = score;
        }
    }

    function GetScore(string name) returns (int){
        return PersonScores[name];
    }
}

现在我想在另一个名为MyGame的合约上使用这个合约,合约代码如下:

pragma solidity ^0.4.4;
contract IScoreStore{
    function GetScore(string name) returns (int);
}
contract MyGame{
    function ShowScore(string name) returns (int){
        // Interface takes an address of the existing contract as parameter
        IScoreStore ss = IScoreStore(0x6c38cfb90e8fb1922e61ea4fbe09d29c7751bf82); 
        return ss.GetScore(name);
    }
}

当我在 truffle 控制台上发出这个命令时,mg.ShowScore.call("Anna") 它抛出了这个:

Error: VM Exception while processing transaction: revert
    at XMLHttpRequest._onHttpResponseEnd (C:\Users\Fariha.Abbasi\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\xhr2\lib\xhr2.js:509:1)
    at XMLHttpRequest._setReadyState (C:\Users\Fariha.Abbasi\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\xhr2\lib\xhr2.js:354:1)
    at XMLHttpRequestEventTarget.dispatchEvent (C:\Users\Fariha.Abbasi\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\xhr2\lib\xhr2.js:64:1)
    at XMLHttpRequest.request.onreadystatechange (C:\Users\Fariha.Abbasi\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\web3\lib\web3\httpprovider.
    at C:\Users\Fariha.Abbasi\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\truffle-provider\wrapper.js:134:1
    at C:\Users\Fariha.Abbasi\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\web3\lib\web3\requestmanager.js:86:1
    at Object.InvalidResponse (C:\Users\Fariha.Abbasi\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\web3\lib\web3\errors.js:38:1)

知道吗,我做错了什么? 感谢任何帮助,P.S:testrpc 已经在运行。

最佳答案

我能够在 remix 中编译两个合约,并在成功设置 ScoreStore 合约的一些值后调用 ShowScore 函数。

你确定给接口(interface)的地址是正确的吗?因为我在提供无效地址时遇到了相同的还原错误。

关于ethereum - 调用外部契约(Contract)抛出错误 : VM Exception while processing transaction: revert,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49339297/

相关文章:

blockchain - 为什么我在宠物店买不到 100 以太币?

Windows 上的 Docker : Error starting protocol stack: listen unix/root/. ethereum/geth.ipc:绑定(bind):不允许操作

ethereum - 由于重新混合时出现气体错误,重入代码未执行

执行智能合约时的 Solidity 错误消息 : “The called function should be payable if you send value...”

smartcontracts - 如何使用 RIDE 函数解码编码的附件?

javascript - 如何显示智能合约中的所有事件日志?

npm - 安装后找不到松露命令

ethereum - 我如何强制交易在某个 future 的区 block #上执行? (以太坊,JS API)

blockchain - 所需的gas超过限额或总是在Geth私有(private)区 block 链上失败,但在其他区 block 链上运行良好

node.js - Web3.js 查看方法 call() 错误,因为返回值无效,是否耗尽了气体