![](/img/trans.png)
[英]Why msg.sender has the address of the account which has deployed the contract (and not the one's which interacts with it)?
[英]Why msg.sender has the address of the deployer (address isnt the caller)
我目前正在為以太坊區塊鏈開發一個簡單的命名服務。 msg.sender
有來自合約而不是來自調用者的部署者的地址。
address public caller;
constructor() {
caller = msg.sender;
}
使用remix.ethereum.org
和pragma solidity >=0.7.0 <0.9.0;
並部署在 JavaScript 虛擬機(倫敦)上。
有人可以解釋我為什么嗎?
現在caller
將等於部署合約的地址,因為這是msg.sender
將引用的內容。 如果你想讓caller
成為合約地址,那么你需要做caller = address(this);
. address(this)
是實際的合約地址。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.