Rise In Logo



Build on Scroll

Welcome to this part of the course where you will learn Solidity programming language. Solidity is specifically designed for Ethereum Virtual Machine (EVM) based blockchain like Scroll. Since it is specifically designed for smart contract development on blockchain, you will see it is more restricted than general purpose programming languages which lowers the learning curve.

What is Solidity?

Solidity is the main language used to create smart contracts on EVM-based blockchains. With Solidity, you can program the blockchain to do just about anything, from creating decentralized applications (dApps) to issuing your own cryptocurrencies.

Why Learn Solidity for Scroll?

Scroll is a layer 2 solution for Ethereum. By learning Solidity, you can create your own smart contracts and maybe decentralized applications (dApps). Also, by learning Solidity, you will have a better understanding of how blockchains work, what can be done with them and how to utilize any EVM based chain, including layer 2 solutions like Scroll.

Syntax and Comments in Solidity

Solidity's syntax might remind you a bit of JavaScript, but with its own flavor. It's strongly typed, meaning you have to be clear about what type of data (like numbers, strings, or more complex structures) you're working with. You have already seen a little bit Solidity in the video during the previous lesson, but again here is a tiny snippet to give you a taste:

// This is a comment - it's for you, not the computer.

pragma solidity ^0.8.0;

contract MyFirstContract {

    // Variables

    uint myNumber = 100;

    // Functions

    function getMyNumber() public view returns (uint) {

        return myNumber;

    }

}

In this snippet, // starts a comment, which is a note to yourself or others reading the code. Comments are ignored by the Solidity compiler, so they're purely for your benefit.

The Basics of Solidity

Solidity is built around contracts. Think of a contract as a class in object-oriented programming, if you're familiar with that. A contract can hold data, like the balance of an account, and it contains functions to read or modify that data. The beauty of Solidity is how it allows you to encode logic

that runs on the blockchain, making those agreements and transactions tamper-proof and automatic.

Writing Comments

As you saw earlier, comments are crucial for making your code readable. There are two types of comments in Solidity:

  • Single-line comments, which start with //.
  • Multi-line comments, which are enclosed between /* and */.

Use comments liberally to explain the "why" behind your code. It's not just about making it understandable to others; in the future you will also appreciate it, at least, I did 🙂.

Pragma and Versioning in Solidity

At the top of every Solidity file, you'll see a pragma line. This isn't about magical spells—`pragma` tells the compiler which version of Solidity your code is written for. Solidity is still evolving, and new versions can introduce changes that might break older code. Specifying the version ensures your contract behaves as expected.

Let’s see pragma in action:

pragma solidity ^0.8.0;

This line specifies that the contract is compatible with Solidity version 0.8.0 and newer minor releases, but not a new major version like 0.9.0, which could introduce breaking changes.

And there you have it—the first steps into the world of Solidity! We've covered the basics, from what Solidity is and why it's a hot skill to learn, to the syntax, comments, and versioning. In the next lesson, you will learn about variables and data types.

Comments

Anonymous

0/500

You need to enroll in the course to be able to comment!

Stay in the know

Never miss updates on new programs and opportunities.

Rise In Logo

Rise together in web3!