[英]Why msg.sender has the address of the deployer (address isnt the caller)
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. msg.sender
有来自合约而不是来自调用者的部署者的地址。
address public caller;
constructor() {
caller = msg.sender;
}
Using remix.ethereum.org
and pragma solidity >=0.7.0 <0.9.0;
使用
remix.ethereum.org
和pragma solidity >=0.7.0 <0.9.0;
and deployed on the JavaScript VM (London).并部署在 JavaScript 虚拟机(伦敦)上。
Can someone explain me why?有人可以解释我为什么吗?
Right now caller
is going to be equal to the address that deployed the contract because that is what msg.sender
will reference.现在
caller
将等于部署合约的地址,因为这是msg.sender
将引用的内容。 If you are trying to make caller
be the contract address instead, then you need to do caller = address(this);
如果你想让
caller
成为合约地址,那么你需要做caller = address(this);
. .
address(this)
is the actual contracts address. address(this)
是实际的合约地址。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.