Skip to content

Compiling with slang

This guide shows you how to use the hardhat-slang plugin to compile your contracts faster while you develop.

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.

First, install the plugin and add it to your Hardhat config:

  1. Install the plugin:

    Terminal window
    npm add --save-dev @nomicfoundation/hardhat-slang
  2. 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:

hardhat.config.ts
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.

With that in place, use slang by passing the --build-profile slang flag to your build command:

Terminal window
npx hardhat build --build-profile slang

Hardhat 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:

Terminal window
npx hardhat test --build-profile slang

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:

hardhat.config.ts
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.

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:

hardhat.config.ts
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:

ModeWhat it does
"1"Least optimization, fastest to compile (the default).
"2"More runtime optimization.
"3"Best runtime performance.
"s"Smaller bytecode.
"z"Smallest bytecode.

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:

hardhat.config.ts
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,
},
});

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:

hardhat.config.ts
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.

slang supports Solidity versions from 0.8.0 to 0.8.37.

slang supports these EVM versions as compilation targets: cancun, prague, and osaka.