New to Rust? Grab our free Rust for Beginners eBook Get it free →
How to Use Solidity in VS Code: Extension and Compiler Setup

VS Code can edit Solidity files, but a useful setup needs language support and a compiler check.
Install Solidity support in VS Code
I compiled the small Counter contract below with solc so you can inspect the editor workflow through a compiler result. Open Extensions in VS Code, search for Solidity by Nomic Foundation, and install the listing published by Nomic Foundation.
Hardhat documents the extension for Solidity language support and project integration, while VS Code documents Extensions as the mechanism for adding language features. The extension does not replace the compiler or the project tool that resolves imports, runs tests, and deploys contracts.
Create a small Solidity contract
Create a folder named src, then save this file as Counter.sol. The SPDX license identifier and pragma belong at the top of the source file, as described in the Solidity documentation.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract Counter {
uint256 public count;
function increment() external {
count += 1;
}
}
The public count variable gets a generated getter, and increment changes its stored value. The pragma accepts compatible 0.8 compiler releases rather than selecting one compiler build by itself.
Compile the contract locally
Install solc in the project directory, then use a short Node script to pass the file to the compiler. This check catches Solidity syntax and type errors before you connect the contract to a test or deployment workflow.
npm install solc
node src/compile.js
Save this compile.js file beside Counter.sol inside src. It requests the contract ABI, stops on compiler errors, and prints a small result you can inspect.
const fs = require("node:fs");
const solc = require("solc");
const source = fs.readFileSync("src/Counter.sol", "utf8");
const input = {
language: "Solidity",
sources: { "Counter.sol": { content: source } },
settings: { outputSelection: { "*": { "*": ["abi"] } } }
};
const output = JSON.parse(solc.compile(JSON.stringify(input)));
const errors = output.errors ?? [];
const failures = errors.filter((item) => item.severity === "error");
if (failures.length) {
console.error(failures.map((item) => item.formattedMessage).join("\n"));
process.exit(1);
}
const contract = output.contracts["Counter.sol"].Counter;
console.log("Compiled Counter.sol");
console.log("Contract: Counter");
console.log(`ABI items: ${contract.abi.length}`);

Keep editor support and project tooling separate
The VS Code extension helps while you edit, whereas solc translates the source into contract output.
Fix common Solidity setup problems
Use a Hardhat or Foundry project when you need dependency handling, tests, local networks, or deployment tasks.
A pragma mismatch means the compiler does not satisfy the version range in the source file. Check the pragma first, then choose a compiler configuration that matches the project instead of editing the contract until the warning disappears.
An import error means the compiler needs the dependency and its import path from the project workspace.
Move the contract into a project
The standalone compiler check proves that Counter.sol parses and produces an ABI. Create a Hardhat or Foundry project next, move the contract into its contracts directory, and add a test before you deploy anything.




