WEBVTT

1
00:00:00.180 --> 00:00:01.260
In this lesson,

2
00:00:01.260 --> 00:00:03.480
we will learn about  Blockchain.

3
00:00:03.480 --> 00:00:08.190
Blockchain is a decentralized, distributed ledger technology

4
00:00:08.190 --> 00:00:12.540
that ensures data integrity and transaction transparency

5
00:00:12.540 --> 00:00:17.100
by recording transactions in a series of immutable blocks.

6
00:00:17.100 --> 00:00:20.130
Immutable means that the blocks are unchangeable

7
00:00:20.130 --> 00:00:21.660
after creation.

8
00:00:21.660 --> 00:00:25.770
An Immutable Database refers to a database where data,

9
00:00:25.770 --> 00:00:30.150
once written, is not able to be altered or deleted.

10
00:00:30.150 --> 00:00:33.690
Immutable databases ensure a permanent record

11
00:00:33.690 --> 00:00:36.000
of blockchain transactions.

12
00:00:36.000 --> 00:00:39.840
Let's learn more about blockchain and immutable databases.

13
00:00:39.840 --> 00:00:43.470
Then, we will conduct a blockchain demonstration.

14
00:00:43.470 --> 00:00:45.720
First, we have blockchain.

15
00:00:45.720 --> 00:00:49.530
Blockchain is a technology that can seem complex,

16
00:00:49.530 --> 00:00:52.530
but is essentially a way to securely record

17
00:00:52.530 --> 00:00:55.470
and share information across a network.

18
00:00:55.470 --> 00:00:57.690
It works like a digital ledger,

19
00:00:57.690 --> 00:00:59.400
similar to a record book

20
00:00:59.400 --> 00:01:01.890
where transactions are written down.

21
00:01:01.890 --> 00:01:05.010
However, unlike traditional ledgers,

22
00:01:05.010 --> 00:01:08.070
blockchain is decentralized and distributed,

23
00:01:08.070 --> 00:01:09.690
meaning it is not controlled

24
00:01:09.690 --> 00:01:12.510
by any single person or organization.

25
00:01:12.510 --> 00:01:13.440
Instead,

26
00:01:13.440 --> 00:01:17.490
it is maintained by a network of computers called nodes

27
00:01:17.490 --> 00:01:18.990
all around the world.

28
00:01:18.990 --> 00:01:23.490
Each transaction or piece of data is recorded in a block.

29
00:01:23.490 --> 00:01:25.080
Once the block is full,

30
00:01:25.080 --> 00:01:27.090
it is linked to a previous one,

31
00:01:27.090 --> 00:01:29.400
forming a chain of blocks,

32
00:01:29.400 --> 00:01:31.590
hence the term blockchain.

33
00:01:31.590 --> 00:01:33.540
What makes blockchain special

34
00:01:33.540 --> 00:01:36.090
is its transparency and security.

35
00:01:36.090 --> 00:01:38.490
Once data is recorded in a block,

36
00:01:38.490 --> 00:01:40.530
it's impossible to change,

37
00:01:40.530 --> 00:01:44.700
providing a tamper-proof record of every transaction.

38
00:01:44.700 --> 00:01:48.510
This feature makes blockchain ideal for situations

39
00:01:48.510 --> 00:01:51.390
where it is crucial to have a transparent

40
00:01:51.390 --> 00:01:53.010
and trustworthy record,

41
00:01:53.010 --> 00:01:56.640
such as financial transactions, voting systems,

42
00:01:56.640 --> 00:01:59.160
or tracking goods in a supply chain.

43
00:01:59.160 --> 00:02:01.020
Every participant in the network

44
00:02:01.020 --> 00:02:03.450
has a copy of the blockchain,

45
00:02:03.450 --> 00:02:06.120
so if someone tries to tamper with the data,

46
00:02:06.120 --> 00:02:09.360
the rest of the network will see that something is wrong,

47
00:02:09.360 --> 00:02:12.660
making blockchain highly resistant to fraud.

48
00:02:12.660 --> 00:02:15.660
Second, we have immutable databases,

49
00:02:15.660 --> 00:02:18.750
and immutable database is a type of database

50
00:02:18.750 --> 00:02:23.700
where the data, once written, cannot be altered or deleted.

