@nomicfoundation/hardhat-slang-solx
v3.0.4
Published
Hardhat plugin for using solx compiler in test builds
Maintainers
Readme
Hardhat Slang Solx plugin
This plugin enables the slang-solx Solidity compiler in Hardhat. slang-solx is a Solidity compiler based on solc and LLVM. It compiles faster, produces better optimized bytecode, and gets rid of “stack too deep” errors.
The slang-solx compiler is currently experimental and is not ready for production use-cases. We recommend using the compiler for test builds and test execution locally, and continuing to use solc for production use-cases (including during deployment, for example with hardhat-ignition and in your CI). Care should be taken before enabling compilation with slang-solx in other build profiles, see configuration flags below.
The compiler was originally developed at Matter Labs under the name solx. It moved to the Nomic Foundation in 2025, where it was renamed slang-solx. Its repository and release assets still use the solx name.
💡 Tip: Read the Compiling with slang-solx guide for more details.
Installation
npm install --save-dev @nomicfoundation/hardhat-slang-solxThen add the plugin to your hardhat.config.ts and create a slang-solx build profile. You must use the build profiles config format, which requires both a default and a slang-solx profile:
import { defineConfig } from "hardhat/config";
import hardhatSlangSolx from "@nomicfoundation/hardhat-slang-solx";
export default defineConfig({
plugins: [hardhatSlangSolx],
solidity: {
profiles: {
default: {
version: "0.8.29",
},
"slang-solx": {
type: "slang-solx",
version: "0.8.34",
},
},
},
});The default profile uses solc as usual. The slang-solx profile uses the slang-solx compiler, identified by type: "slang-solx". Your .sol files should have compatible pragmas, for example pragma solidity ^0.8.29;. Strict pragmas for unsupported Solidity versions, for example pragma solidity 0.8.28;, will currently not compile with the hardhat-slang-solx plugin. See more details below for the currently supported Solidity versions and EVM versions.
Usage
Run tests or compile using the slang-solx build profile:
hardhat test --build-profile slang-solx
hardhat build --build-profile slang-solxThe default profile continues to use solc as usual:
hardhat build # uses solc (default profile)Configuration
Multi-version example
You can configure the slang-solx profile with multiple compilers. Compilers without type: "slang-solx" will use solc:
export default defineConfig({
plugins: [hardhatSlangSolx],
solidity: {
profiles: {
default: {
compilers: [{ version: "0.8.34" }, { version: "0.8.20" }],
},
"slang-solx": {
compilers: [
{ type: "slang-solx", version: "0.8.34" },
{ version: "0.8.20" }, // uses solc, slang-solx doesn't support this version
],
},
},
},
});Options
dangerouslyAllowSlangSolxInProduction(boolean, default:false), allows compiler type"slang-solx"in build profiles other thanslang-solx. By default, usingtype: "slang-solx"in any other profile (e.g.default,production) will produce a validation error.
export default defineConfig({
plugins: [hardhatSlangSolx],
solidity: {
profiles: {
default: {
type: "slang-solx", // allowed only because of the option below
version: "0.8.34",
},
"slang-solx": {
type: "slang-solx",
version: "0.8.34",
},
},
},
"slang-solx": {
dangerouslyAllowSlangSolxInProduction: true,
},
});Optimization level
slang-solx optimizes via LLVM; set the level per profile with settings.optimizer.mode:
| 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. |
slang-solx has two independent optimizer knobs:
optimizer.mode(above) is the LLVM backend level. There is no "off" — the minimum is"1", so LLVM always optimizes.optimizer.enabledis the embedded solc front end's own optimizer,falseby default. It only affects the legacy pipeline, where it optimizes the EVM assembly slang-solx translates. UnderviaIR: trueit changes nothing but the metadata hash: slang-solx bypasses the Yul optimizer entirely, so the IR handed to LLVM is always unoptimized.
For example, optimizing for size instead of performance:
import { defineConfig } from "hardhat/config";
import hardhatSlangSolx from "@nomicfoundation/hardhat-slang-solx";
export default defineConfig({
plugins: [hardhatSlangSolx],
solidity: {
profiles: {
default: { version: "0.8.34" },
"slang-solx": {
type: "slang-solx",
version: "0.8.34",
settings: { optimizer: { mode: "z" } }, // optimize for size
},
},
},
});Or, on the legacy pipeline, run the front end's assembly optimizer before LLVM -O3 (both knobs on) — just the slang-solx profile:
"slang-solx": {
type: "slang-solx",
version: "0.8.34",
settings: { optimizer: { enabled: true, mode: "3" } },
},Supported Solidity versions
slang-solx maps each Solidity version to a specific slang-solx binary version internally. Currently supported: 0.8.34 (solx 0.1.8). Earlier slang-solx releases did not emit the DWARF debug info that EDR relies on for Solidity stack traces, so they are not supported by this plugin.
EVM version support
slang-solx supports EVM versions cancun, prague, and osaka. Using an older EVM target (e.g., paris, shanghai) with compiler type "slang-solx" will result in a validation error.
