To build trust in smart contracts, some of them make the source code available. To prevent legal problems regarding copyright, it is important to specify the license of the smart contract.
The most commonly used license is probably the MIT license and it can be specified with the following line of code:
// SPDX-License-Identifier: MIT
The MIT license makes the code available as free and open-source, however, the author is not liable for damages from the use of the software and the author still owns the copyright, so others can't remove the license.
It is recommended to specify the license in the first line of code, however, the compiler will recognize it anywhere in the file.
The SPDX license identifier is supplied in the bytecode metadata by the compiler.
A list of allowed licenses can be found on the SPDX website. If the source code is not open-source, it can be specified as UNLICENSED.
Errors and Warnings
In case the SPDX license identifier is not specified anywhere in the source file, the Solidity Parser will raise a Warning.
Warning: SPDX license identifier not provided in source file. Before publishing, consider adding a comment containing "SPDX-License-Identifier: " to each source file. Use "SPDX-License-Identifier: UNLICENSED" for non-open-source code. Please see https://spdx.org for more information.
In case the SPDX license identifier is defined more than once, a ParserError is raised.
ParserError: Multiple SPDX license identifiers found in source file. Use "AND" or "OR" to combine multiple licenses. Please see https://spdx.org for more information.
To fix warnings and errors, specify the SPDX license identifier at the first line of the smart contract in the correct format.