Solidity SPDX-License-Identifier Line

whiteboard crypto logo
Published by:
Whiteboard Crypto
on

The SPDX-License-Identifier is a special line of code that put inside a comment to specific the licensing rights of a code. In Solidity, the License Identifier is used to let other developers know how they can use someone else’s code. In some cases, it is free to use, reproduce, or copy… however in other cases, it may be illegal to do so.

This is what the most common license, and you can use it to let anyone know they are free to use, copy, publish, or sell your code:

//SPDX-License-Identifier: MIT
SPDX License Identifier in Solidity

If you’ve been using the online Remix Solidity IDE, and you don’t have a license specified in the proper format, you may receive a warning like this:

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.
--> contracts/yourContract.sol

You can put the license identifier anywhere in your code, but many Solidity developers recommend and expect this line of code to be the very first line of code in a contract or file.

The first line of code in a solidity contract

Including an SPDX license in your software is important for several reasons.

First, it helps to ensure that users of your software understand what they are allowed to do with it. By providing a clear and standardized license that specifies the permissions, conditions, and limitations associated with your software, you can help to prevent misunderstandings and potential legal issues.

Second, an SPDX license can help to protect your own rights as the creator of the software. By clearly stating the terms under which your software is licensed, you can retain control over how it is used and distributed, and you can ensure that you receive proper attribution for your work.

Third, an SPDX license can also help to promote the growth and adoption of your software. Many users and organizations are more likely to use and contribute to software that is licensed in a clear and permissive way, and an SPDX license can help to signal to potential users and contributors that your software is open-source and freely available.

In short, including an SPDX license in your software can help to protect your rights, promote the growth and adoption of your software, and ensure that users understand and comply with the terms of the license.

How Many SPDX Licenses are there?

The MIT License is a permissive license that allows users to do pretty much anything they want with the licensed software, as long as they include a copy of the license and copyright notice with the software.

The Apache License 2.0 is another permissive license that allows users to distribute and modify the licensed software, as long as they include a copy of the license and properly attribute the original authors.

The GNU General Public License (GPL) is a copyleft license that requires users to distribute any modifications they make to the licensed software under the same license. This ensures that any derivatives of the licensed software remain open-source and freely available to the public.

When did Solidity introduce the License Identifier warning?

The developers of Solidity added the warning about not having a SPDX License in version 0.6.8, which was published around October 2020.

Can you have more than one license declared?

If you have more than one license declared, most IDEs will show an error instead of a warning.

It should also be noted that if you don’t want to select a predetermined license, you can always use the “UNLICENSED” term.

whiteboard crypto logo

WhiteboardCrypto is the #1 online resource for crypto education that explains topics of the cryptocurrency world using analogies, stories, and examples so that anyone can easily understand them. Growing to over 870,000 Youtube subscribers, the content has been shared around the world, played in public conferences and universities, and even in Congress.