简体   繁体   English

为什么 msg.sender 有部署者的地址(地址不是调用者)

[英]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.orgpragma 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.

相关问题 为什么msg.sender具有已部署合同的帐户的地址(而不是与之交互的帐户的地址)? - Why msg.sender has the address of the account which has deployed the contract (and not the one's which interacts with it)? 在传递给另一个合约作为参数时,msg.sender地址是否已更改? - Is the msg.sender address changed while passing to another contract as a parameter? 如果我将地址作为参数传递,为什么我需要在 function 中使用`msg.sender`? - Why do I need to use `msg.sender` in my function if I pass an address as an argument? 下面代码中的 msg.sender 和 address(this) 有什么区别? - what is the differnce between msg.sender and address(this) in below code? 如何在不使用设置 msg.value 的情况下将资金从 msg.sender(amount) 转移到收件人地址 - how to transfer fund from msg.sender(amount) to recipient address without using setting msg.value ParserError:应为“;” 但得到了“事件”——solidity 0.8 address payable(msg.sender) - ParserError: Expected ';' but got 'event' -- solidity 0.8 address payable(msg.sender) function 调用中的参数类型无效。 从地址到请求的应付地址的隐式转换无效。对于 msg.sender 和地址 0 - Invalid type for argument in function call. Invalid implicit conversion from address to address payable requested.for msg.sender and adress 0 Msg.sender在“视图”功能中不起作用,为什么? 有解决方法吗? - Msg.sender does not work inside a “view” function, why? Is there a workaround? 检查 msg.sender 是否是特定类型的合约 - Check if msg.sender is a specific type of contract Solidity 基础知识:“msg.sender”代表什么 - Solidity basics: what "msg.sender" stands for
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM