不幸的是,我试图编译这段代码,但我通常会出错
I have tried to compile this code unfortunately i usually get error
这是代码:function () external payable {
编译时的错误:
ParserError: Expected a state variable declaration. If you intended this as a fallback function or a function to handle plain ether transactions, use the "fallback" keyword or the "receive" keyword instead. --> mytoken.sol:145:32: | 145 | function () external payable { | ^
出现此错误是因为您在 0.6 或更新版本中使用 Solidity 0.5 或更早版本的语法。
在Solidity 0.6中,fallback函数发生了变化,新的语法是
pragma solidity ^0.6;
contract MyContract {
fallback() external payable {
// TODO implement or leave empty
}
}
您可以在文档部分找到更多信息 breaking changes。
这是代码:function () external payable {
编译时的错误:
ParserError: Expected a state variable declaration. If you intended this as a fallback function or a function to handle plain ether transactions, use the "fallback" keyword or the "receive" keyword instead. --> mytoken.sol:145:32: | 145 | function () external payable { | ^
出现此错误是因为您在 0.6 或更新版本中使用 Solidity 0.5 或更早版本的语法。
在Solidity 0.6中,fallback函数发生了变化,新的语法是
pragma solidity ^0.6;
contract MyContract {
fallback() external payable {
// TODO implement or leave empty
}
}
您可以在文档部分找到更多信息 breaking changes。