From the course: Blockchain: Learning Solidity
Solidity syntax basics
From the course: Blockchain: Learning Solidity
Solidity syntax basics
- [Instructor] So let's get started with our first syntax in Solidity and show you the base layout and syntax of a file. So I'm back in VSCode, and again, if you don't have the extension, please make sure that you do install it so you can have syntax check and all these nice features that comes with this package here. So let's go and start our first file. So what I'm going to do first is create a folder inside of my desktop, and I'm going to call this DAPP, and then I'm going to drag and drop it inside of VSCode. And then I have my folder open right here. So I'm going to create my first file, and this first file is going to be called sample, or we can call this first DAPP if you want, or whatever it is that you want, and the extension for the file is dot SOL, like so. And you'll see this little icon if you're writing this right. So you always start your syntax with importing Solidity. So I'm just going to type a note here, import Solidity, and we're going to go ahead and import with pragma Solidity. And then you need to write the version number. So for this one, what we're going to do is follow what they do in Remix and import in between 8.2 or nine, like so. So 0.90, like so, and then semicolon. So now that we have Solidity import, I'm going to show you how to import files from other programs or packages. So again, we're just going through the syntax. We're not going to create a full program, we're just going through the syntax. So this is the syntax to import from another file. So you can import a file name like so. It's very similar to importing in JavaScript or any of the C-based language. You can import this way, too, by doing import as symbol name from file name. So you can import as the symbol from symbol name a package that's inside file name. That's another way of doing it. And FIY, if you're seeing errors, it's because we're already have imported file name here. And another way of importing could be symbol one, so basically importing multiple classes from a specific package. So let's say we're importing from file name again, and inside of file name, there are multiple classes that you can import. You could just import these classes from this specific package here. So symbol one could be one of the classes that you're importing and you can import it as alias. So you can use this class as alias later on inside of your contract, or you can just import a specific symbol class that you will use later on. So you could use it symbol down here like so. Okay. So far, so good. Now, the first thing that we're going to do now is, what is the syntax of a contract? It's very, very simple. So let's just write a note, your first contract, and this is how the syntax of a contract starts. Contract, and you would call it whatever you want. In this case, I'm going to call it simple contract. Then we open curly braces, and this is where your contract code would go, and we're going to add some contract code in the following videos, but this is basically the syntax, and I'm going to check what's happening here. It's just as expected. Oh, I didn't have my semicolon here, that's why there's a problem here. Okay. And this is a reserved word, so I'm going to call it alies. And it gives me... Yeah, file name is imported multiple times. That I was expecting. Okay, so we can do file name two here, file name three here, just to make sure we don't get little errors like this. So this is basically how it would work. You import first Solidity, then you can import a couple of files here as needed, and then you can start your first contract here. So this is how the syntax starts. Play with the syntax, have fun with it, and then move on to the next video.
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
Solidity syntax basics5m 31s
-
(Locked)
Basic syntax of a contract5m 52s
-
(Locked)
Types in Solidity6m 31s
-
(Locked)
Units and global variables5m 37s
-
(Locked)
Other special variables2m 37s
-
(Locked)
Functions overview3m 40s
-
(Locked)
Operators in Solidity4m 46s
-
(Locked)
Conditionals in Solidity3m 55s
-
-
-
-