Sitemap

ParserError: Multiple SPDX license identifiers found in source file. Use “AND” or “OR” to combine multiple licenses — And How To Fix It (Hardhat)

2 min readJan 17, 2022

--

Press enter or click to view image in full size

By default, The flatten feature in hardhat doesn’t solve SPDX license identifiers conflicts. In this article I’ll provide two solutions:

  • Modifying hardhat.config.js
  • Script that fixes broken flattened contracts

These solutions are simplified and cleaner versions of BoringCrypto’s solution to this problem, found on #1050 at the hardhat github

Get Rubydusa’s stories in your inbox

Join Medium for free to get updates from this writer.

These also deal with multiple experimental ABI encoders deceleration in a file

Hardhat

For hardhat users, this can be fixed by adding the following task to your hardhat.config.js file:

This creates a task flat that has the exact same syntax and function as flatten, but changes the syntax of every SPDX-License-Identifier comment to match the MIXED SPDX-License-Identifier

How To Use

The newly created flat task operates identically to the flatten task. Example:

> npx hardhat flat contracts/ContractToFlatten.sol > path/to/Output.sol

Script

If you’re not using hardhat, the solution is the same but instead of the fix being a hardhat task, it is a script:

In this script the path to the flattened broken contract is set as a constant, but depending on your use case you may want to modify the script to accept input from the command line / return the fixed version as a value from a function

Incompatible Licenses

In the two solutions I provided, a program modifies a flattened contract with multiple SPDX license identifiers to a flattened contract with the SPDX License Identifier: MIXED and multiple license identifiers that define the mixed license.

Unfortunately, detecting incompatible SPDX licenses is not a trivial task, so solidity compilers won’t pick up on all incompatibility issues.

This shouldn’t be an issue most of the time since most of the popular smart contract libraries have very permissive licenses. For example, the Openzeppelin Contracts library is licensed under the MIT license

However, for a large serious project that uses code from a couple of different sources — extra caution may be needed

--

--