One of the first programming languages for writing smart contracts to enter the industry is Solidity. Solidity is an object-oriented and high-level programming language especially personalized for creating smart contracts.
Like any other language, we also need a code editor to write Solidity code. Code editors make writing languages easy with features like syntax highlighting, auto-suggestions, auto-indenting, code completion, code generation and more.
But with Solidity, it is hard to use regular code editors. There are many code editors that you can use to write Solidity code, but the one we will be talking about in this article is the most popular among them: VS Code.
The combination of VS Code and Solidity can prove to be very useful. So let’s see how to use them together.
Also Read: Smart Contracts and Why They Matter – An Ultimate Beginner’s Handbook
What is Solidity?
Solidity is an object-oriented programming language created for the Ethereum network or the Ethereum Virtual Machine (EVM) to develop smart contracts. Solidity files are identified by a ‘.sol’ file extension. It is a statically typed 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 also supports inheritance, libraries, tools, and complex user-defined types, making coding easier for developers.
Remix IDE for Solidity
For people who have just started learning Solidity, it is recommended they use the Remix IDE which can be used directly on the browser. It comes with a great set of tools essential for Solidity. It even helps to run and deploy Solidity code to a local Ethereum network for testing.
Moreover, it is an open-source IDE. 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 also visit the official docs for more.
But if you are someone who likes to always use VS Code, we will see how to set it up for Solidity, but first let’s understand why we can’t directly use it on VS Code.
Trouble Accessing Solidity on VSCode
If you open VS Code and start writing Solidity, the first thing you will notice is VS Code doesn’t recognize Solidity as a programming language. It is foreign to it. Moreover, you will also see that the status bar doesn’t show ‘Solidity’ as soon as you save a .’sol’ file because VS Code acknowledges it as a plain text file.
The second problem is that if you avoid these issues and write your code, but then without any additional features, testing the behaviour of your smart contract becomes very difficult.
Hence we need to install a third-party extension so that VS code starts to recognise Solidity language, plus the extension imports additional features to help us with the development. Let’s see how to install it.
Set Up Solidity with VS Code
To set up Solidity with VS Code, we need to install an extension called ‘solidity’ by Juan Blanco from the Visual Studio Marketplace
Follow the below steps to install the VS Code extension ‘solidity’ by Juan Blanco:
- Open VS Code
- Look for ‘Extensions’ in the right sidebar and click it:
- Search for “solidity” and click the one whose author is “Juan Blanco“:
- Click “Install”:
- After it is installed, here’s how it looks.
- To check if the extension is working, create a “.sol” file:
You can notice that VS Code now generates an Ethereum icon for the “.sol” file we created.
- Checking the status bar:
- Finally, let us write some Solidity on VS Code:
Great! We are now successfully writing Solidity on VS Code!
Frequently Asked Questions (FAQs)
Is Solidity still used?
Yes, Solidity is still the most popular language for creating smart contracts, especially on the Ethereum blockchain. It cannot be dominated by any other language because it is one of the first programming languages for writing smart contracts to enter the industry.
Does VS Code support Solidity?
VS code doesn’t have built-in support for Solidity but by installing the Solidity extension we can make it recognise Soldity. The extension also has features like syntax highlighting, IntelliSense, and debugging tailored.
How do I format a Solidity code in VS Code?
You can format Solidity code in VS Code by using the built-in formatting shortcut. For Windows/Linux: Shift + Alt + F and For macOS: Shift + Option + F. This will not do Solidity-based formatting as relies on the generic code formatter. For advanced Solidity-specific formatting install Solidity extension.
How to install Solidity extension in Visual Studio Code?
Open VS Code and look for “Extensions” in the right sidebar and click it, then search for “solidity” and click the one whose author is “Juan Blanco”, finally, click on the “install” button to add the extension to your development environment.
Where can I write Solidity code?
For people who have just started learning Solidity, it is recommended to use the Remix IDE to write Solidity code. Although, you can write Solidity code on any code editor with an additional Solidty extension as some don’t have built-in support for it.
Is Solidity compiled to bytecode?
Yes, Solidity code needs to be compiled to bytecode in order to execute on the Ethereum Virtual Machine (EVM). This is done by the solc compiler.
Conclusion
The programming world comprises a large number of languages some of which we as developers might haven’t even heard of. The reason is 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. Hope you have learned how to use Solidity on VS Code with this beginner’s guide.
Read More: How to Send Ethereum to Message Sender in Solidity?