Check out a free preview of the full A Tour of Web 3: Ethereum & Smart Contracts with Solidity course

The "Solidity Language Basics" Lesson is part of the full, A Tour of Web 3: Ethereum & Smart Contracts with Solidity course featured in this preview video. Here's what you'd learn in this lesson:

ThePrimeagen introduces the Solidity language and shares some common code structures like conditions, loops, and type declarations. Contracts are similar to classes. The base type in Solidity is a 256-bit unsigned integer.


Transcript from the "Solidity Language Basics" Lesson

>> I'm gonna go on a brief, quick tour of the language. Like I said, I'm not gonna really go over every one of these things. I just wanna show them to you. So solidity, if you've seen an if statement, you know how if statements work, right? If you've seen a for Loop, just like every for Loop you've ever used.

Contracts effectively are identical to classes. You can hang members off contracts. There are constructors on contracts. You can specify a function with a scope and a return type. All these things should be pretty familiar. Yes you may not be able to type the exact syntax your first try just because you haven't done it enough time for it to be habitual but for now that's that, all right.

So that's the simplicity of the language. Like I said, the language is actually very simple. It only gets into the weeds when you get to the more advanced stuff. So the base type on solidity is a 256 bit number. It's unusual because base types usually aren't numbers, nor are they 256 bits that's actually a really large number.

It's effectively the size of the universe in atoms. Maybe I'm off by about a factor of 10,000. But that's a very large number, right? 10 to the 79, I think is two to the 56. And so you can subdivide these out and do like a u and eight, that's eight bits or one byte or representing 256 distinct values.

You can do a u and 16, 32, 64, 128. It allows some for some basic subdividing in there. Strings suck, so don't do them. That's the general rule of thumb is that unless if you have a bunch of hard coded ones, you're gonna construct some sort of output with.

Working with strings is really painful because the base type is 256 bit number. So you're kind of mashing strings into these number representations. It can lead to a lot of pain. I tend to just avoid strings in the things I've written every single time except for like I said meta information generation by simply just concatenate a bunch of stuff together that are hard coded strings and pulling out data.

Array, there are dynamic and static arrays or fixed arrays. If you specify array on the contract as a member, it is a dynamic array. Right now you're probably thinking, why does that matter? When we get to the final part of this it will make perfect sense for now, except it is beautiful.

If you specify an array inside the function, you specify it as a fixed array. I need an array of size 10, you cannot inline generate an array right now so you just have to do this and then you can add in each number as you'd like. So fixed inside of functions dynamic outside when it's on a member of a contract.

Maps again, different from what you're used to. It's a mapping, not necessarily a map, a map stores keys and values. Mappings do not store keys, and they technically don't even store values. It's kinda confusing. You do a mapping from type to type and the type can even be a complex type.

It doesn't have to be a simple type. And that will be a mapping. It'll do some super special magic underneath the hood, and it will be able to store that. But you cannot for each over keys. You cannot for each over values. You don't even know how many items are inside of your map because it's actually just simply a mathematical function that gets executed.

And we'll go over that in more detail later on, but it will make perfect sense why this is and just for now keep it that way all right. Struct, they're just like C you simply say struct foo or I guess go lang is another example and you can specify a bunch of stuff in there.

You can create a mapping from say you went to foo. You can create a full array, right? So you can use those, you can create a mapping to a mapping that is a UN to a full array. So there is no, you can do all the standard mixes you'd like.

There are also enums. We'll be using one here shortly, so I just didn't even put it in here. And there you go. That is the basic of the language. At this point, you've already seen enough of the solidity language, you pretty much know most of its bits. Some of the concepts get pretty hard if you ever want to learn more about solidity, go to

And it gives you this really nice like, you can learn everything about it. The layout of the memory, how call data works, types, global things, expressions, contracts, inline assembly, it has everything to it. It's very, very nice. I figured you probably didn't want me to read the docs for you.

You can read the friendly manual on your own time,we should probably discuss more of the fun parts and so we are gonna build as we learn that is always my favorite way to learn. It's not just simply reading but to build something fail get better learn why and slowly build over time.

So is there any questions thus far on what I just showed you with just the basic types, the unit type which is of course, 256 bit number, anything like that.?
>> Why does solidity exist? Why couldn't they have just made a library from Python or another Language?
>> My guessing is that as we go on, you'll see a lot of the complications with how they chosen some of their things that they've done.

Solidity seems to fit very, very well with this. I know Solona went with rust. I don't know how much it actually resembles rust itself or what subset they've chosen to implement from rust, but it appears to be much nicer that way. I don't know why they went with their own language.

I don't know why anyone invents their own language in fact, with all the languages we already have, pretty much all the problems you've ever wanted have all ready been solved. But they've chosen this language. It works very well for what they want. And when you break into inline assembly, it works very, very well.

And so I think that they kind of chose this to ease a lot of it. I cannot speak on behalf that I don't know the technical answer, but a lot of the peculiarities of the Ethereum network are built into the language and you'll see why soon because like I said, it's not a map.

There is no map. There's a mapping. It's like a map. It's unique, if you will.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now