Basics of Solidity - Compilers

Solidity Blockchain
Transcript

English (Auto-generated)

Okay. So in this video we're gonna talk about, you know, solidity Smart contracts and um we're gonna focus on, you know, compilers and compiler versions. So um when writing smart contracts, smart contracts were written in a programming language called solidity, which is very similar to javascript. Um and uh the first line that you basically specify in in any smart contract that that you're going to ever write is going to be the compiler version. So which which compiler version is going to be used to compile this? Um you know that this solidity file, this this smart contract um so that it can be deployed onto the Blockchain and uh it it basically starts off with um so you start off with the term prag MMA solidity and then you specify the, you know, which version of the compiler of this? This particular smart contract will will need. And here I've I've specified 0.8.4. Now there's a couple of different strategies that you can use when you're, when you're doing this. Um one is specify a specific version and only that version and and and and there's kind of pros and cons to that. So the pros the pros to that is that um when you when you tire smart contract to a specific version of of a solidity compiler um any any bugs that may come up after or were present before in other versions of this compiler, you know, you will not be affected by. So it has been kind of shown in the past that there's, you know, different versions of compilers will sometimes even give different outputs because of, you know, bugs that are found. So what this does the pros the pro to tying it to a specific version is that, you know, you can kind of prevent yourself prevent from that, you know, that risk from being able to, you know, not not being exposed to errors and different upgrades. However, Any contract or any any other contract that would need to compile this contract. So say if there was another contract contract that needed to import this contract and use the functions that were specified in here, that contract would have to have the exact same compiler version of 0.8.4. Right. Um and um and and the thing is once you've, once you've deployed or compiled this contract and then once you've deployed it to the Blockchain, you can't really change anything after that. So it's kind of it's kind of set where it is. So, you know, you have to be careful with that. Um Yeah, there's there's a couple of different options to make your contract kind of able to if if you if you want to be able if you want other contracts to be able to import it without errors and be able to compile it with different compiler versions. Um you can specify a range, so what you could do is um you could say greater than or equal to Um 0.8.0 and then less than or equal to 0.8.5. So then that would basically give you a range. So, so any sorry to be So anything greater than 0.8 or equal to 0.8.0. And anything in between this range, you know, if there was another contract that was that that needed to compile this. Any of these versions of the solidity compiler would be valid. Now, personally, what I like is using something called like the Carrot, which which basically um basically says that anything above this version can be used to compile it, so I I prefer to use this um rather than fixing it to one because, you know, who knows down the road, um especially if you're writing a contract that you're expecting, it's gonna be, you know, you know, functions are going to be called in other contracts. Uh and whatnot. And you know, that this contract is going to be compiled, you know, using other contracts. It's it's it's better to, you know, I would prefer using this character. And basically what this character says is any anything nothing below. Uh This version is going to be able to compile um this contract. So to kind of desperate, it kind of prevents you from having to be exposed to any any bugs prior uh to this. So, if, you know, there was something, you know, in previous versions that may not be compatible with this with with whatever it is that you're doing, um now you you could specify it like this, but but yeah, that that's pretty much it for the compiler, what you need to know about compilers are, again, there are different versions of compilers, so um you know, um if you want to read up on that more you can but basically um this is something that is kind of the first line that you'll see and it kind of pretty much has to be, you know, included in every single contract. Otherwise, you know, your contract basically, it won't compile. Alright, that's it. Thank you very much.
38 Views 0 Likes 0 Comments

Comment
Leave a comment (supports markdown format)