Storage(variable n) of E won't get updated when I use call from contract D.
addressOfE = "0x13fac93069c10e977204b9b64502439740cbe46a"; //Contract E's address that exist on my private chain.
call does not update E's storage:
D.callSetN(addressOfE, 100); //I have waited transaction to be deployed.
D.getN(); //returns 0;
E.getN(); //returns 0;
delegatecall seems working:
D.delcallCfunc(addressOfE, 101); //I have waited transaction to be deployed.
D.getN(); //returns 101;
E.getN(); //returns 0;
callcode seems working:
D.callcodeSetN(addressOfE, 102); //I have waited transaction to be deployed.
D.getN(); //returns 102;
E.getN(); //returns 0;
[Q] What should I do to update E's storage by calling contract D's function? Is it possible?
I have tried the exact same tutorial on the following guide: https://ethereum.stackexchange.com/a/3672/4575
contract D {
uint public n;
address public sender;
function callSetN(address _e, uint _n) {
_e.call(bytes4(sha3("setN(uint256)")), _n); // E's storage is set, D is not modified
}
function callcodeSetN(address _e, uint _n) {
_e.callcode(bytes4(sha3("setN(uint256)")), _n); // D's storage is set, E is not modified
}
function delegatecallSetN(address _e, uint _n) {
_e.delegatecall(bytes4(sha3("setN(uint256)")), _n); // D's storage is set, E is not modified
}
function getN() constant returns(uint){
return n;
}
function getSender() constant returns(address){
return sender;
}
}
contract E {
uint public n;
address public sender;
function setN(uint _n) {
n = _n;
sender = msg.sender;
// msg.sender is D if invoked by D's callcodeSetN. None of E's storage is updated
// msg.sender is C if invoked by C.foo(). None of E's storage is updated
}
function getN() constant returns(uint){
return n;
}
function getSender() constant returns(address){
return sender;
}
}
Thank you for your valuable time and help.
_e.call.gas(5000)(bytes4(sha3("setN(uint256)")), _n)– Tjaden Hess Mar 29 '17 at 19:01