Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,420 --> 00:00:00,810
All right.
2
00:00:00,810 --> 00:00:07,440
Now that we have our first smart contract in remix, I think it's time to actually talk about how smart
3
00:00:07,440 --> 00:00:11,420
contracts are working a little bit more under the hood.
4
00:00:11,430 --> 00:00:13,860
So you have the theory side as well.
5
00:00:14,040 --> 00:00:17,170
Now, in general, what is a smart contract?
6
00:00:17,190 --> 00:00:23,910
The term itself was coined by a computer scientist named Nick Szabo already in 1994.
7
00:00:23,910 --> 00:00:27,990
So it's not particularly new what smart contracts are.
8
00:00:28,020 --> 00:00:34,470
They are a piece of code that is running on the blockchain, and the blockchain itself is like a state
9
00:00:34,470 --> 00:00:41,910
machine, so it needs a transaction to change from one state to the other and it can do some logic operations.
10
00:00:41,910 --> 00:00:44,610
So that is basically how that thing works.
11
00:00:44,610 --> 00:00:51,510
And the state change happens through mining and the mining is going to take the transactions to the
12
00:00:51,630 --> 00:00:56,040
transaction pool and then changing the state on the blockchain.
13
00:00:56,250 --> 00:01:03,510
Now the Ethereum blockchain is a Turing complete blockchain, so that means in theory it can solve any
14
00:01:03,510 --> 00:01:05,069
computational problem.
15
00:01:05,069 --> 00:01:11,760
And it's just a theory because it's very limited by the computational power that it has.
16
00:01:12,120 --> 00:01:13,320
You will see it later.
17
00:01:13,890 --> 00:01:17,160
It's calculated in the gas amount.
18
00:01:17,160 --> 00:01:22,800
So if you need a certain amount of gas, which is getting too much, you cannot in practice solve any
19
00:01:22,800 --> 00:01:23,820
computational problem.
20
00:01:23,820 --> 00:01:25,050
But in theory you can.
21
00:01:25,050 --> 00:01:31,500
So in theory you have all the functions and all the logic there to solve anything that needs to be solved.
22
00:01:31,800 --> 00:01:36,150
Now there are a couple of programming languages for
23
00:01:38,190 --> 00:01:43,560
Ethereum virtual machines, and the most popular one is solidity.
24
00:01:43,560 --> 00:01:52,710
But there is also Viper, which came from Vitalik, wanting a new language that is more secure and a
25
00:01:52,710 --> 00:01:55,590
little bit also more for academic purposes.
26
00:01:55,590 --> 00:02:01,350
Then there was a L, which I think looks a little bit like Python, but it's, it's, there is no development
27
00:02:01,350 --> 00:02:02,460
for these languages anymore.
28
00:02:02,460 --> 00:02:08,759
And then there was bamboo and there were a lot of other languages that basically compile the source
29
00:02:08,759 --> 00:02:12,420
code into IBM bytecode and that is what is run on the blockchain.
30
00:02:12,420 --> 00:02:19,200
So the IBM byte code is actually the kind of code that the Ethereum blockchain nodes are executing.
31
00:02:19,200 --> 00:02:28,650
And then there is high level languages, very much like C, C++, what do we have go and so on.
32
00:02:28,650 --> 00:02:36,810
So those languages, you can write them in a specific syntax and you have specific language features
33
00:02:36,810 --> 00:02:41,550
and then they compile down to the actual byte code or assembly code for the EVM.
34
00:02:41,550 --> 00:02:46,170
And this stays constant and the language features change.
35
00:02:46,920 --> 00:02:51,030
Actually, the EVM also doesn't doesn't stay constant because there are hard forks, but more on that
36
00:02:51,030 --> 00:02:51,480
later.
37
00:02:51,690 --> 00:02:53,100
So how about solidity?
38
00:02:53,100 --> 00:02:57,450
I mean, that's by far the most popular language and this course is also building upon it.
39
00:02:57,450 --> 00:03:01,950
We are doing a lot in solidity and we are trying to touch on every kind of topic that solidity has to
40
00:03:01,950 --> 00:03:04,860
offer in the projects that we are doing.
41
00:03:04,920 --> 00:03:12,900
It is very often compared to JavaScript and actually it's compared to a script and it's like.
42
00:03:13,500 --> 00:03:21,310
Every high language code is then compelled to bytecode, and that is very important to understand.
43
00:03:21,330 --> 00:03:27,870
And in the Ethereum network, every node then executes the same code.
44
00:03:27,870 --> 00:03:31,830
So you're going to write your solidity smart contracts in.
45
00:03:32,100 --> 00:03:34,560
So it's going to be compiled to even bytecode.
46
00:03:34,560 --> 00:03:39,990
Then you send the transaction with that byte code to the blockchain and then every node in the network
47
00:03:39,990 --> 00:03:45,750
is going to execute the same code because every node has a copy of the whole chain.
48
00:03:45,750 --> 00:03:52,050
It's very important to understand that it is not like you're going to send your code to the data center
49
00:03:52,050 --> 00:03:54,780
and then there is it's a machine that is going to execute the code.
50
00:03:54,810 --> 00:04:01,410
It is you send the code to the network and then the network itself takes care of distributing your transactions
51
00:04:01,410 --> 00:04:03,540
across all the nodes to the running in the network.
52
00:04:03,540 --> 00:04:06,210
And then those are executing the same code again.
53
00:04:06,960 --> 00:04:12,360
Now, as I said before, there are other languages I will serve them that is similar to Python at least
54
00:04:12,360 --> 00:04:13,410
like Lisp.
55
00:04:13,560 --> 00:04:17,579
This was mute then and now there is Viper and in between they also had bamboo.
56
00:04:17,579 --> 00:04:23,340
But I still recommend staying in solidity because it's really by far the most famous language that is
57
00:04:23,340 --> 00:04:25,920
out there for smart contract development.
58
00:04:25,950 --> 00:04:29,520
Now, how does a solidity smart contract actually look like?
59
00:04:29,520 --> 00:04:36,660
And it's very tiny here, but I want to touch on a couple of features that these the language has that
60
00:04:36,660 --> 00:04:43,410
are probably very familiar to some of you who are coming from a language like Java or like C-sharp or
61
00:04:43,410 --> 00:04:44,490
like C++.
62
00:04:44,790 --> 00:04:51,240
So there is a class like structure and those classes are well the keyword for the classes are contract
63
00:04:51,240 --> 00:04:58,770
and they contain functions and the functions can contain control structures like if else there is loops
64
00:04:58,770 --> 00:05:03,210
for and while loops there's different data types, it's a statically type language.
65
00:05:03,210 --> 00:05:09,630
So you have to give it for every variable that you define, you have to tell it which kind of data type
66
00:05:09,630 --> 00:05:10,290
is that?
67
00:05:10,290 --> 00:05:16,110
There is unsigned integers, integers, booleans array, struct, states, mappings, which a little
68
00:05:16,110 --> 00:05:17,310
bit look like hash maps.
69
00:05:17,310 --> 00:05:22,470
There is a special data type called address that is, I think, not available in any other language
70
00:05:22,470 --> 00:05:23,730
that I've ever seen.
71
00:05:23,730 --> 00:05:26,730
And be careful, there are no floats.
72
00:05:26,730 --> 00:05:35,250
So if you want to have some sort of decimal points, you have to make a large enough integer to take
73
00:05:35,250 --> 00:05:37,770
care of the decimal places.
74
00:05:37,770 --> 00:05:38,970
And more on that also later.
75
00:05:38,970 --> 00:05:42,450
When we do our first coin, there is inheritance.
76
00:05:42,450 --> 00:05:51,090
So you can have contracts, extending other contracts, there is special structures like modifiers that
77
00:05:51,180 --> 00:05:56,130
yeah, a little bit like go to statements in basic and then there is also import.
78
00:05:56,130 --> 00:06:01,560
So you can finally fine grained structure your smart contract files and then just import whatever you
79
00:06:01,560 --> 00:06:01,860
need.
80
00:06:01,890 --> 00:06:03,480
You will also see that later on.
81
00:06:03,840 --> 00:06:13,170
Now as dee dee dee lay out more, more at the beginning, what you saw now is that one what we did in
82
00:06:13,170 --> 00:06:19,680
the previous lectures with an SPD license identifier, that one identifies the license of that file.
83
00:06:19,680 --> 00:06:22,830
It doesn't identify the license of the project that is running under.
84
00:06:22,830 --> 00:06:31,770
So make no mistake, it's not that because the neft is sees 721 token file is a license as MIT that
85
00:06:32,250 --> 00:06:33,860
the NFT is licenses MIT.
86
00:06:33,870 --> 00:06:35,010
It's about the source code.
87
00:06:35,010 --> 00:06:39,840
So this one depicts the license of the source code as far as I know.
88
00:06:40,890 --> 00:06:47,220
Then there is a line, the line is a pre compiler line that tells the pre compiler to select the rights.
89
00:06:47,220 --> 00:06:52,860
So really the compiler for that file or at least it tells it like this file is written for this compiler
90
00:06:52,860 --> 00:06:57,780
version and that is in a similar style semantic versioning.
91
00:06:58,260 --> 00:07:01,770
So in this case it is clearly zero 814.
92
00:07:01,770 --> 00:07:03,840
So it's locked into a specific version.
93
00:07:03,840 --> 00:07:09,930
And if there was a carrot in the front, then it would mean zero 814 or larger, but not more than zero
94
00:07:09,930 --> 00:07:12,720
nine, excluding zero nine.
95
00:07:12,720 --> 00:07:19,230
Or you can also use the the greater sign, smaller sign, greater equal sign and so on.
96
00:07:19,230 --> 00:07:25,830
So you can use those to, to tell the compiler or the, the environment that you're in, the compiler,
97
00:07:26,400 --> 00:07:29,670
what kind of compiler version is that file written for?
98
00:07:29,670 --> 00:07:36,360
And the reason is that you want to lock in specific compiler version because sometimes the compilers
99
00:07:36,360 --> 00:07:44,360
change and they have a different meaning for the same for the same language features.
100
00:07:44,370 --> 00:07:45,870
Now let me give you an example.
101
00:07:45,870 --> 00:07:49,920
Unsigned integers and integers in previous versions.
102
00:07:49,920 --> 00:07:52,080
We're rolling over and we'll show you this later.
103
00:07:52,080 --> 00:07:59,940
So if you hit zero and then you decrement an unsigned integer, you suddenly hit max int and this was
104
00:07:59,940 --> 00:08:04,500
changed in I think it is 086 or free or something.
105
00:08:04,500 --> 00:08:10,500
So be careful that you lock in a specific compiler version that you're currently working on and then
106
00:08:10,500 --> 00:08:12,840
make sure if you upgrading to a new compiler version that.
107
00:08:13,370 --> 00:08:15,500
All of your files are still compatible.
108
00:08:15,530 --> 00:08:17,870
This is where unit tests come in which we are also writing.
109
00:08:18,440 --> 00:08:20,740
Now then comes a contract.
110
00:08:20,750 --> 00:08:23,760
This is what I told you before with the classes.
111
00:08:23,780 --> 00:08:31,820
The contract is depicted with a contract keyword and then comes in captured style.
112
00:08:32,000 --> 00:08:33,110
Well, you don't have to.
113
00:08:33,110 --> 00:08:38,929
But the official naming convention of solidity, which you can also find in the city docs, is here
114
00:08:38,929 --> 00:08:44,810
is a cap word style, meaning the first letter is capitalized and then every other word is also capitalized.
115
00:08:44,810 --> 00:08:48,380
So my name is capitalized and the contract is capitalized.
116
00:08:48,380 --> 00:08:51,080
And then if there would be other words, then you would also capitalize them.
117
00:08:51,560 --> 00:08:52,610
And it's the first letter.
118
00:08:52,700 --> 00:08:58,400
Then there is curly brackets, and then inside the curly brackets are this one is a storage variable
119
00:08:58,400 --> 00:09:04,460
which you are talking about later on is basically the the variable that stays across several transactions.
120
00:09:04,460 --> 00:09:06,400
So you can store some value in there.
121
00:09:06,400 --> 00:09:11,960
There is going to be events and modifiers and functions and constructors and all of the other things
122
00:09:11,960 --> 00:09:15,020
that we want to do with solidity are in there.
123
00:09:17,060 --> 00:09:20,930
Now for the deployment we sent off a transaction.
124
00:09:20,930 --> 00:09:27,590
And what when you had a look when you opened the transaction field in remix, then you probably saw
125
00:09:27,590 --> 00:09:31,400
that there was a data field or a value field that was populated.
126
00:09:31,400 --> 00:09:34,520
It's called Input Field in Remix, but it's actually for the transaction.
127
00:09:34,520 --> 00:09:40,010
It's a data field and this data field has the compiled bytecode.
128
00:09:40,010 --> 00:09:46,910
And that one, if it's not sent to any specific address, if the two field is empty, then it will the
129
00:09:46,910 --> 00:09:49,010
EVM will know this is bytecode.
130
00:09:49,010 --> 00:09:53,540
I have to deploy it to the blockchain and then it will create a new address which is a deterministic
131
00:09:53,540 --> 00:09:54,200
operation.
132
00:09:54,200 --> 00:09:59,840
We create a new address for this smart contract, and then it will deploy the smart contract bytecode
133
00:09:59,840 --> 00:10:04,280
that is sent in the data field, in the blocks, in the blockchain.
134
00:10:04,290 --> 00:10:05,270
That's how it is.
135
00:10:06,230 --> 00:10:10,400
And this is what we are going to do now in a couple of next lectures over and over again.
136
00:10:10,400 --> 00:10:12,800
So you understand exactly how this works.
137
00:10:12,800 --> 00:10:15,740
But this this is the basic so this is the very basic.
138
00:10:15,740 --> 00:10:22,220
If you understand that, then you understand already 80% of how smart contracts are deployed, how the
139
00:10:22,220 --> 00:10:23,570
interaction works, and so on.
140
00:10:24,410 --> 00:10:29,840
Now the key takeaways are the smart contracts are running on the blockchain and they are deployed as
141
00:10:29,840 --> 00:10:36,140
EVM bytecode and blockchain itself or the EVM is a Turing complete system.
142
00:10:36,590 --> 00:10:44,450
The structure for a smart contract, if you had any prior coding experience, should look fairly familiar.
143
00:10:44,450 --> 00:10:50,540
Even if you come from only JavaScript or only PHP, it should still look very familiar.
144
00:10:50,540 --> 00:10:51,050
So there is.
145
00:10:51,050 --> 00:10:59,480
There shouldn't be much of a new thing other than the addresses and the special edge cases like no floating
146
00:10:59,480 --> 00:11:00,080
points.
147
00:11:00,620 --> 00:11:06,950
The deployment is done with transactions and this is going to change the state of what is basically
148
00:11:06,950 --> 00:11:08,930
a state machine, the blockchain.
149
00:11:09,020 --> 00:11:09,560
All right.
150
00:11:09,650 --> 00:11:11,570
I will see you in the next lecture.
15856
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.