51
00:02:23.700 --> 00:02:28.020
A key feature of immutability means that every piece of data

52
00:02:28.020 --> 00:02:32.160
remains exactly as it was when it was first recorded.

53
00:02:32.160 --> 00:02:34.380
Unlike traditional databases

54
00:02:34.380 --> 00:02:36.900
where data can be changed or removed,

55
00:02:36.900 --> 00:02:41.070
immutable databases ensure that a permanent record is kept.

56
00:02:41.070 --> 00:02:43.740
This makes them particularly valuable

57
00:02:43.740 --> 00:02:45.840
in scenarios where it is important

58
00:02:45.840 --> 00:02:50.430
to maintain a historical record without the risk of changes,

59
00:02:50.430 --> 00:02:54.600
such as in compliance, auditing, or legal contexts.

60
00:02:54.600 --> 00:02:57.600
While blockchain is a specific application

61
00:02:57.600 --> 00:02:59.520
of an immutable database,

62
00:02:59.520 --> 00:03:01.920
the two concepts are not the same.

63
00:03:01.920 --> 00:03:06.330
Blockchain uses immutability as one of its core features,

64
00:03:06.330 --> 00:03:10.770
but it also relies on decentralization and cryptography

65
00:03:10.770 --> 00:03:13.590
to provide a secure, transparent way

66
00:03:13.590 --> 00:03:16.260
of managing data across a network.

67
00:03:16.260 --> 00:03:19.110
Immutable databases on their own

68
00:03:19.110 --> 00:03:22.800
do not need to be distributed or decentralized.

69
00:03:22.800 --> 00:03:26.010
They simply ensure that once data is written,

70
00:03:26.010 --> 00:03:27.840
it cannot be modified,

71
00:03:27.840 --> 00:03:31.530
providing a reliable way to preserve information

72
00:03:31.530 --> 00:03:34.110
exactly as it was recorded.

73
00:03:34.110 --> 00:03:38.700
Now, let's demonstrate blockchain on a Kali Linux machine

74
00:03:38.700 --> 00:03:41.970
using an application called Ganache.

75
00:03:41.970 --> 00:03:46.200
Ganache is a personal blockchain for Ethereum development

76
00:03:46.200 --> 00:03:50.280
that we can use to deploy contracts, develop applications,

77
00:03:50.280 --> 00:03:51.870
and run tests.

78
00:03:51.870 --> 00:03:55.890
So while our instance of Ganache will not be made public,

79
00:03:55.890 --> 00:03:58.920
the concepts we can demonstrate would be the same

80
00:03:58.920 --> 00:04:01.980
if it were a publicly distributed blockchain.

81
00:04:01.980 --> 00:04:05.670
For our demonstration, I've installed Node.js,

82
00:04:05.670 --> 00:04:08.880
the Node package manager, and Ganache.

83
00:04:08.880 --> 00:04:10.110
Ganache is running

84
00:04:10.110 --> 00:04:12.120
and we can see that it has provided us

85
00:04:12.120 --> 00:04:13.980
with some starting information.

86
00:04:13.980 --> 00:04:16.290
Here's a breakdown of what we're seeing.

87
00:04:16.290 --> 00:04:20.820
The Available Account section lists 10 Ethereum accounts

88
00:04:20.820 --> 00:04:22.440
that have been created.

89
00:04:22.440 --> 00:04:26.160
Each account has a unique Ethereum address

90
00:04:26.160 --> 00:04:30.870
and an initial balance of 1,000 Ether.

91
00:04:30.870 --> 00:04:33.960
These accounts are used for sending transactions,

92
00:04:33.960 --> 00:04:36.090
deploying smart contracts,

93
00:04:36.090 --> 00:04:38.970
and interacting with the blockchain.

94
00:04:38.970 --> 00:04:43.970
Next, each Ethereum account has a corresponding private key

95
00:04:44.100 --> 00:04:46.770
shown here in hexadecimal format.

96
00:04:46.770 --> 00:04:50.520
These private keys are critical for signing transactions

97
00:04:50.520 --> 00:04:53.250
and proving ownership of accounts.

98
00:04:53.250 --> 00:04:55.170
They're exposed here in Ganache

99
00:04:55.170 --> 00:04:57.660
because it's a development environment,

100
00:04:57.660 --> 00:04:59.490
but in a live blockchain,

