Home » Warning: SPDX license identifier not provided in source file

Warning: SPDX license identifier not provided in source file

Last updated on May 13, 2022 by

In this article, we will see how to solve the “Warning: SPDX license identifier not provided in the 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.” warning in a solidity programming language. Let’s just see how to resolve it.

Solution for Warning: SPDX license identifier not provided in the source file

A solution to this problem is already included in the warning message. From Solidity ^0.6.8 SPDX license is introduced. So you need to use SPDX-License-Identifier: <SPDX-License> in the first line of your contract with comments like below:

// SPDX-License-Identifier: MIT

You just need to write your own license according to your project in place of <SPDX-License>. For example, GPL-3.0, MIT, UNLICENSED, etc. For more licenses visit this link https://spdx.org/licenses/

Notes: If you do not want to specify a license or if the source code is not open-source, please use the special value UNLICENSED.

Example

// SPDX-License-Identifier: GPL-3.0

pragma solidity >=0.7.0 <0.9.0;

/**
 * @title Storage
 * @dev Store & retrieve value in a variable
 */
contract Storage {

    uint256 number;

    /**
     * @dev Store value in variable
     * @param num value to store
     */
    function store(uint256 num) public {
        number = num;
    }

    /**
     * @dev Return value 
     * @return value of 'number'
     */
    function retrieve() public view returns (uint256){
        return number;
    }
}

Why SPDX License Identifier Required

Trust in smart contracts can be better established if their source code is available. Since making source code available always touches on legal problems with regards to copyright, the Solidity compiler encourages the use of machine-readable SPDX license identifiers.

The comment is recognized by the compiler anywhere in the file at the file level, but it is recommended to put it at the top of the file.

You can find all SPDX license lists here: https://spdx.org/licenses/

That’s it for now. We hope this article helped you to learn more about the Warning: SPDX license identifier not provided in the source file.

Additionally, read our guide:

  1. jQuery Form Submit With Examples
  2. Check If Array Is Empty Or Undefined In JavaScript
  3. How To Detect IE Browser In JavaScript
  4. AJAX PHP Post Request With Example
  5. How To Declare A Global Variable in Vue
  6. How To Remove A Specific Item From An Array In JavaScript
  7. How To Check Array Contains A Value In JavaScript
  8. How To Merge Objects In Vue
  9. How to Allow Preview of Draft Post Without Login in WordPress
  10. Import Users From CSV In WordPress Programmatically
  11. Dynamically Populate A Select Field’s Choices In ACF
  12. How To Create Database Table In WordPress
  13. Difference Of require, include, require_once And include_once
  14. PHP: Get Day Name From Date
  15. PHP: Get Year From Date
  16. How To Update Pivot Table In Laravel

Please let us know in the comments if everything worked as expected, your issues, or any questions. If you think this article saved your time & money, please do comment, share, like & subscribe. Thank you in advance 🙂. Keep Smiling! Happy Coding!

Leave a Comment

*

code