What every beginner should know about Solidity (2024)

Introduction to smart contracts programming language

What every beginner should know about Solidity (3)

Solidity is a programming language for implementing smart contracts on various blockchains, most notably, Ethereum. Smart contracts are programs which control the behavior of accounts within the Ethereum state. With Solidity you can create contracts for uses such as voting, crowdfunding, auctions, multi-signature wallets and many more.

Solidity is a curly-bracket language, which means it uses curly brackets to enclose blocks, as opposed to languages like Python, where blocks are defined by indentation. But Solidity documentation says that it is influenced not only by C++ and JavaScript, but also by Python. Anyway, from the syntax perspective you’ll find it close to C++ and other curly-bracket languages deriving syntax from plain old C, such as C# and Java.

If you are now scared of Solidity as a language like C++, please don’t worry, here are talking about syntax only, there’s no complex staff like manual memory management.

Below is a simple contract from the official Solidity documentation, which will demonstrate Solidity syntax:

// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.4.16 <0.9.0;

contract SimpleStorage {
uint storedData;

function set(uint x) public {
storedData = x;
}

function get() public view returns (uint) {
return storedData;
}
}

Influence from C++ can be seen in the syntax for variable declarations, loops, the concept of overloading functions, implicit and explicit type conversions, and many other details, as opposed to influence from Python, which is much less and can be seen only in multiple inheritance, super keyword, and few other features, like Solidity’s modifiers, which were added trying to model Python’s decorators with a much more restricted functionality.

You can find more details about which languages Solidity has been inspired by in the language influences section of the official Solidity documentation.

Since Solidity syntax is like C++ syntax, it has many of the same expressions and control structures typically used in curly-brace languages, like if, else, while, do, for, break, continue, and return. It also supports exception handling with try/catch statements.

Solidity is an object-oriented language, meaning that it follows OOP paradigm based on the concept of classes, which can contain data and code in a way that such classes will be self-contained and reusable entities, like a “black box”, so when using such classes, one doesn’t need to worry about its internals.

As Solidity is object-oriented, it also supports one of the basic OOP features, such as inheritance. In general OOP, inheritance is understood as a way to create a custom class on top of another base class, extending base class functionality.

In Solidity inheritance allows developers to create a contract built on an existing contract.

Here is an extract from the documentation, which demonstrates inheritance in Solidity:

contract Owned {
constructor() { owner = payable(msg.sender); }
address payable owner;
}
// Use `is` to derive from another contract. Derived
// contracts can access all non-private members including
// internal functions and state variables. These cannot be
// accessed externally via `this`, though.
contract Destructible is Owned {
// The keyword `virtual` means that the function can change
// its behaviour in derived classes ("overriding").
function destroy() virtual public {
if (msg.sender == owner) selfdestruct(owner);
}
}

As many other modern high-level languages, programs (or contracts) written on Solidity runs on a virtual machine, as opposed to languages designed to be compiled in binary code to be executed directly by a CPU.

As Java programs run on JVM, Python programs run on PVM, so does Solidity programs run on EVM, which stands for Ethereum Virtual Machine, which is the runtime environment for transaction execution in Ethereum. It includes everything you would expect for a typical virtual machine: stack, memory, program counter, and the persistent storage for all accounts, including contract code.

Solidity is a statically typed language, meaning that all variable types must be explicitly defined during declaration. That means, that there are no any “general” variable types, such as JavaScript “var” or modern C++ “auto” type.

Solidity supports three main categories of types: value types, reference types, and mapping types. Each category includes many different types, i.e., value types are integers, booleans, address type, fixed-point numbers, contract types, and more.

The concept of “undefined” or “null” values does not exist in Solidity, but newly declared variables always have a default value dependent on its type.

Libraries are like contracts but are mainly intended for reuse. A Library contains functions which other contracts can call. Solidity imposes certain restrictions on use of a Library. Following are the key characteristics of a Solidity Library:

  • Library functions can be called directly if they do not modify the state. That means pure or view functions only can be called from outside the library.
  • Library can’t be destroyed as it is assumed to be stateless.
  • A Library cannot have state variables.
  • A Library cannot inherit any element.
  • A Library cannot be inherited.

Despite having libraries, basic tooling functions and variables are just exposed as globals, rather than being stored grouped in some sort of a standard library.

This includes properties that give certain information about the blockchain, mathematical functions, decoding and encoding functions, error-handling functions, members of address types, and so on.

What every beginner should know about Solidity (2024)

FAQs

What do I need to know before learning Solidity? ›

Before diving into Solidity, having a foundation level coding knowledge is helpful, which makes the learning process smoother. Knowledge of variables, functions, loops, and conditionals is essential. Experience with Javascript gives you an edge, as it shares a similar basic structure, which makes it easy to pick up.

Is Solidity beginner friendly? ›

Despite its similarity with other programming languages, some might take some time before settling into using Solidity. For the most part, however, most developers who have had previous experience with C++, Python, and JavaScript will find Solidity user-friendly and intuitive to learn.

Is Solidity worth learning in 2024? ›

Solidity. It is worth exploring Solidity, which is currently used for smart contracts. This can help you understand the technology currently shrouded in hype.

Can I learn Solidity without coding experience? ›

Yes, you can learn Solidity directly by studying its documentation, online courses, and practice coding. Having prior programming experience may help, but it's not a strict requirement.

Is Solidity harder than Python? ›

Yes, Solidity is harder than Python. While both Solidity and Python are object-oriented, Solidity is considered more difficult due to its focus on blockchain applications. However, it offers more features for complex contracts compared to Python.