101
00:04:59.490 --> 00:05:01.830
private keys must be kept secret

102
00:05:01.830 --> 00:05:05.040
to protect the security of the funds.

103
00:05:05.040 --> 00:05:08.250
Next, the hierarchial deterministic

104
00:05:08.250 --> 00:05:11.580
or HD wallet section shows the mnemonic

105
00:05:11.580 --> 00:05:15.930
or seed phrase used to generate the accounts.

106
00:05:15.930 --> 00:05:18.060
The mnemonic is a set of words

107
00:05:18.060 --> 00:05:21.360
that can recreate the private keys and accounts,

108
00:05:21.360 --> 00:05:25.170
so it must be kept safe in production scenarios.

109
00:05:25.170 --> 00:05:28.560
Next, the default gas prices listed.

110
00:05:28.560 --> 00:05:32.700
Gas prices determine the cost of executing transactions

111
00:05:32.700 --> 00:05:35.850
or smart contracts on the blockchain.

112
00:05:35.850 --> 00:05:38.940
The block gas limit is the maximum amount

113
00:05:38.940 --> 00:05:41.580
of computational work or gas

114
00:05:41.580 --> 00:05:45.780
that can be included in a single block on the blockchain.

115
00:05:45.780 --> 00:05:48.570
It ensures that blocks do not get too large

116
00:05:48.570 --> 00:05:50.940
or expensive to process.

117
00:05:50.940 --> 00:05:55.380
The call gas limit represents the maximum amount of gas

118
00:05:55.380 --> 00:05:59.100
allowed for a single function call or transaction.

119
00:05:59.100 --> 00:06:02.160
This ensures that computational operations

120
00:06:02.160 --> 00:06:05.070
do not exceed reasonable limits.

121
00:06:05.070 --> 00:06:08.220
Finally, we have chain information.

122
00:06:08.220 --> 00:06:10.170
This section provides details

123
00:06:10.170 --> 00:06:12.720
about the blockchain configuration,

124
00:06:12.720 --> 00:06:15.270
including the hard fork being used,

125
00:06:15.270 --> 00:06:16.800
which is Shanghai,

126
00:06:16.800 --> 00:06:20.700
and the chain ID, 1337.

127
00:06:20.700 --> 00:06:25.470
The hard fork refers to a specific set of protocol changes

128
00:06:25.470 --> 00:06:28.740
and updates that are applied to the blockchain.

129
00:06:28.740 --> 00:06:33.090
The chain ID uniquely identifies the blockchain network,

130
00:06:33.090 --> 00:06:37.290
which helps prevent transactions intended for one network

131
00:06:37.290 --> 00:06:40.860
from being accidentally executed on another.

132
00:06:40.860 --> 00:06:45.860
Okay, now we need some way to interact with the blockchain,

133
00:06:46.050 --> 00:06:51.050
so we will install Web3.js with the following command,

134
00:06:51.870 --> 00:06:56.870
sudo npm install web3@1.6.0.

135
00:07:04.200 --> 00:07:05.670
While that's installing,

136
00:07:05.670 --> 00:07:08.583
let me show you the script that I've created.

137
00:07:11.640 --> 00:07:15.933
Cat blockchain_demo.js.

138
00:07:17.250 --> 00:07:21.960
This JavaScript uses the Web3.js library

139
00:07:21.960 --> 00:07:24.930
to interact with a local blockchain.

140
00:07:24.930 --> 00:07:28.320
It demonstrates basic blockchain operations,

141
00:07:28.320 --> 00:07:32.220
such as retreating accounts, checking balances,

142
00:07:32.220 --> 00:07:33.990
sending a transaction,

143
00:07:33.990 --> 00:07:36.840
and displaying transaction details.

144
00:07:36.840 --> 00:07:40.707
The local blockchain is hosted at 127.0.0.1,

145
00:07:42.780 --> 00:07:44.370
or this machine,

146
00:07:44.370 --> 00:07:47.130
on port 8545.

147
00:07:47.130 --> 00:07:51.510
First, this script will retrieve a list of accounts.

148
00:07:51.510 --> 00:07:54.270
These accounts are used to send transactions

149
00:07:54.270 --> 00:07:56.910
and interact with the blockchain.

150
00:07:56.910 --> 00:07:59.820
Next, the script will send the transaction

151
00:07:59.820 --> 00:08:02.790
from the first account to the second account,

152
00:08:02.790 --> 00:08:05.070
transferring one Ether.

153
00:08:05.070 --> 00:08:09.450
The gas limit of this transaction is set to 21,000,

154
00:08:09.450 --> 00:08:11.280
which is the standard amount of gas

155
00:08:11.280 --> 00:08:14.490
required for a simple Ether transfer.

156
00:08:14.490 --> 00:08:17.160
After the transaction is successful,

157
00:08:17.160 --> 00:08:20.220
the script prints out the transaction hash,

158
00:08:20.220 --> 00:08:24.480
which uniquely identifies the transaction on the blockchain.

159
00:08:24.480 --> 00:08:26.790
After sending the transaction,

160
00:08:26.790 --> 00:08:30.720
the script checks the updated balance of the first account

161
00:08:30.720 --> 00:08:33.840
to show the impact of the transaction.

162
00:08:33.840 --> 00:08:38.160
Finally, the details of the transaction will be displayed.

163
00:08:38.160 --> 00:08:42.570
Now, let's run this script using the following command,

164
00:08:42.570 --> 00:08:47.570
sudo node blockchain_demo.js.

165
00:08:55.230 --> 00:08:56.130
Okay.

166
00:08:56.130 --> 00:08:58.950
Here's a breakdown of what we're seeing.

167
00:08:58.950 --> 00:09:01.200
The Available Accounts section

168
00:09:01.200 --> 00:09:04.380
lists our 10 Ethereum accounts.

169
00:09:04.380 --> 00:09:07.230
Each account has a unique address

170
00:09:07.230 --> 00:09:10.890
which serves as its identifier on the blockchain.

171
00:09:10.890 --> 00:09:15.600
Next, we see the initial balance of the first account,

172
00:09:15.600 --> 00:09:18.330
which is 1,000 Ether (ETH).

173
00:09:18.330 --> 00:09:23.040
Next, we see a transaction successful hash.

174
00:09:23.040 --> 00:09:24.090
This indicates

175
00:09:24.090 --> 00:09:27.510
that a transaction was successfully completed.

176
00:09:27.510 --> 00:09:31.500
The transaction hash uniquely identifies this transaction

177
00:09:31.500 --> 00:09:34.590
on the blockchain and serves as a reference

178
00:09:34.590 --> 00:09:37.140
for querying the transaction details

179
00:09:37.140 --> 00:09:40.530
and proves the transaction was recorded.

180
00:09:40.530 --> 00:09:44.910
Next, we see a new balance of the first account,

181
00:09:44.910 --> 00:09:49.800
which is updated to approximately 999 ETH

182
00:09:49.800 --> 00:09:52.440
due to 1 ETH being sent

183
00:09:52.440 --> 00:09:56.700
and the gas fee charged for processing the transaction.

184
00:09:56.700 --> 00:10:00.090
Last, we see the Transaction Details.

185
00:10:00.090 --> 00:10:02.100
We won't review them all,

186
00:10:02.100 --> 00:10:06.120
but there are a few that are relevant to our discussion.

187
00:10:06.120 --> 00:10:09.990
The Block Hash and Block Number indicate the block

188
00:10:09.990 --> 00:10:12.480
where the transaction was recorded.

189
00:10:12.480 --> 00:10:15.600
Next, the transaction index.

190
00:10:15.600 --> 00:10:19.410
This is the position of the transaction within the block.

191
00:10:19.410 --> 00:10:21.690
From and To:

192
00:10:21.690 --> 00:10:25.290
These are the sender and receiver addresses.

193
00:10:25.290 --> 00:10:27.540
Next, we have a Value:

194
00:10:27.540 --> 00:10:30.930
This is the amount of Ether that has been transferred

195
00:10:30.930 --> 00:10:33.240
specified in wei.

196
00:10:33.240 --> 00:10:37.020
Then we see the Gas Price and the Gas.

197
00:10:37.020 --> 00:10:40.140
This indicates the computational cost

198
00:10:40.140 --> 00:10:45.140
for processing the transaction and the fee per unit of gas.

199
00:10:45.480 --> 00:10:48.570
Finally, v, r, and s:

200
00:10:48.570 --> 00:10:50.580
These values are used

