2024-01-08
*post*
================================================================================

VSCode for Foundry

================================================================================

0 CONTENTS

*post-contents*

*post-intro*

1 INTRO

Hey there! If you’re into blockchain development, particularly with Solidity, and love using Foundry, you’re in the right place. Today, I’m going to walk you through setting up Visual Studio Code (VSCode) to work seamlessly with Solidity and Foundry. Let’s dive in!

*post-install-extension*

2 INSTALL EXTENSION

First things first, to get Solidity support in VSCode, you need to install the  VSCode Solidity extension. This extension is a must-have for any Solidity developer using VSCode.

*post-remappings*

3 REMAPPINGS

Remappings are crucial in ensuring that your project’s dependencies are correctly resolved. Here’s how to set them up:

*post-configure-dependencies*

4 CONFIGURE DEPENDENCIES

To help the Solidity extension find your project’s dependencies, add these settings to your .vscode/settings.json:

{
    "solidity.packageDefaultDependenciesContractsDirectory": "src",
    "solidity.packageDefaultDependenciesDirectory": "lib"
}

Here, src is where your source code lives, and lib is your dependency directory.

*post-formatter*

5 FORMATTER

Good code formatting is non-negotiable. To enable Foundry’s built-in formatter and automatically format your code on save, add these settings to your .vscode/settings.json:

{
    "editor.formatOnSave": true,
    "[solidity]": {
        "editor.defaultFormatter": "JuanBlanco.solidity"
    },
    "solidity.formatter": "forge"
}

For more on configuring the formatter, check out the  Formatter reference.

*post-solc-version*

6 SOLC VERSION

Consistency in compiler versions between your IDE and Foundry is key. Specify your Solidity compiler version in .vscode/settings.json:

"solidity.compileUsingRemoteVersion": "v0.8.23",

And align Foundry with this version in foundry.toml:

solc = "0.8.23"

And there you have it! A straightforward guide to setting up your VSCode for a smooth Solidity development experience with Foundry. Remember, a well-set-up environment can make your coding experience much more enjoyable and efficient. Happy coding!

================================================================================

TAGS

*post-tags*

================================================================================

LINKS

*post-links*