简体   繁体   English

为什么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)?

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.

相关问题 为什么 msg.sender 有部署者的地址(地址不是调用者) - Why msg.sender has the address of the deployer (address isnt the caller) 在传递给另一个合约作为参数时,msg.sender地址是否已更改? - Is the msg.sender address changed while passing to another contract as a parameter? OpenZeppelin 的可拥有合约 vs 需要 msg.sender - OpenZeppelin's ownable contract vs require msg.sender 检查 msg.sender 是否是特定类型的合约 - Check if msg.sender is a specific type of contract 无法从智能合约向 msg.sender 发送以太币 - Not able to send ether to msg.sender from smart contract 如果我将地址作为参数传递,为什么我需要在 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? Solidity:从另一个具有相同 msg.sender 的合约调用合约函数 - solidity: call contract function from another contract with the same msg.sender Msg.sender在“视图”功能中不起作用,为什么? 有解决方法吗? - Msg.sender does not work inside a “view” function, why? Is there a workaround? 如何在不使用设置 msg.value 的情况下将资金从 msg.sender(amount) 转移到收件人地址 - how to transfer fund from msg.sender(amount) to recipient address without using setting msg.value
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM