0

I'm trying to update a variable within an external contract.

My 2 contracts are as follow:

pragma solidity ^0.4.25;
contract MainContract {
string public variable1;

function setVariable1(string memory newValue) public {
    variable1 = newValue;
}}

contract SetContract {
//address MainContract;
MainContract myMainContract;  

constructor(
    address _myMainContract
) public {
    myMainContract = MainContract(_myMainContract);  
}

function setVariable1MainContract(string memory newValue) public {
    myMainContract.setVariable1(newValue);
}}

MainContracts holds the variable1 and de SetContract uses the setVariable1 function from MainContract.

When I deploy both contracts this works fine.

When I execute the function setVariable1MainContract I get an exception within Remix: "VM exception while processing transaction: revert".

Any suggestion is welcome.

  • Extra info: ofcourse I have deployed the SetContract with a reference to MainContract via the constructor. – Arnoud Apr 16 at 6:56
  • But have you deployed the MainContract? – goodvibration Apr 16 at 6:59
  • Yes @goodvibration I deployed both contracts – Arnoud Apr 16 at 7:16
  • Change MainContract myMainContract to MainContract public myMainContract, call SetContract.myMainContract() in Remix and let us know what you get. – goodvibration Apr 16 at 8:00
  • Hi @goodvibration, I added 'public' and called SetContract.myMainContract() within the setVariable1MainContract function. Now I get a compiler error: Typeerror: type is not callable. – Arnoud Apr 16 at 8:23
1

This issue was caused by an issue with Ganache. I reinstalled Ganache and the issue was resolved. Thanks for your help!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.