How to Use Solidity on VS Code – An Easy Beginner’s Guide

Solidity On VS Code Featured Image

Are you a VS Code fan like me and recently started learning the Solidity programming language? Then this Solidity on VS Code guide is for you.

The programming world comprises a large number of languages some of which we as developers might haven’t even heard of. The reason being large-scale advancements occurring regularly and the rise of newer programming languages.

The Solidity programming language is just one of the incredible languages out there in the wild. Speaking of programming languages reminds me of code editors or IDEs. Code editors make it easier to write a language with features like syntax highlighting, auto-suggest, auto-indenting, language-specific tools, and a lot more.

The most popular of these is VS Code. To be honest, I am a big fan of it too! However, Solidity programmers face a small problem when working with VS Code. You cannot use Solidity on VS Code ☹. But, don’t worry there are ways you can!

Also read: Smart Contracts and Why They Matter – An Ultimate Beginner’s Handbook

Since most developers around here are beginners with Solidity, I would like to throw some light on a quick overview on what the Solidity programming language is all about.

What is Solidity?

Solidity is an object-oriented programming language created for the Ethereum network or the Ethereum Virtual Machine (EVM) so to say, to implement smart contracts. According to the official documentation, it is a curly bracket language.

If you are somewhat familiar with Python, C++, or JavaScript, then you will find it easier to learn Solidity because of its similarity with those languages. Like most other languages, this language too supports inheritance, libraries, tools, and complex user-defined types, making coding easier for developers.

Solidity files are identified by a ‘.sol’ file extension name. It is a statically typed language. While I write, the latest stable version of Solidity released is v0.8.9. you can find the link to the Solidity official docs by clicking here.

What are Smart Contracts?

Smart contracts are nothing but applications or programs on the Ethereum network, that administer how accounts on the network behave.

They are nothing but programs or applications stored on decentralized blockchains. They run when predetermined conditions are met and are commonly used to automate the execution of an agreement.

Here’s a simple smart contract code is written in Solidity:

contract Inbox {
    string public message;

    function Inbox(string initialMessage) public {
        message = initialMessage;
    }

    function setMessage(string newMessage) public {
        message = newMessage;
    }

    function getMessage() public view returns (string) {
        return message;
    }
}

Looks so much like JavaScript, right? Well, it is even easier than the languages you already know! Read here in detail about Smart Contracts.

How to Use Solidity on VS Code

Okay, so now that we brushed a little bit on the basics, it is time we learn how to use Solidity on VS Code. Do you remember I mentioned we “can’t” write Solidity on VS Code? Well, we definitely can type Solidity code in our editor but the problem is, VS Code doesn’t recognize Solidity as a programming language.

It is something foreign to it. You must have noticed when you type Solidity on VS Code, the syntax looks pure white (on a dark VS Code theme) or light grey (on a light VS Code theme). Moreover, you will also notice the status bar doesn’t show ‘Solidity’ as soon as you save a .sol file.

All of this is an indication Solidity on VS Code is not yet recognized. However, I am here to help. All we need to do is install a small extension from the VS Code Extension Marketplace. We will be installing the extension named ‘solidity’ by Juan Blanco.

The Remix IDE for Solidity

For people who have just started learning Solidity, it is recommended they use the Remix IDE that is based on the browser. It comes with a great set of tools essential for Solidity, for example, the Solidity compiler, debugger, and helps your run and deploy your code to a local Ethereum network for testing.

Moreover, it is an open-source IDE made to write smart contracts using Solidity. You can install the Remix IDE application on your desktop or choose to use it on the browser. Here’s the Git repository of Remix. You can click here to visit the official docs.

Installing the Extension to Write Solidity on VS Code

Follow the below steps to install the VS Code extension ‘solidity’ by Juan Blanco to work with Solidity on VS Code easily.

  • Open VS Code
  • Look for ‘Extensions’ in the right sidebar and click it
Solidity On Vs Code Step1
  • Search for solidity and click the one whose author is ‘Juan Blanco’
Solidity On Vs Code Step2
  • Click install. I have already installed it, so here’s how it looks:
Solidity On Vs Code Step3
  • To check if the extension is working, I will create a .sol file
Solidity On Vs Code Step4

You can notice that VS Code now generates an Ethereum icon for the .sol file we created.

  • Checking the status bar:
Solidity On Vs Code Step5
  • Finally, let us write some Solidity on VS Code:
Solidity On Vs Code Step6

Great! We are now successfully writing Solidity on VS Code!

Conclusion

The programming world comprises a large number of languages some of which we as developers might haven’t even heard of. The reason being large-scale advancements occurring regularly and the rise of newer programming languages.

The Solidity programming language is just one of the incredible languages out there in the wild. Learn how to write or use Solidity on VS Code with this beginner’s guide.