调用外部合同会引发错误:处理事务时VM异常:恢复

法里哈·阿巴斯(Fariha Abbasi)

我已经部署了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)

任何想法,我在做什么错?感谢您的任何帮助,PS:testrpc已经在运行。

苏拉杰·科利(Suraj Kohli)

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

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Openzepplin众包合同获得:处理事务时VM异常:恢复错误

错误:返回错误:处理事务时的 VM 异常:恢复余额不足 -- 给出的原因:余额不足

处理事务时VM异常:用完了

错误:返回的错误:处理事务时VM异常:使用New创建时还原

DeployedAddresses +错误:处理事务时虚拟机异常:恢复

骆驼异常/错误处理事务路由而不会导致客户端异常

在C#循环中调用SQL存储过程时处理事务

有些交易有效,有些则无效。处理事务时出现UnhandledPromiseRejectionWarning和VM异常

在foreach循环中插入列表时如何处理事务

在StepExecutionListener中的Spring批处理事务

使用容器管理事务时如何处理异常

在.then()内部调用函数会引发错误

当我使用Appcache清单请求外部资源时,为什么jQuery会引发错误?

调用connect方法时,Web蓝牙API会引发错误“不受支持的设备”

如何在Fabric8中处理事务日志?

线程化Django任务不会自动处理事务或数据库连接吗?

Firebase RTDB 批处理事务(同时增加 2 个值)

如何为 Firebase 管理实时数据库编写批处理事务?

在ViewPager中处理事务后,ListFragment显示空白屏幕

SQL适配器可以处理事务(开始/插入/回滚)吗?

使用定期提交从csv加载大数据时如何在Neo4j中处理事务回滚

为什么onSubmit中的方法调用会引发错误?

有时JavaScript代码块会引发错误

处理日期时Export-Csv引发错误

将测试文件定义为模块时,使用hspec定义的通过堆栈调用的测试会引发错误

调用Web API操作时Jquery Ajax引发错误

Flutter/Dart API 调用引发错误(有时)

Ajax调用失败,但在调试时未引发错误

服务合同的RealProxy引发WCF错误异常