201
00:10:50.580 --> 00:10:53.610
in the digital signature of the transaction,

202
00:10:53.610 --> 00:10:56.850
proving it was signed by the sender.

203
00:10:56.850 --> 00:11:01.290
But all we are seeing here is a single transaction.

204
00:11:01.290 --> 00:11:03.390
Let's take a look at the ledger.

205
00:11:03.390 --> 00:11:05.850
All transactions can be summarized

206
00:11:05.850 --> 00:11:09.480
by querying the blockchain to observe transactions.

207
00:11:09.480 --> 00:11:11.940
So I've created a separate script

208
00:11:11.940 --> 00:11:13.710
that will query the blockchain

209
00:11:13.710 --> 00:11:16.200
and provide us with a summary of transactions

210
00:11:16.200 --> 00:11:17.400
that have occurred.

211
00:11:17.400 --> 00:11:19.200
Before we run this script,

212
00:11:19.200 --> 00:11:21.570
let's do one more transaction,

213
00:11:21.570 --> 00:11:24.960
that way we have a little more data to look at.

214
00:11:24.960 --> 00:11:28.050
We'll do this by rerunning the command

215
00:11:28.050 --> 00:11:32.743
sudo node blockchain_demo.js.

216
00:11:34.500 --> 00:11:38.070
Next, let's take a look at our ledger.

217
00:11:38.070 --> 00:11:43.070
We'll do this by running the sudo node ledger.js command.

218
00:11:48.270 --> 00:11:50.610
Okay, here's what we're seeing.

219
00:11:50.610 --> 00:11:54.330
We can see the details about the most recent blocks

220
00:11:54.330 --> 00:11:55.680
of our blockchain,

221
00:11:55.680 --> 00:11:59.610
along with the transactions contained within these blocks.

222
00:11:59.610 --> 00:12:02.190
Here we're viewing our ledger.

223
00:12:02.190 --> 00:12:05.280
We can see the latest block number,

224
00:12:05.280 --> 00:12:07.950
which indicates that block two

225
00:12:07.950 --> 00:12:11.190
is the most recent block in the blockchain.

226
00:12:11.190 --> 00:12:14.880
The number represents the sequential order of blocks,

227
00:12:14.880 --> 00:12:18.363
starting from the genesis block, block 0.

228
00:12:19.200 --> 00:12:23.250
Then we can see the block 2 details,

229
00:12:23.250 --> 00:12:25.500
including the block number,

230
00:12:25.500 --> 00:12:28.050
which is the block's position in the chain,

231
00:12:28.050 --> 00:12:31.140
and the hash for block 2.

232
00:12:31.140 --> 00:12:33.750
Each block in the blockchain is hashed.

233
00:12:33.750 --> 00:12:37.020
A hash is a cryptographic representation

234
00:12:37.020 --> 00:12:38.700
of the block's data,

235
00:12:38.700 --> 00:12:40.920
essentially a digital fingerprint

236
00:12:40.920 --> 00:12:43.680
that uniquely identifies the block.

237
00:12:43.680 --> 00:12:47.220
What makes blockchain truly secure and immutable

238
00:12:47.220 --> 00:12:50.190
is that each block also includes the hash

239
00:12:50.190 --> 00:12:52.860
of the previous block in the chain.

240
00:12:52.860 --> 00:12:55.500
This creates a link between blocks,

241
00:12:55.500 --> 00:12:59.010
forming a continuous tamper-proof chain.

242
00:12:59.010 --> 00:13:03.120
If any information in a block is altered, even slightly,

243
00:13:03.120 --> 00:13:05.190
the block's hash will change.

244
00:13:05.190 --> 00:13:08.970
Since each block contains the previous block's hash,

245
00:13:08.970 --> 00:13:11.160
any change would break the link,

246
00:13:11.160 --> 00:13:14.910
alerting the network that tampering has occurred.

247
00:13:14.910 --> 00:13:17.160
This interconnected structure

248
00:13:17.160 --> 00:13:19.950
means that to alter any single block,

249
00:13:19.950 --> 00:13:22.080
a malicious actor would need to change

250
00:13:22.080 --> 00:13:23.970
all subsequent blocks,

251
00:13:23.970 --> 00:13:26.130
recalculate all hashes,

