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

Gog*_*gle 11 blockchain solidity remix

我创建了一个新的 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.
Run Code Online (Sandbox Code Playgroud)

编译时没有错误。

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

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

我的代码片段:

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


Run Code Online (Sandbox Code Playgroud)

小智 29

从 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
}
Run Code Online (Sandbox Code Playgroud)

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

// SPDX-License-Identifier: GPL-3.0-or-later
Run Code Online (Sandbox Code Playgroud)

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