首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >msg.sender未被识别

msg.sender未被识别
EN

Ethereum用户
提问于 2022-09-24 00:36:33
回答 2查看 41关注 0票数 1

我得到了下面的代码错误

代码语言:javascript
复制
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7 ;

contract Variables {
   //Global variables
   uint public pubInt = 25;
   bool public truth = false;
   string public msg = "Hello World";

   function dosomething() public{
       uint8 v = 30;
       address sender = msg.sender;
   }

}

TypeError:在字符串存储参考文件中,在依赖于参数的查找之后,找不到或看不到成员“发件人”。->Web3 3/Variables.sol: 12 :25:\x{e76f}\x{e76f}地址发件人= msg.sender;

任何帮助都是非常感谢的。

EN

回答 2

Ethereum用户

回答已采纳

发布于 2022-09-24 01:17:02

您使用保留关键字msg声明状态变量:

代码语言:javascript
复制
string public msg = "Hello World";

你不会想那样做的。您不应该尝试声明作为Solidity的保留关键字的变量,比如全局可用的msg。因此,你实际上是在“推翻”或隐藏它。

最好声明如下:

代码语言:javascript
复制
string public message = "Hello World";

整个代码将如下所示:

代码语言:javascript
复制
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7 ;

contract Variables {
   //Global variables
   uint public pubInt = 25;
   bool public truth = false;
   string public message = "Hello World";

   function dosomething() public {
       uint8 v = 30;
       address sender = msg.sender;
   }

}
票数 1
EN

Ethereum用户

发布于 2022-09-24 01:08:10

代码语言:javascript
复制
pragma solidity ^0.8.7 ;

contract Variables {
   //Global variables
   uint public pubInt = 25;
   bool public truth = false;
   string public message = "Hello World"; // msg is a special global variable that needs to have a property or don't use it

   function dosomething() public{
       uint8 v = 30;
       address sender = msg.sender; // msg has a property called "sender"
   }
}
票数 0
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://ethereum.stackexchange.com/questions/136259

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档