252
00:13:26.130 --> 00:13:28.320
and gain control of the majority

253
00:13:28.320 --> 00:13:30.510
of the network's computing power,

254
00:13:30.510 --> 00:13:33.390
which is practically impossible.

255
00:13:33.390 --> 00:13:36.570
This reliance on previous block hashes

256
00:13:36.570 --> 00:13:39.060
is what makes blockchain immutable

257
00:13:39.060 --> 00:13:41.640
as it safeguards the entire chain

258
00:13:41.640 --> 00:13:44.160
from unauthorized modifications,

259
00:13:44.160 --> 00:13:46.890
ensuring that once data is recorded,

260
00:13:46.890 --> 00:13:49.590
it remains permanent and secure.

261
00:13:49.590 --> 00:13:53.280
Finally, we have a transaction hash.

262
00:13:53.280 --> 00:13:55.350
This identifies the transaction

263
00:13:55.350 --> 00:13:58.170
and some details about the transaction,

264
00:13:58.170 --> 00:14:02.220
including the transaction parties, the amount transferred,

265
00:14:02.220 --> 00:14:04.260
and the gas used.

266
00:14:04.260 --> 00:14:06.600
As we continue to look down the output,

267
00:14:06.600 --> 00:14:10.320
we can see our first transaction in block number one,

268
00:14:10.320 --> 00:14:13.020
and we can see block 0.

269
00:14:13.020 --> 00:14:16.320
Block 0 is known as the genesis block,

270
00:14:16.320 --> 00:14:19.200
it's the first block in the blockchain.

271
00:14:19.200 --> 00:14:22.530
The genesis block contains no transactions,

272
00:14:22.530 --> 00:14:26.370
which is typical since it primarily serves as the foundation

273
00:14:26.370 --> 00:14:28.530
for all subsequent blocks.

274
00:14:28.530 --> 00:14:31.470
This demonstration showed us the concept

275
00:14:31.470 --> 00:14:36.000
of blockchain's immutability and distributed ledger.

276
00:14:36.000 --> 00:14:39.000
It showed how blocks are sequentially late,

277
00:14:39.000 --> 00:14:41.880
each containing unique transactions.

278
00:14:41.880 --> 00:14:45.450
Additionally, based on each block containing data

279
00:14:45.450 --> 00:14:47.340
from the previous blocks,

280
00:14:47.340 --> 00:14:51.390
we showed that data recorded in a block is immutable,

281
00:14:51.390 --> 00:14:55.110
maintaining a secure and transparent record

282
00:14:55.110 --> 00:14:57.270
of all transactions.

283
00:14:57.270 --> 00:14:59.310
So remember,

284
00:14:59.310 --> 00:15:02.820
blockchain is a decentralized technology

285
00:15:02.820 --> 00:15:06.720
that records data in a secure and transparent way

286
00:15:06.720 --> 00:15:09.240
across a network of computers.

287
00:15:09.240 --> 00:15:11.220
It acts like a digital ledger

288
00:15:11.220 --> 00:15:13.980
where transactions are stored in blocks,

289
00:15:13.980 --> 00:15:15.930
and once a block is full,

290
00:15:15.930 --> 00:15:18.030
it is linked to the previous one,

291
00:15:18.030 --> 00:15:20.610
creating an unchangeable chain.

292
00:15:20.610 --> 00:15:24.420
The key feature of blockchain is its immutability,

293
00:15:24.420 --> 00:15:28.260
meaning once data is recorded, it cannot be altered,

294
00:15:28.260 --> 00:15:31.860
ensuring a trustworthy and tamper-proof record.

295
00:15:31.860 --> 00:15:34.560
Immutable databases, on the other hand,

296
00:15:34.560 --> 00:15:37.170
are systems where data, once written,

297
00:15:37.170 --> 00:15:39.330
cannot be changed or deleted,

298
00:15:39.330 --> 00:15:43.470
preserving information as it was originally recorded.

299
00:15:43.470 --> 00:15:46.500
While blockchain uses immutable databases

300
00:15:46.500 --> 00:15:48.180
as a core component,

301
00:15:48.180 --> 00:15:52.290
it also includes decentralization and cryptography

302
00:15:52.290 --> 00:15:55.170
to add security and transparency

303
00:15:55.170 --> 00:15:57.663
across its entire network.

