调用外部合同会引发错误:处理事务时出现VM异常:还原

时间:2018-03-17 16:37:12

标签: 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);
    }
}

当我在松露控制台上发出此命令时,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已经在运行。

1 个答案:

答案 0 :(得分:0)

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

您确定接口的地址是否正确?因为当我提供无效地址时,我得到了相同的还原错误。

相关问题