Search code examples
ethereumsoliditysmartcontractstruffle

Calling External Contract throws error : VM Exception while processing transaction: revert


I've deployed the ScoreStore contract to test RPC, and it works fine. This is ScoreStore contract:

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];
    }
}

Now I want to use this contract on another contract named MyGame, the contract code is as follows:

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);
    }
}

When I give this command on truffle console, mg.ShowScore.call("Anna") it thorws this:

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)

Any idea, what i am doing wrong? Any help is appreciated, P.S: testrpc is already running.


Solution

  • I was able to compile both the contracts in remix and call the ShowScore function after setting some value from ScoreStore contract successfully.

    Are you sure the address given to the interface is correct? Because I got the same revert error when I gave an invalid address.