solidityspdx

How do I add <SPDX-License> as a comment in my code?


pragma solidity >=0.6.0 <0.9.0;

contract SimpleStorage {

    //this will get initialized to 0!
    uint256 favoriteNumber;

    function store(uint256 _favoriteNumber) public {
        favoriteNumber = _favoriteNumber;

        //<SPDX-License>
    }
}

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. --> SimpleStorage.sol


Solution

  • The license identifier goes at the first line, before the pragma statement.

    Example:

    // SPDX-License-Identifier: UNLICENSED
    pragma solidity >=0.6.0 <0.9.0;
    
    contract SimpleStorage {