Compiling with slang
This guide shows you how to use the hardhat-slang plugin to compile your contracts faster while you develop.
What is slang?
Section titled “What is slang?”slang is a Solidity compiler based on LLVM. It compiles faster, produces better optimized bytecode, and removes “stack too deep” errors. See the performance numbers in our announcement blog post.
Use it to speed up your development workflow and CI builds. Avoid using it to deploy to production networks, as slang is still under development. By default, the plugin will not allow usage in production Build Profiles, unless config settings are explicitly overridden.
The easiest way to use slang is with the hardhat-slang plugin. Read the rest of this guide to learn how to set it up.
Setting up hardhat-slang
Section titled “Setting up hardhat-slang”Installing the plugin
Section titled “Installing the plugin”First, install the plugin and add it to your Hardhat config:
-
Install the plugin:
Terminal window npm add --save-dev @nomicfoundation/hardhat-slangTerminal window pnpm add --save-dev @nomicfoundation/hardhat-slangTerminal window yarn add --dev @nomicfoundation/hardhat-slang -
Add it to the list of plugins in your config:
hardhat.config.ts import { defineConfig } from "hardhat/config";import hardhatSlang from "@nomicfoundation/hardhat-slang";export default defineConfig({plugins: [// ...other plugins...hardhatSlang,],// ...other config fields...});
The plugin extends the values that your Solidity config accepts, adding a new compiler type named slang. Hardhat won’t use this new type automatically, so you’ll need to modify your config to use it.
Using the slang compiler type in your config
Section titled “Using the slang compiler type in your config”The plugin is configured with a slang Build Profile:
import { defineConfig } from "hardhat/config";import hardhatSlang from "@nomicfoundation/hardhat-slang";
export default defineConfig({ plugins: [ // ...other plugins... hardhatSlang, ], // ...other config fields... solidity: { profiles: { // ...existing solidity config... slang: { type: "slang", version: "0.8.37", }, }, },});With the type: "slang" property set, Hardhat will use slang to build your contracts and tests whenever you use this Build Profile. Any compiler without a type keeps using solc.
The version of a compiler with type: "slang" is the Solidity version. It needs to be set to one of the supported Solidity versions, like 0.8.37, or Hardhat will report a config error.
Splitting compilation between slang and solc for older unsupported versions
Section titled “Splitting compilation between slang and solc for older unsupported versions”slang supports all Solidity versions 0.8.0 - 0.8.37. See the full list of versions to check which versions work with slang.
For codebases that still rely on Solidity versions prior to 0.8.0, you can mix solc and slang in the same Build Profile. To learn how, read Using solc and slang in the same Build Profile.
Building and testing with slang
Section titled “Building and testing with slang”With that in place, use slang by passing the --build-profile slang flag to your build command:
npx hardhat build --build-profile slangpnpm hardhat build --build-profile slangyarn hardhat build --build-profile slangHardhat prints the compiler it uses for each set of contracts, so you can check there that slang picked them up.
You can also use it to run your tests:
npx hardhat test --build-profile slangpnpm hardhat test --build-profile slangyarn hardhat test --build-profile slangAdvanced topics
Section titled “Advanced topics”Using solc and slang in the same Build Profile
Section titled “Using solc and slang in the same Build Profile”If your project uses more than one Solidity version, you can list several compilers in the slang Build Profile. Those without the type field will use solc:
9 collapsed lines
import { defineConfig } from "hardhat/config";import hardhatSlang from "@nomicfoundation/hardhat-slang";
export default defineConfig({ plugins: [ // ...other plugins... hardhatSlang, ], // ...other config fields... solidity: { profiles: { // ...existing solidity config... slang: { compilers: [ { type: "slang", version: "0.8.37" }, { version: "0.7.6" }, // using `solc` for this unsupported version ], }, }, },});When building with this Build Profile, Hardhat will choose slang for the contracts that are compatible with 0.8.37, and solc for the ones that are only compatible with 0.7.6.
Configuring the optimizer
Section titled “Configuring the optimizer”slang always applies optimizations through LLVM. There is no unoptimized mode.
To set the level of LLVM-based optimizations, use the settings.optimizer.mode setting of your compiler config:
9 collapsed lines
import { defineConfig } from "hardhat/config";import hardhatSlang from "@nomicfoundation/hardhat-slang";
export default defineConfig({ plugins: [ // ...other plugins... hardhatSlang, ], // ...other config fields... solidity: { profiles: { // ...existing solidity config... slang: { type: "slang", version: "0.8.37", settings: { optimizer: { mode: "z", // optimize aggressively for size }, }, }, }, },});These are the available modes:
| Mode | What it does |
|---|---|
"1" | Least optimization, fastest to compile (the default). |
"2" | More runtime optimization. |
"3" | Best runtime performance. |
"s" | Smaller bytecode. |
"z" | Smallest bytecode. |
Using slang in other Build Profiles
Section titled “Using slang in other Build Profiles”By default, type: "slang" is only allowed in the slang profile. Using it anywhere else, including in default or production, is a validation error. That’s deliberate, because slang is still under development and isn’t ready to build contracts for production deployments.
If you understand the risk and still want slang in another Build Profile, set dangerouslyAllowSlangInProduction in the plugin’s own slang config section, next to solidity:
9 collapsed lines
import { defineConfig } from "hardhat/config";import hardhatSlang from "@nomicfoundation/hardhat-slang";
export default defineConfig({ plugins: [ // ...other plugins... hardhatSlang, ], // ...other config fields... solidity: { profiles: { default: { type: "slang", // allowed only because of the option below version: "0.8.37", }, slang: { type: "slang", version: "0.8.37", }, }, }, slang: { dangerouslyAllowSlangInProduction: true, },});Pinning a slang release
Section titled “Pinning a slang release”One slang binary compiles a range of Solidity versions (0.8.x). The plugin downloads a single release, the one pinned in slang.version, and uses it for every type: "slang" compiler entry. By default, that’s the latest release known to your version of the hardhat-slang plugin. Upgrading the plugin can therefore upgrade slang, and your next build compiles your contracts with the new release.
To stay on a specific slang release, set the version in the slang config section:
9 collapsed lines
import { defineConfig } from "hardhat/config";import hardhatSlang from "@nomicfoundation/hardhat-slang";
export default defineConfig({ plugins: [ // ...other plugins... hardhatSlang, ], // ...other config fields... slang: { version: "0.1.0-pre.2026-10-14", },});The supported slang releases are listed in the Supported Solidity versions section of the plugin’s README.
Supported Solidity versions
Section titled “Supported Solidity versions”slang supports Solidity versions from 0.8.0 to 0.8.37.
Supported EVM versions
Section titled “Supported EVM versions”slang supports these EVM versions as compilation targets: cancun, prague, and osaka.