Editing the storage of a remote contract

As was the case for reading contract storage, you cannot modify states of another contract without defining a setter function.

Let’s have a look at the following example:

contract ContractA {
uint256 public state;
function setstate(uint _value) {
state = _value;
}
}

contract ContractB{
ContractA public OneInstance = new ContractA();

function getstateA() public {
OneInstance.state = 12;
OneInstance.setstate(12);
}
}

The OneInstance.state = 12; line in the getstateA method will raise an error. We need instead to call the setstate() setter to update the state value.

The need for getters (read) and setters (update) in intra-contract interactions demonstrates the importance of the CRUD pattern.

Let’s get back to our game code. So far, in our Ctontine contract, we have declared the required states and our constructor is already defined. All we are missing is implementing the Ctontine contract methods.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset