Skip to content

4.2. Choosing a Solidity Version#

Supported Versions#

Slang aims to support all Solidity language versions, starting with 0.4.11, and adding support for all future versions as they are released.

In order to use many of the Slang APIs, you will need to specify the Solidity version that you want to work with. You can see a list of all supported Solidity versions here.

You can also access this list programmatically, by using the LanguageFacts API:

supported-versions.mts
import assert from "node:assert";
import { LanguageFacts } from "@nomicfoundation/slang/utils";

test("supported versions", () => {
  assert.strictEqual(LanguageFacts.allVersions().length, 84);

  assert.strictEqual(LanguageFacts.earliestVersion(), "0.4.11");

  assert.strictEqual(LanguageFacts.latestVersion(), "0.8.29");
});

Inferring Compatible Solidity Versions#

For cases where you don't know in advance which version of Solidity to use, the LanguageFacts API provides a utility to generate a list of compatible versions. It uses the version pragmas defined in your Solidity source file to filter the list of versions supported by Slang, returning only the compatible ones.

The list is sorted in ascending order. The first item in the list will typically be the version that the code author used during development and testing, and the last item will be the latest version allowed by the code author and supported by Slang. If the source file does not contain any version pragmas, all versions supported by Slang will be returned.

infer-versions.mts
import assert from "node:assert";
import { LanguageFacts } from "@nomicfoundation/slang/utils";

const src = `
  pragma solidity ^0.8.0;

  contract Test {}
`;

test("infer versions", () => {
  const versions = LanguageFacts.inferLanguageVersions(src);

  assert(versions.includes("0.8.0"));
  assert(versions.includes("0.8.3"));
  assert(!versions.includes("0.7.8"));
  assert(!versions.includes("1.0.0"));

  const latest = versions.at(-1);
  assert(latest == "0.8.29");
});