Is it possible to call a contract in solidity, using its storage but passing along msg.sender?

185 views Asked by At

I have the following two contracts:


contract A {
  uint256 someData = 3

  function foo() public view returns (uint256) {
    // return something based on msg.sender and someData
  }
}

contract B {
  A public a;

  function bar() public {
    // I'd like to call a.foo with msg.sender for this context
    uint256 ret = a.foo()  
  }
}

As indicated, I want to call a.foo within B with the msg.sender in B's context, but I want to use someData in A's storage. This means that using delegatecall wouldn't work as it'd use B's storage for the A.foo call.

Is there any way to do what I want here? The problem has to do with the fact that the 'real' A is already deployed on mainnet and I can't change the way it's written.

1

There are 1 answers

1
ska On

I don't think this is possible as of now. I just faced the same issue but not able to find any solution. It would be better if you can create a new contract from scratch and deploy it again on mainnet by transferring all the tokens to new address.