0

I'm currently developing on a simple Naming Service for the Ethereum Blockchain. msg.sender has the address of the deployer from the contract and not from the caller.

    address public caller;

      constructor() {
      caller = msg.sender;
   }

Using remix.ethereum.org and pragma solidity >=0.7.0 <0.9.0; and deployed on the JavaScript VM (London).

Can someone explain me why?

zerokamix
  • 23
  • 2
  • 1
    In which function do you check `msg.sender`? Here, in the constructor, `msg.sender` is the address of the deployer. That makes sense, because the account that deploys the contract, executes the constructor. – Rafał Leszko Apr 06 '22 at 07:31
  • How to make the constructor the caller? Or are there other ways todo that – zerokamix Apr 06 '22 at 07:34
  • @zerokamix What do you mean by "make the constructor the caller"? Constructor is a function that is executed only once - during the contract deployment... Do you want to assign the contract address to the `caller` variable? Or do you want the `caller` variable to always reflect the current `msg.sender`? – Petr Hejda Apr 06 '22 at 08:15

1 Answers1

0

Right now caller is going to be equal to the address that deployed the contract because that is what msg.sender will reference. If you are trying to make caller be the contract address instead, then you need to do caller = address(this);. address(this) is the actual contracts address.

Michael
  • 1,454
  • 3
  • 19
  • 45