我得到了下面的代码错误
// 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;
任何帮助都是非常感谢的。
发布于 2022-09-24 01:17:02
您使用保留关键字msg声明状态变量:
string public msg = "Hello World";你不会想那样做的。您不应该尝试声明作为Solidity的保留关键字的变量,比如全局可用的msg。因此,你实际上是在“推翻”或隐藏它。
最好声明如下:
string public message = "Hello World";整个代码将如下所示:
// 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;
}
}发布于 2022-09-24 01:08:10
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"
}
}https://ethereum.stackexchange.com/questions/136259
复制相似问题