2

I have the following solidity code.

pragma solidity ^0.4.21;

contract Parent {
    uint public childCount;
    Child[] public children;

    function makeChild(string name) external {
        children.push(new Child(address(this), childCount, name));
        childCount++;
    }

    function renameChild(uint index, string newName) external {
        require(address(children[index]) != 0);
        Child thisChild = Child(address(children[index]));
        if (thisChild.isUpdated()) {
            thisChild.rename(newName);
        }
    }
}

contract Child {
    address parentAddress;
    uint index;
    string public name;
    bool public isUpdated;

    constructor(address parent, uint _index, string _name) public {
        parentAddress = parent;
        index = _index;
        name = _name;
        isUpdated = false;
    }

    function rename(string newName) external {
        name = newName;
    }

    function renameViaParent(string updateName) external {
        isUpdated = true;
        Parent(parentAddress).renameChild(index, updateName);
    }
}

I have been testing this code via Remix Solidity IDE. When I run in Javascript VM, I can create a child from parentInstance.makeChild("childName") and rename it using childInstance.renameViaParent("newName").

However when I switch to an Ethereum private chain, i.e. Injected Web3, I can still create the child, but fail in renaming using childInstance.renameViaParent("newName"). It gives the message:

Gas estimation errored with the following message (see below). The transaction execution will likely fail. Do you want to force sending? Invalid JSON RPC response: {"id":1830,"jsonrpc":"2.0","error":{"code":-32603}}

I tried to remove thisChild.isUpdated() condition check in renameChild(index, newName) and the code ran fine in both JS VM and private Web3. This is why I believe accessing the member variable isUpdated of Child from Parent is causing the problem.

What is wrong here? Probably with my private chain set up? How is it different from the Javascript VM Remix is using?

I am using geth-linux-amd64-1.8.6-12683 to run my private chain.

TylerH
  • 20,799
  • 66
  • 75
  • 101
3tbraden
  • 667
  • 1
  • 10
  • 21

0 Answers0