How many hours to learn Solidity? ›

Professionals with experience in programming concepts and coding languages can usually learn Solidity in 1-6 months. If you have no programming experience, it may take longer. Beginners can take advantage of platforms like CryptoZombies or other free online courses to build a foundation for advanced classes.

Can I get a job with only Solidity? ›

If you want to work strictly with solidity and web3 technologies then look for jobs specifically with this title. You'll need expert knowledge of Solidity, EVM, smart contract design patterns, and security best practices.

How much do Solidity coders make? ›

$105,000 is the 25th percentile. Salaries below this are outliers. $135,500 is the 75th percentile.

Is Solidity still in demand? ›

Solidity developers are in high demand, and as a result, their salaries are on the rise.

Do I need to learn Python before Solidity? ›

If Solidity is your primary first language, you'll have a lot of trouble because switching to another language from Solidity takes time. If, on the other hand, your primary language is something like JavaScript/Python, you can easily switch to Solidity. It will be simple for you.

Does Solidity require math? ›

However, before you dive headfirst into the world of Solidity, it's crucial to have a solid understanding of the mathematics that underpin this powerful programming language.

Is Solidity easier than Javascript? ›

For instance, both JS and Solidity are object-oriented and event-driven. So, you'll already be familiar with concepts like classes, inheritance, and events. However, Solidity is a bit stricter in its syntax, and you'll need to learn about blockchain-specific concepts, such as transactions, gas, and contracts.

What language should I learn before Solidity? ›

Combining the above factor about syntax-similarity and the previous ones — especially the one about Javascript being easier to learn, it's simply a no-brainer to learn Javascript before taking on Solidity.

How difficult is Solidity? ›

Some argue that Solidity is relatively easy to learn, while others contend that it is difficult to master. According to BestColleges, Solidity is “user-friendly for those with prior programming experience,” but it can take longer to learn for those without programming experience.

Is Solidity enough to become a blockchain developer? ›

Proficiency in Smart Contracts and Solidity

Smart Contracts, facilitated by Solidity programming language, represent a pinnacle of blockchain development. Developers must master Solidity to code and implement these contracts, streamlining transactions and reducing third-party involvement.

What language to learn before Solidity? ›

Combining the above factor about syntax-similarity and the previous ones — especially the one about Javascript being easier to learn, it's simply a no-brainer to learn Javascript before taking on Solidity.

Can I learn Solidity without knowing JavaScript? ›

Solidity is the perfect next step for Developers with experience in either Python or Javascript, but it's also relatively easy enough to learn (when following a set training program) that even beginners can pick it up with no prior experience.

Is it hard to learn Solidity? ›

Conclusion. Is solidity hard to learn? No. Its clear and concise syntax makes it accessible to developers with experience in other programming languages, but its complexity increases as you start building more complex smart contracts.

Top Articles
What is a bill payment Payee?
Here it is: The real meaning of accountability in the workplace
55Th And Kedzie Elite Staffing
Minooka Channahon Patch
Palm Coast Permits Online
Odawa Hypixel
Couchtuner The Office
<i>1883</i>'s Isabel May Opens Up About the <i>Yellowstone</i> Prequel
Women's Beauty Parlour Near Me
How Far Is Chattanooga From Here
Espn Expert Picks Week 2
Baseball-Reference Com
Premier Boating Center Conroe
Vichatter Gifs
Conduent Connect Feps Login
De Leerling Watch Online
Walthampatch
The most iconic acting lineages in cinema history
Lima Funeral Home Bristol Ri Obituaries
Eka Vore Portal
Skyward Login Jennings County
Fsga Golf
Holiday Gift Bearer In Egypt
Gotcha Rva 2022
Drift Hunters - Play Unblocked Game Online
Breckiehill Shower Cucumber
Renfield Showtimes Near Paragon Theaters - Coral Square
Craftsman Yt3000 Oil Capacity
Darktide Terrifying Barrage
Gideon Nicole Riddley Read Online Free
Ket2 Schedule
Msnl Seeds
Soulstone Survivors Igg
Latest Nigerian Music (Next 2020)
Main Street Station Coshocton Menu
Uc Santa Cruz Events
Dollar Tree's 1,000 store closure tells the perils of poor acquisitions
Myanswers Com Abc Resources
Leena Snoubar Net Worth
Hireright Applicant Center Login
What Is A K 56 Pink Pill?
11526 Lake Ave Cleveland Oh 44102
2132815089
SF bay area cars & trucks "chevrolet 50" - craigslist
Post A Bid Monticello Mn
Valls family wants to build a hotel near Versailles Restaurant
Iman Fashion Clearance
Tyco Forums
Horseneck Beach State Reservation Water Temperature
Coleman Funeral Home Olive Branch Ms Obituaries
Bumgarner Funeral Home Troy Nc Obituaries
Latest Posts
Article information

Author: Arielle Torp

Last Updated:

Views: 6479

Rating: 4 / 5 (61 voted)

Reviews: 92% of readers found this page helpful

Author information

Name: Arielle Torp

Birthday: 1997-09-20

Address: 87313 Erdman Vista, North Dustinborough, WA 37563

Phone: +97216742823598

Job: Central Technology Officer

Hobby: Taekwondo, Macrame, Foreign language learning, Kite flying, Cooking, Skiing, Computer programming

Introduction: My name is Arielle Torp, I am a comfortable, kind, zealous, lovely, jolly, colorful, adventurous person who loves writing and wants to share my knowledge and understanding with you.