0

I am trying to pass configuration values from one contract to another, so I can change them and avoid transaction fees.

I have two contracts:

pragma solidity ^0.4.23;

import "./two.sol";

contract One{

    string name;

    constructor() public{

    }

    Two two;

    function getNameFromOtherContract() public returns(string) {
        name = two.getName();
        return name;
    }
}

And second:

pragma solidity ^0.4.23;

contract Two{

    constructor() public{
    }

    function getName() external pure returns (string name) {
        name = "Amel";
    }
}

When I triger getNameFromOtherContract I get:

transact to One.getNameFromOtherContract errored: VM error: revert. revert The transaction has been reverted to the initial state.

What would be the correct syntax and solution for this approach?

  • Is unclear how you are planning to avoid transaction fees using this approach. Two is not deployed, or is it? – Jaime May 16 '18 at 17:03
2

1) You're one contract is not setting the variable two to the deployed two contract's address. This is why you're getting a revert error.

Rev A) fixed code

pragma solidity ^0.4.23;

import "./Two.sol";

contract One{

    string name;
    Two two;

    constructor() public{
        two = new Two();
    }

    function getNameFromOtherContract() public returns(string) {
        name = two.getName();
        return name;
    }
}

Rev B (actually setting the address of contract two via the constructor of contract one. Note: this requires two to be deployed before one)

pragma solidity ^0.4.23;

import "./Two.sol";

contract One{

    string name;
    Two two;

    constructor(address _two) public{
        require(_two != address(0));
        two = Two(_two);
    }

    function getNameFromOtherContract() public returns(string) {
        name = two.getName();
        return name;
    }
}

2) I'm not sure how you're going to accomplish this part: change them and avoid transaction fees. Please explain further and I'll be happy to assist.

| improve this answer | |
  • I will use call functions which do not change state so there is no transaction happening which means there is no mining. – sensei May 16 '18 at 19:49
  • call functions which do not change state This means you can read variables but not change them. Changing variables require a state change - which requires a tx. – Matt Swezey May 16 '18 at 20:33
  • Correct, that’s what i want to achieve – sensei May 17 '18 at 4:34

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.