[英]Why msg.sender has the address of the account which has deployed the contract (and not the one's which interacts with it)?
I am currently developing a dapp on ethereum. 我目前正在以太坊上开发一个dapp。 From what I know msg.sender should has the value of the account who interact with it. 据我所知,msg.sender应该具有与其交互的帐户的价值。 However, it keeps the value of the deployer's account. 但是,它保留了部署者帐户的价值。
I am using metamask and solidity ^0.4.24. 我正在使用metamask和solidity ^ 0.4.24。 I am deploying the contact using truffle framework and also Ganache GUI as my virtual node 我正在使用松露框架以及Ganache GUI作为我的虚拟节点来部署联系人
function getMe() public view returns(address){
return msg.sender;
}
So, I expect this code to return the hash of the account which is interacting with the contract but instead I am taking back the address of the acount which deployed it 因此,我希望这段代码返回与合同进行交互的帐户的哈希,但是我要取回部署它的帐户的地址
msg.sender
contains the value of the address of the caller. msg.sender
包含调用方地址的值。 You must be deploying and interacting from the same account, probably using accounts[0]
. 您必须使用相同的帐户(可能使用accounts[0]
进行部署和交互。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.