警告:源文件中未提供 SPDX 许可证标识符

Warning: SPDX license identifier not provided in source file

我创建了一个新的 solidity 合约。合同已经到期,运行 但给我这个警告。

Warning: SPDX license identifier not provided in source file. Before publishing, consider adding a comment containing "SPDX-License-Identifier: <SPDX-License>" to each source file. Use "SPDX-License-Identifier: UNLICENSED" for non-open-source code. Please see https://spdx.org for more information.

编译没有错误

我在https://remix.ethereum.org/中使用的编译器版本是v0.7.5+commit.eb77ed08 语言:Solidity EVM 版本:编译器默认值

每当我按下编译时,它都会给我警告,但部署时没有问题。

我的代码片段:

pragma solidity ^0.7.5;
contract TestContract {
// Some logic
}


来自 Solidity ^0.6.8 引入了 SPDX 许可证。所以需要在代码中使用SPDX-License-Identifier

看看这个:https://forum.openzeppelin.com/t/solidity-0-6-8-introduces-spdx-license-identifiers/2859

例如,在您的代码中,您需要使用像

这样的许可证标识符
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.5;
contract TestContract {
// Some logic
}

您需要根据您的项目使用license。其他一些许可证是:

// SPDX-License-Identifier: GPL-3.0-or-later

您可以在此处找到许可证列表: https://spdx.org/licenses/

"// SPDX-License-Identifier: 麻省理工学院 " 在顶部添加这个。 这是Solidity扩展的问题,卸载它。然后安装然后关闭编辑器并重新加载它。

例如:

//SPDX-License-Identifier:麻省理工学院

pragma solidity ^0.8.14;