text
stringlengths 61
434
|
---|
what's known as a 51% attack. And it's happened on blockchains like Ethereum classic, which is not Aetherium. This is why the bigger a blockchain is, the more decentralized and the more secure it becomes. So after you watch this video, and you become a blockchain engineering expert, I definitely recommend you run a node as |
well, because you are going to increase the security of the network as a whole by running a node. So proof of work is fantastic because it allows us to very easily protect against the Sybil attacks and keep our blockchain is decentralized and secure. However, it has some drawbacks as well. Proof of Work |
costs a lot of electricity, because every single node is running as fast as they can to win this race to get the rewards. This leads to obviously an environmental impact. Now since proof of work and Nakamoto consensus, a lot of other protocols have taken this idea and gone in a different |
direction with a different civil resistance protocol, a lot of them with the intention to be a lot more environmentally friendly. And the most popular one right now is proof of stake. There are some chains that are already using this proof of stake protocol, and that are live and thriving. Some of them are like avalanche, LaLana, Polygon, polka dot and Terra and |
additionally Aetherium is decided to upgrade to eath. Two, which will have this proof of stake algorithm as well, it will also have some other features, which we'll talk about in a bit. Now as a quick aside, all the tools that we're going to learn here are still going to work in eath. Two, so depending on when |
you watch this, everything here is still valid. So let's talk about proof of stake. Now, again, this is a different civil resistance mechanism. Instead of solving this difficult problem, proof of stake nodes put up some collateral that they're going to behave honestly, aka, they stake in the example of Aetherium. two |
nodes put up some Aetherium as a stake that they're going to behave honestly in the network, if they misbehave to the network, they are going to be slashed or remove some of their steak. Obviously, this is a very good civil resistance mechanism. Because if you try to create a whole bunch of anonymous |
accounts, then each one of those accounts, you have to put up some stake. And if you misbehave, you're going to run the risk of losing all the money that you put up as collateral. In this system, miners are actually called validators because they're no longer binding anything, they're actually just validating other nodes. Now, unlike proof of |
work, which every node is racing to be the first one to find the block, and proof of stake nodes are actually randomly chosen to propose the new block and then the rest of the validators will validate if that node has proposed the block. Honestly, as we saw with our cryptography lesson, it's usually very easy |
for other nodes to verify if a proposal or a transaction is honest. Now randomness is a really important topic when we're talking about blockchains. Because keep in mind, these blockchains are deterministic systems. They're walled gardens from the rest of the world. And as you know, a deterministic |
system by definition can't have random numbers. So how do we choose the random validators in the system? While it changes from blockchain to blockchain, and actually choosing the node will change blockchain to blockchain, but eath two, they're using what's called Rand doubt, at least for the original |
implementation. This is a decentralized autonomous organization that collectively chooses the random number and collectively chooses which node is going to run. Next, we aren't going to dive too deep into this because there's a good chance that this might change in the future. But we will go into randomness solutions and blockchain later on in this |
course. Now, proof of stake obviously has some pros and cons as well, pros are that again, it is a great civil resistance mechanism. And a great way to figure out who the author of a block should be. The other pros are that it's way less computationally expensive to figure out the new block, because instead of every single node on the network trying to do |
this, only one node needs to do this. And then the rest of the nodes just need to validate it. The cons are that it's usually considered a slightly less decentralized network, due to the upfront staking costs it cost to participate. Now, this gets into a little bit of a philosophical battle on how |
decentralized is decentralized enough. And I think that's up to the community to decide. And as we progress, I think we'll learn more and more about how decentralized is decentralized enough. The general consensus amongst blockchain engineers, though, is that proof of stake is very, very decentralized and very secure. This massive environmental impact improvement |
is one of the two main reasons why eath is shifting to eath. Two, it reduces the environmental impact by up to 99%. Now, these are the main pieces of proof of work and proof of stake. But I did want to talk about another concept that's really important in these ecosystems. And that is |
scalability. When we were talking about gas prices, we were saying that the gas prices can get really high if a lot of people want to send a transaction, because a block only has so much black space, and the nodes can only add so many notes. So when a lot of people want to use a blockchain, |
the gas price skyrockets. This is not very scalable, because if we want to add more and more people to these blockchains, it's going to cost more and more to use the blockchains. Because more people are going to want to get into these blocks. This means that there's kind of a ceiling to how many people can |
use the system because of the financial constraints that will get imposed as gas prices keep rising. Aetherium too is not only attacking the environmental impact of proof of work by switching to proof of steak, but they're also implementing this new methodology called sharding. And sharding is a solution to |
the scalability problem, a sharded blockchain really just means that it's going to be a blockchain of blockchains there's a main chain that's going to coordinate everything amongst several chains that hook into this main chain. This means that there's more chains for people to make transactions on |
effectively increasing the amount of block space that there is sharding can greatly increase the number of transactions on a blockchain layer one now there's another term that might be the first time you heard it, a layer one, we're going to talk about layer one and layer twos in terms of scalability really |
quickly as well. A layer one refers to any base layer blockchain implementation Bitcoins, a layer one Aetherium the layer one avalanches, a layer one, these are the base layer blockchain solutions. A layer two is any application |
that is added on top of a layer one added on top of the blockchain. Some examples of layer twos are going to be chain link arbitrage, or optimism. Arbitrage and optimism are very interesting because they are layer twos that also look to solve this scalability issue. Arbitrage and optimism are |
what's known as roll ups and they roll up their transactions into a layer one like Aetherium, we're not going to go too deep into roll ups and how they actually work. But all you really need to know is that a roll up is kind of like a sharded chain, they derive their security from the base layer |
from the layer one like Aetherium. And they bulk send their transactions onto the layer one, they solve some of the scalability issues by being another blockchain that people can make transactions on, still on kind of this base Aetherium layer. Now they're different from side chains. Because side |
chains derive their security from their own protocols, roll ups, derive their security from the base layers. So arbitrage and optimism, for example, is going to be just about as secure as Aetherium. There's some fantastic guys in there that go a little bit deeper into roll ups and I've left a link in the description for you. All right, so we just talked about a lot of |
stuff. So let's do a quick recap before moving on. Aetherium and Bitcoin are currently both proof of work blockchains that follow Nakamoto consensus, however, Aetherium is moving to Aetherium two, which will be a proof of stake sharded blockchain Sybil attacks are prevented due to protocols like proof of work and |
proof of steak 51% attacks grow increasingly harder with the size of blockchain. So you should run a node consensus is the mechanism that allows a blockchain to agree upon what the state of the blockchain is sharding and roll ups are solutions to scalability issues on layer ones. Layer One is any |
based blockchain implementation like Bitcoin or Aetherium. A blockchain scalability problem is that there's not always enough block space for the amount of transactions that want to get in them. This leads to very high gas prices and a Again, gas prices or how much it costs to interact with the blockchain. |
So that's it for the blockchain basics and the blockchain explainers. With just this information, you now can go off into the world and start working with blockchains and interacting with blockchains. With at least some level of knowledge as to what's going on, you should be incredibly proud of yourself for |
just making it this far. Definitely be sure to give yourself a pat on the back and a round of applause. Now that we've gotten a lot of the basics and the fundamentals of the way, let's start jumping into the coding aspect. This is where you're going to learn how to actually build these smart |
contracts, how to build these trust minimized agreements, in these blockchains. And in the smart contract platforms. This next section, this solidity basics, the solidity fundamentals section will give you all the skills to start actually coding solidity and understanding how these smart |
contracts work underneath the hood. So at this point, absolutely, give yourself a high five, maybe say hi, in the GitHub discussions, maybe say hi in the community, on Twitter, on Reddit, etc, and be proud of just making it this far, the journey has really only just begun, but you've already |
learned so much. Let's begin the next section. And let's jump into the code. Now that we're getting to the coding sections, I need to stress to absolutely use the GitHub repository associated with this course. If you come to the GitHub repo, and you scroll |
down, and you click the lesson that we're on right now, we're on lesson two. Welcome to remix, simple storage. If you click on it, it'll give you a ton of timestamps and, and other helpful links associated with this lesson. Additionally, the biggest piece is that all the code will be available right |
underneath the lesson title. This will have all the code that we're going to be working with, as well as some more additional information on how to work with the code. Please, when asking questions and entering in discussions, though, please ask your questions and the full blockchain solidity course |
repository. Thank you. And if we're at the top of the repository, and we scroll down, we have the resources for this course section. Which brings us to the GitHub discussions in which you can ask questions in the GitHub discussion section of this course. Additionally, on Stack Exchange, Aetherium, or at |
Stack Overflow. I'll talk a little bit about how to format questions and ask questions the best way so that you have the highest chance of getting a good answer in a later lesson, I highly recommend you pause and make accounts for Stack Exchange Aetherium, Stack Overflow, and GitHub right now, if you haven't |
already, links to them, of course, can be found in our GitHub repository. Typically, for each coding section, I'll start it off by giving a quick overview of the code of what we're going to be working with and what we're going to be building towards, since everything that we're doing is going to be project based. And that's how we're going to learn. |
For our first one and remix though, we're going to skip over that because there's a lot of stuff to get used to. Now, I highly recommend that as I'm coding this. And as I'm doing all this in remix, you follow along with me and you code along with me. Remember, you can change my speed if I'm coding |
too fast, or if I'm coding too slow. To start, we're going to jump into a tool called remix. If you're unsure how to get there, there's a link to remix in our GitHub repository. This is where we're gonna be writing all of our code. So welcome to the remix IDE, or integrated development environment. This is |
where we're going to learn how to code and interact with our smart contracts. If you want, you can go ahead and accept help out remix. If you've never been here before, it'll give you a quick walkthrough of some of the tools that remix actually has, we're going to skip over them for now. Because I'm gonna explain everything that's going up. Remix is such a powerful |
tool because it has a lot of features that allow us to really see and interact with our smart contracts. Eventually, we're going to move off of remix, actually to a local development environment. However, remix is absolutely fantastic for learning the fundamentals of solidity. And I highly recommend |
everybody start with remix when they're getting started. When you come to the remix IDE, there's a whole lot of different things that are popping out to us. There's a lot of different plugins as well. Since we're going to be working with solidity, which is going to be the language that we're using to develop our smart contracts. We can go ahead and get started by |
clicking the solidity plugin, and a couple of other tools will show up on the side. Even if you don't click the solidity plugin, you'll still be able to code solidity smart contracts, the left hand side is where we're going to start to actually interact with things. The button on the top most of the left is |
our files or explore directories, remix comes boilerplate with some different contracts, some different scripts, some different tests, and different dependencies. We are going to minimize this a little bit. So if you want to go ahead and right click and delete some of these folders other than |
the contracts folders, feel free to do so. Or if you kind of like them there, feel free to leave them as well. We're going to leave our contracts folder and we're going to delete the different files inside of it just so that we can start From a blank slate. Most projects come with something known as a |
readme. Usually it's a readme.md, which usually explains how to actually work with code. But for our purposes, we're going to delete this as well. And you can just follow along with me. Now we have a blank remix Setup, click on the contracts folder and click the |
little page icon to create a new file, a little box will pop up and you can start typing text into it. We're going to type in simple storage dot Sol, dot Sol tells our compilers that this is going to be a solidity file, and that we're going to code |
solidity in this solidity is the primary coding language of smart contracts. There are a few other smart contract languages as well. But solidity by far is the most dominant smart contract coding language out there. And now we have a simple storage dot soul contract on the right that we can actually start coding our |
solidity with. So let's start coding some solidity. Now if you click on this button right below the files button that looks like the solidity logo, you'll see a bunch of stuff pop up in here. These are different parameters for us to actually compile our solidity code so that we can run it. So the first thing that |
you're going to need in any solidity smart contract is going to be the version of solidity that you're going to use. And this should always be at the top of your solidity code, solidity is a constantly changing language, and it constantly updating language. Because it's relatively new compared to other languages, we need to tell our code, hey, this is the version |
that I want you to use, we can add the solidity version by doing pragma. solidity. And then the version that we want to use, if we want to choose a very specific version, we could say zero, point 8.7. The most current version to date is 0.8. |
Point 12. But getting used to different versions of solidity is good practice, and different versions of solidity are considered more stable than others. Zero point 8.7 is one of those versions that is considered more stable. These double slashes here are what's known as a comment, there are |
places where you can type stuff that won't actually get executed in won't get compiled and isn't really considered part of your code. For example, I could write Hello all. I'm Patrick. And if we were going to run this code, this part of my code would get completely ignored. So this double backslash is how we do |
what's called comments. And as we're coding, and as we're building our projects, be sure to use this comments tool to your advantage every time you write a new function, or you learn something that you didn't understand, or you learned something new that you want to remember, put it in a comment in |
your code, you're going to be most effective at taking notes in this course, by making them comments in your code and then saving your code so you can refer back to it later. So leave comments in your code, leave notes in your code. And that will be one of the best ways for you to understand what you're coding when you want to refer back to it later. Now when it |
comes to the versions of solidity, there's actually a few different ways we can actually write it, we can say we want to use only zero point 8.7. And this is how we would write that. But maybe we're okay if we use a more new version of solidity than zero point 8.7 to tell our code that we're okay with a more |
new version, we can put a little caret here. And this is how we tell solidity. Hey, any version of zero point 8.7 And above is okay for this contract. This means zero point 8.8 would work zero point 8.9 0.8 point 10, etc. But if we wanted to use |
just 0.17, we would type in like that if we want to use solidity versions between a specific range, we could do something like this, we can say we want our solidity version greater than or equal to zero point 8.7 But less than zero point 9.0. |
This means that any compiler between zero point 8.7 and zero point 9.0 would work. This means zero point 8.8 would work. Zero point 8.9 would work 0.8 point 10 would work. But zero point 9.0 would not work because it is not strictly less than 0.9 point |
00 point 9.1 would also not work. To keep things simple for us, we're going to use zero point 8.8. And every line of solidity that's completed, every completed section needs to end with one of these semicolons this is how you tell solidity it's the end of the line. Also at the top of your code, you're |
always going to want to put what's called an spdx license identifier. This is optional, but some compilers will flag your warning that you don't have one. This is to make licensing and sharing code a lot easier. We have a link to more about how licenses work in the section of this lesson in our GitHub |
repository to do an spdx license identifier, we just say spdx license identifier, and we're gonna choose MIT, the MIT license is one of the least restrictive licenses out there. So we use the MIT license for most of our code samples once |
you have a version and once you have Is this much written, we can actually go ahead and write to our compiler tab and scroll down and hit Compile, that little turn thing will go. And in a minute, we'll see, this contract is attempted to be compiled. Since we actually don't have a contract, we see no |
contract compiled yet, but we see the compiler automatically switched to zero point 8.8. compiling our code means taking our more human readable code like pragma, solidity and transforming it into computer code, or very specific instructions for the computer to use. We'll go over what a lot of |
this machine level code or this computer level code is doing in a later section. If you're using a Mac, you can also hit command S, and it will run the compiler for you as well. On Windows, it might be Ctrl S, we can actually choose the compiler version that we want to use. However, if we tell in our code to specifically |
use zero, point 8.8, and we hit the compile button, it'll automatically switch to zero point 8.8. However, if we use the carrot thing, we get specifically say, hey, we want 0.8 point 10, we can hit compile, and it will compile |
with 0.8 point 10. Because again, remember, the carrot says we want to use at least zero, point eight, all the way up to the latest version of 0.8. Now let's stay on zero point 8.8. The next thing that we're going to do in our code is define our |
contract. And to get a full screen view, you can go ahead and hit the compiler button to get rid of it there. To start defining our contract, we're gonna go ahead and write the word contract. This tells solidity that the next pieces of code is going to be a contract contract is a key word in solidity, and it tells our compiler that the next section |
of this code is going to define a contract. You can think of a contract similar to a class in any object oriented programming like Java or JavaScript. Let's go ahead and give our contract a name here, we're going to call RS simple storage. And then we |
add this little open and close curly brackets. Everything inside this open and close curly brackets is going to be the contents of this contract. Simple Storage. Now, if we go ahead and hit command S or Ctrl S, we can see this little green checkmark show up. And if you don't, you can always go back to |
the compiler tab, scroll down and hit Compile and see the little green checkmark. That little green checkmark means that our code is compiling successfully. And we don't have any errors, we could hypothetically deploy this contract right now. And it would be a valid contract. So |
congratulations on writing your first contract. Now solidity has multiple different types or primitive data types. And if you go to the solidity documentation, which again, is in our GitHub repository, you can read more and learn more about the different types that are in |
here. The four most basic types are going to be Boolean, you int, int, and an address or bytes, which is a lower level type, which we'll talk about a little bit later. A boolean define some type of true false, a you int is going to be an unsigned integer, which means |
it's going to be a whole number that isn't positive or negative. It's just positive, we have an integer, which is going to be a positive or negative whole number. And then we have an address, which is going to be an address, like what we see in our meta mask here. There are some other types as well that you'll |
learn later on. The reason that we have these types is we use them to define what different variables are. Variables are basically holders for different values. For example, we could create a variable called has favorite number to represent if |
somebody has a favorite number. And we would put this bull keyword before has to renumber say, Okay, we have a variable called has favorite number, and it's of type boolean. So this has favorite number is going to represent a true or a false to |
set its value, we could say has favorite number equals true. Now has favorite number is going to be true. We could also say has favorite number equals false. So this Boolean has faded number is now going to be false. For uns we could say you went favorite |
number equals and then set a number 123. This means that our favorite number is going to be 123 You'll enter is special because we can actually specify how many bits want to allocate to this number bits and bytes are pretty fundamental pieces of |
information for computer science. We're not going to go over it here. However, there's a fantastic video in the GitHub repository that explains it more. Basically, it's how much storage or memory to allocate to this number. How big can it get, if we say a you int eight can have eight bits all the way up |
to you went to 56. If you don't specify how big it is, it automatically defaults to you into 256. Oftentimes, it's better when writing our code to be very explicit. So usually you'll see me just do you int 256 to represent a un 256. We |
could also do an int favorite number equals 123 or an int 256. I'm just Going to go ahead and add this Boolean back here, we're going to change this back to UNT to 36. And let's change our favorite number to five here, we could also do something called strings, string, favorite number in text |
equals five strings represent basically words, and you can represent them by putting them in these quotes, it's going to be some word or phrase, or really, really just kind of any combination of keystrokes in here, our ends can be positive |
or negative. So we could say, negative five or positive five, both are going to be valid, since we can also do address my address equals and grab our address, right from Metamask. And paste it in, you'll notice that we end all of these lines |
of code with the semicolon. We also have bytes objects, or a bytes 32, again, representing how many bytes we want them to be. And this says that we have called favorite bytes, and we're |
just gonna set it equal to cat. So strings are actually really interesting, because strings are secretly just bytes objects, but only for text to a cat is actually a string, but can automatically get converted into one of these bytes object bytes, objects typically look like 0x. And then some random letters and |
numbers that represent the bytes object, but cat can automatically get converted down to bytes. We'll talk about bytes more in coming sessions, you can also do bytes, two bytes, three bytes, five bytes 22, you get the picture for our uns and our into the sixth lowest we can go is eight bits, because eight |
bits is a byte. And we can go up by steps of eight. So we can do 816 32, etc, all the way to 256. For example, down here, we can't do bytes 64. And if we go ahead and try to compile this, we get |
a little red thing here. And if we scroll down, we get a declaration error identifier not found or not unique. Bytes 64 favorite bytes equals cats. And we even got a little red warning sign here in our remix. This is remix telling us there's |
something wrong with this line. So we can switch back to bite 32. Since byte 32 is the maximum size that a bytes can be, you could also do just a bytes object, which means it can have any size, but we typically want to be explicit. And we're going to stick with bytes 32 For now want to learn more about the |
different types and how to use them and all the different features with them, be sure to check out the solidity documentation. For now for our simple storage, let's say we only want to store numbers. So let's go ahead and delete everything except for the favorite number section. Now in solidity, |
if I do this, and I remove the equals five, this favorite number actually does get set to a default value, the default value for solidity is going to be whatever the null value is, which in solidity is case zero. So saying you Intuit six favorite number is going to be the same as saying you 256 |
favorite number equals zero since it gets initialized to zero. So for now, let's not initialize it to anything. So that favorite number will automatically start off as zero. Now, if you get confused, as you're coding along, and you're following along with me, be sure to write comments in your code |
so you know what's going on. So maybe, for example, a great comment here would be this gets initially alized to zero. And then if that's even confusing, you could say, this means that this section is a comment. Now let's go ahead and create a |
function functions or methods are self contained modules that will execute some specific set of instructions for us, when we call it if you're familiar with Java, or Python, or JavaScript or anything like that functions work the exact same way functions get identified by the keyword function, let's create a |
function called store that will change the value of favorite number to some new value. And the number that we're going to change it to is going to be variables that are passed to our store function here. So we're going to allow our store function to take a variable of type un 256. And we'll call it |
underscore favorite number, we'll make this a public function, which we'll get to in a minute. And all we're going to do is we're going to set favorite number equal to whatever variable that we just passed. So now we have this function called store, that it |
takes some parameter that we're going to give it and it sets this favorite number variable equal to whatever number that we give this function. Now to see this actually in action, let's deploy this to an even thicker blockchain than a test net. We're going to actually deploy this to a local network or a |
JavaScript VM. And first before we can even do that, let's just make sure that it's going compiling correctly looks like we have a green checkmark, which is good. And we'll come down to this button here, which is our deploy and run Transactions tab. Our deploy and run Transactions tab has a ton of different |
Subsets and Splits