Skip to content

solidstate-network/hardhat-license-identifier

Repository files navigation

Hardhat License Identifier

Automatically prepend Solidity source files in Hardhat projects with an SPDX License Identifier.

Versions of this plugin prior to 3.0.0 were released as hardhat-spdx-license-identifier, outside of the @solidstate namespace.

Versions of this plugin prior to 2.0.0 were released as buidler-spdx-license-identifier.

Installation

npm install --save-dev @solidstate/hardhat-license-identifier
# or
pnpm add -D @solidstate/hardhat-license-identifier

Usage

Load plugin in Hardhat config:

import hardhatLicenseIdentifier from '@solidstate/hardhat-license-identifier';

const config: HardhatUserConfig = {
  plugins: [
    hardhatLicenseIdentifier,
  ],
  licenseIdentifier: {
    ... // see table for configuration options
  },
};

Add configuration under the licenseIdentifier key:

option description default
license SPDX license to add to source files license field of package.json
overwrite whether to overwrite existing SPDX license identifiers false
runOnCompile whether to automatically prepend identifiers during compilation false
only Array of String matchers used to select included paths, defaults to all contracts if length is 0 []
except Array of String matchers used to exclude paths []
licenseIdentifier: {
  overwrite: true,
  runOnCompile: true,
  except: ['vendor/']
}

The included Hardhat task may be run manually. Its arguments override any existing configuration:

npx hardhat prepend-license UNLICENSED --overwrite
# or
pnpm hardhat prepend-license UNLICENSED --overwrite

Files which do not contain a license identifier will be prepended with one. Files with a license identifier which does not match that which is specified in package.json may be updated, depending on configuration.

Development

Install dependencies via pnpm:

pnpm install

Setup Husky to format code on commit:

pnpm prepare

About

©️ Prepend local Solidity source files with an SPDX License Identifier 🔨

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 6