Skip to content

Create Your First Smart Contract

Now we are creating a new file and inserting some Solidity code. Don't worry if you don't fully understand everything - we have to start somewhere and we're here to play around. Just follow along, I promise everything will be clear later on!

Create A New File

Click on the plus icon in the code-editor and create a new file, name it "MyContract.sol". The sol-extension stands for Solidity.

Add Solidity Hello World Code

Now add the following code to the file:

// SPDX-License-Identifier: GPL-3.0

pragma solidity ^0.8.1;

contract MyContract {
    string public myString = 'hello world';

It should look like this and the "Compiler" Plugin should have a green checkmark badge. That's the icon in the left side panel:

Wondering what that all means?

This is a very basic version of a Smart Contract. Let's go through it line by line:

// SPDX-License-Identifier: GPL-3.0: The The Software Package Data Exchangeยฎ (SPDXยฎ) identifier is there to clearly communicate the license under which the Solidity file will be made available. Well, if you make it available. But you should. Smart Contracts transparency and trust greatly benefit from the source being published and sometimes it's not 100% clear under which license the source is out in the wild. The SPDX identifier is optional, but recommended.

pragma solidity ^0.8.1: The pragma keyword is for the compiler to enable certain features or check certain things. The version pragma is a safety measure, to let the compiler know for which compiler version the Solidity file was written for. It follows the SemVer versioning standard. ^0.8.1 means >=0.8.1 and <0.9.0.

contract MyContract: That's the actual beginning of the Smart Contract. Like a Class in almost any other programming language.

string public myString = 'hello world': That is a storage variable. It's public and Solidity will automatically generate a getter function for it - you'll see that in a minute!

Perfect! Let's proceed to deploy this Smart Contract to a Blockchain!

Last update: March 28, 2022