0

I need to call a function from another contract, but is it possible that the caller is the calling contract, and not msg.sender/wallet?

For example

contract BrainGame {
function updateGameScores(uint _scores, address _user) public onlyAdmin {
    userScores[_user] = _scores;
}

}

The onlyAdmin modifier is defined in the contract, and the UserPlay contract is added as an Admin (which could update the scores)

contract UserPlay {
    BrainGame bg = BrainGame(0x000ContractAddress000);
function playGame(uint _fun) public {
    /// game logic goes

    bg.updateGameScores(_fun, msg.sender);
}

}

My question is, can updateGameScores function be called by UserPlay instead of wallet/msg.sender? Can we call a function (from another contract) and caller be the calling contract (instead of wallet/msg.sender)?

Thanks.

Zeeshan
  • 103
  • 4

1 Answers1

0

Yes, and in this case it will be. Msg.sender is the last contract/entity in the contract call stack, and tx.origin is what you use to get the original wallet of whoever started the interaction in the first place. Usually you do not want to use tx.origin in practice.

Bruce
  • 947
  • 3
  • 10