Build Blockchain Voting Dapp (Decentralized) using Nextjs, Solidity, MetaMask & Hardhat | Voting App

Full Transcript — Download SRT & Markdown

00:00
Speaker A
All of you, welcome back to yet another video.
00:07
Speaker A
In this video, we'll talk about the decentralized voting app project.
00:11
Speaker A
Which we have built on the channel, that why this project is so important.
00:18
Speaker A
And I'll also talk about some of the minor changes you have to do in the code base to execute.
00:29
Speaker A
Because recently Infura have made the changes in their terms and policy.
00:35
Speaker A
So you no longer will use the Infura for deploying the images to the IPFS.
00:40
Speaker A
So I have an alternative which I'm going to do the setup in this video.
00:45
Speaker A
I believe that you guys have followed this entire project, it's a four hours long.
00:51
Speaker A
This will teach you every single thing about the smart contract.
00:56
Speaker A
And how we have built the complex logic for having the voting system.
01:02
Speaker A
So let me talk about the changes I have done.
01:05
Speaker A
So right now you can see I have these two folders.
01:10
Speaker A
This one is the code base which we have coded together in this entire project.
01:16
Speaker A
So this is what we have coded together.
01:20
Speaker A
And in this I have done the minor changes in the upload function.
01:25
Speaker A
So let's talk about the complete code which we have coded together.
01:30
Speaker A
So if you see here, this is the entire smart contract we have written together in the project.
01:36
Speaker A
It's pretty huge.
01:38
Speaker A
It has close to 244 lines of code.
01:42
Speaker A
That's what we have here.
01:44
Speaker A
And the changes I have done in only two functions.
01:49
Speaker A
I haven't done any changes in the contract, but I did changes in the upload function.
01:53
Speaker A
So if I come back here in the context inside this voter, here you will find that.
02:00
Speaker A
That earlier we were using this global endpoint of Infura for deploying our images to the IPFS.
02:09
Speaker A
But when the Infura made the changes in the terms and policy for the very first time.
02:16
Speaker A
So we no longer able to use this one.
02:20
Speaker A
But in the second policy change they have introduced that if you want to use it, we have to do the configuration like this.
02:27
Speaker A
And we have to provide our valid gate card details, then you can easily able to generate the private key.
02:33
Speaker A
And the secret key and with this configuration you can simply follow.
02:38
Speaker A
And I also made a video on this where I have explained that how you can do that.
02:43
Speaker A
But this is also not working anymore.
02:46
Speaker A
Because Infura for the time being is not working in IPFS.
02:51
Speaker A
So the changes we have to do in our function in only two places.
02:56
Speaker A
So here you can see that this is what we have coded together.
03:01
Speaker A
You don't need to do anything in here.
03:03
Speaker A
So let me close it one by one.
03:05
Speaker A
So this is the check if wallet connect function, don't need to do anything in here.
03:09
Speaker A
Here we have connect wallet function.
03:11
Speaker A
Close that one.
03:13
Speaker A
And here we have to do the changes.
03:15
Speaker A
So we have to do the changes here in the upload to IPFS.
03:20
Speaker A
Because here we are using Infura.
03:22
Speaker A
So this is the change we got to do it.
03:24
Speaker A
And we have to do the changes here as well for the candidate registration.
03:28
Speaker A
And this is fine.
03:30
Speaker A
Let's close this one.
03:32
Speaker A
And this one is they get all.
03:34
Speaker A
Close this one.
03:36
Speaker A
And here we have the voter details, don't need to do anything in here.
03:39
Speaker A
And here we have this again.
03:41
Speaker A
So we have to do the changes here in this as well.
03:44
Speaker A
Set candidate.
03:46
Speaker A
And we have this.
03:48
Speaker A
The new candidate.
03:50
Speaker A
So we have to do four changes in our function.
03:55
Speaker A
Which I have already done in this updated one which I will show you.
03:58
Speaker A
So now let's come back to the updated one.
04:00
Speaker A
And let me tell you the few things which you have to know.
04:03
Speaker A
So if I come back to the package JSON file, I'm using these packages.
04:08
Speaker A
Make sure you have to use the exact version, no matter when you are building this project.
04:13
Speaker A
You have to use the exact version.
04:15
Speaker A
And it will work fine.
04:17
Speaker A
If you go with any other version, it will not work because every single version has its specific setups.
04:22
Speaker A
Which we have to do.
04:24
Speaker A
Here I'm using Hardhat.
04:26
Speaker A
I'll show you the both way that how you can use this particular application with Hardhat and without Hardhat.
04:32
Speaker A
Because recently there is a few changes have taken place in the Hardhat package.
04:37
Speaker A
And in Node as well.
04:39
Speaker A
So if I open my terminal and if I show you the Node version.
04:43
Speaker A
Like this is the version I'm using currently.
04:46
Speaker A
And this particular version is absolutely compatible with Hardhat.
04:52
Speaker A
So whether you are using the upgraded one of Hardhat or you are going with this one.
04:56
Speaker A
Because Hardhat also got couple of updates and this package has also got updated.
05:00
Speaker A
So it will work fine as long as you're working with this particular Node version or below this.
05:05
Speaker A
But if you are working with the latest one like 20, if I come back to the Node.
05:09
Speaker A
And if you're using this 20, then Hardhat will not work.
05:13
Speaker A
Okay, don't need to be panic.
05:15
Speaker A
I will show you both the way that how you can execute this smart contract and how you can run this application.
05:20
Speaker A
Without Hardhat and with Hardhat.
05:22
Speaker A
So just wait.
05:23
Speaker A
I'll show you that.
05:25
Speaker A
The very first thing I want to show you that how you can execute this code with Hardhat.
05:30
Speaker A
So make sure you have to install the exact version if you are making any changes.
05:35
Speaker A
First execute and then you do all the modification.
05:38
Speaker A
So I have this particular.
05:40
Speaker A
Now the very first thing I have to do is I have to get into this particular folder.
05:43
Speaker A
And this is the exact step you have to follow when you will download the source code or if you want to do the modification.
05:48
Speaker A
Okay, this is the exact thing you have to do.
05:50
Speaker A
So first you have to get into this folder.
05:53
Speaker A
So I'll say updated code and I'm into this particular directory.
05:57
Speaker A
And now I have to install these packages.
06:00
Speaker A
So I'll type NPM and I or install.
06:02
Speaker A
Both will work fine.
06:04
Speaker A
And hit enter.
06:05
Speaker A
This will take few seconds to install all the packages.
06:08
Speaker A
So just wait.
06:10
Speaker A
And finally I have installed all the packages successfully.
06:13
Speaker A
If you have encountered any error, try to install the packages one by one.
06:18
Speaker A
So this is looks pretty fine.
06:20
Speaker A
Now I'm going to simply clear the terminal.
06:22
Speaker A
And now let me show you the changes I have done before I execute this particular code.
06:26
Speaker A
So if I come back to the context, if I go to the voter.
06:30
Speaker A
And I'm using Pinata for deploying the images.
06:32
Speaker A
So this is the variables we have, this is the check if wallet connected.
06:36
Speaker A
I haven't done any changes, don't need to do anything.
06:38
Speaker A
This is the same function we have.
06:40
Speaker A
And here I have made the changes.
06:42
Speaker A
So instead of Infura, I'm using Pinata.
06:44
Speaker A
So this is the exact function all I have done, made the changes in this particular function.
06:49
Speaker A
So in this particular function we are using to deploy the image.
06:52
Speaker A
Again, I have covered this extensively in the project.
06:56
Speaker A
So make sure to follow that.
06:58
Speaker A
So I'm taking the image, then I'm converting into a form data.
07:01
Speaker A
And this is the endpoint for deploying any image to Pinata IPFS.
07:07
Speaker A
So this one is only for image.
07:09
Speaker A
If you want to deploy folder, if you want to deploy JSON data, it has a different endpoint which I will talk about.
07:14
Speaker A
So this is the exact configuration you have to do.
07:18
Speaker A
Method this, URL endpoint.
07:20
Speaker A
This is the data.
07:22
Speaker A
And here we have this header.
07:24
Speaker A
And you have to get your like API key and the API secret key, which is absolutely free to get from Pinata.
07:30
Speaker A
And I have made tons of video.
07:33
Speaker A
So make sure to check that how you can get this particular key and how you can get this particular secret key.
07:37
Speaker A
I'll link in the I button on the description.
07:39
Speaker A
So you can follow that video.
07:40
Speaker A
So simply paste here.
07:42
Speaker A
Or if you download the source final source code in that I will provide you this, so you can simply go with this my keyword.
07:47
Speaker A
So what we are doing, we are simply uploading the image.
07:50
Speaker A
Then we are getting the hash.
07:52
Speaker A
And that's what we are returning here.
07:54
Speaker A
So this is the changes I have done here in the upload to IPFS.
07:57
Speaker A
This is the exact function name we have given in the old code base.
08:00
Speaker A
And this is what I have done here.
08:02
Speaker A
So this is the one change you have to do.
08:04
Speaker A
Now here we have to do the same thing in the candidate upload.
08:07
Speaker A
And this is exactly the same thing I have done, I have provided my Pinata configuration and the credential.
08:12
Speaker A
And we are uploading the image to Pinata.
08:14
Speaker A
So this is for the image.
08:16
Speaker A
Pinata file to IPFS.
08:20
Speaker A
So this endpoint is for image.
08:22
Speaker A
Now we'll talk about the JSON data.
08:25
Speaker A
Because in the project we have used like Infura IPFS for uploading the JSON as well.
08:30
Speaker A
That will also I will cover.
08:32
Speaker A
So these are the two changes, make sure to do that in both the function.
08:36
Speaker A
And here we have this create voter.
08:38
Speaker A
So those who will vote, they can create their profile.
08:42
Speaker A
And we have to upload their information as well.
08:44
Speaker A
Now here you can see that here we are uploading the JSON data.
08:47
Speaker A
So this is absolutely fine.
08:50
Speaker A
We are getting checking the condition that whether the data is available or not.
08:55
Speaker A
Again, I'm telling you that I have extensively covered this in the project.
08:59
Speaker A
So make sure to follow the complete project.
09:01
Speaker A
You will understand everything.
09:02
Speaker A
This is the Web3 model configuration for making the connection with our contract.
09:06
Speaker A
And the our wallet.
09:08
Speaker A
We are converting the entire data into the JSON file.
09:11
Speaker A
And that's what we are passing into our IPFS.
09:15
Speaker A
So this is the endpoint for the JSON data.
09:17
Speaker A
You can see pin JSON to Pinata IPFS.
09:20
Speaker A
So this is the endpoint we are using to uploading the JSON data.
09:23
Speaker A
And same thing we have provided the header configuration like the API key and the secret key.
09:27
Speaker A
And then we are returning the URL and that's what we are passing into our smart contract.
09:30
Speaker A
Into the contract.
09:32
Speaker A
So this is the exact thing you have to do if you want to upload the JSON file.
09:36
Speaker A
And that's what we have done here.
09:37
Speaker A
Again, make sure to pause it.
09:40
Speaker A
I'm just simply scrolling slowly, slowly.
09:42
Speaker A
So you can simply type it down.
09:44
Speaker A
So this is the one change you have to do.
09:46
Speaker A
And the same change we have to do here in the candidate as well.
09:49
Speaker A
Because this one is for the voter.
09:51
Speaker A
And this one is get all voter.
09:53
Speaker A
So we don't need to do any changes here.
09:55
Speaker A
Close that one.
09:57
Speaker A
And now come back here, give voter.
09:59
Speaker A
Don't need to do any changes here.
10:01
Speaker A
And here we have to do the changes.
10:03
Speaker A
So candidate set candidate.
10:05
Speaker A
In that we are taking the data.
10:08
Speaker A
Then we are making the connection with the wallet.
10:10
Speaker A
Converting the data into a JSON format.
10:13
Speaker A
And then we are simply uploading the data to the IPFS.
10:17
Speaker A
And this is the endpoint we are calling.
10:19
Speaker A
At the end, it's going to return the entire URL which contain all of this information.
10:24
Speaker A
And that's what we are passing into our contract.
10:26
Speaker A
Got it?
10:27
Speaker A
I believe that you guys have understood that what logic we have implemented.
10:32
Speaker A
It's a pretty simple change.
10:34
Speaker A
All you have to do to simply provide the API key and the secret key.
10:40
Speaker A
And if you get the final source code in that I will provide you this my key.
10:44
Speaker A
It's pretty easy to get your own one, simply go to the Pinata.
10:48
Speaker A
Or you can watch this video in that I have explained extensively.
10:51
Speaker A
So these are the four changes you have to do in four of these functions.
10:55
Speaker A
Hope things are fine to all of you guys.
10:57
Speaker A
And now let me show you how you can execute that.
10:59
Speaker A
So first you have to get into this folder.
11:01
Speaker A
And let's come back here.
11:04
Speaker A
We are already into this particular folder.
11:06
Speaker A
And now we have to simply start the application.
11:09
Speaker A
So this is the command we have to run, again you have to install the exact version, no matter when you are watching this project.
11:14
Speaker A
So simply type.
11:16
Speaker A
So we have already installed that, now we have to simply type this one.
11:20
Speaker A
Type NPM run dev.
11:23
Speaker A
And this will start the application on localhost 3000.
11:26
Speaker A
You can simply copy.
11:28
Speaker A
And you can simply paste in your browser.
11:30
Speaker A
So come back to the browser.
11:32
Speaker A
Make sure to check your Node version.
11:34
Speaker A
Come here, paste.
11:36
Speaker A
And you can simply see.
11:38
Speaker A
Our application is working fine.
11:41
Speaker A
Right now we don't have any data because we have not connected with the application.
11:44
Speaker A
Now all we have to do is simply click on this connect wallet.
11:48
Speaker A
It's going to open this Metamask.
11:50
Speaker A
Provide your, provide your credential.
11:53
Speaker A
So I'll say.
11:55
Speaker A
And here I'm connected.
11:58
Speaker A
But the one thing you will notice that we haven't deployed the contract.
12:03
Speaker A
So there is nothing in here.
12:05
Speaker A
So I'll come back to my code base because I have to show you the both method.
12:09
Speaker A
First Hardhat, then second the test network.
12:12
Speaker A
The Mumbai test network.
12:14
Speaker A
So what I will do, I'll simply going to stop the application.
12:18
Speaker A
Now you have to split your terminal in two parts.
12:20
Speaker A
And make sure you are into the same directory.
12:23
Speaker A
Now we have to start our local blockchain.
12:26
Speaker A
So come back to the Hardhat config file.
12:29
Speaker A
And here you can see that we are interacting with our local host.
12:33
Speaker A
So let's run the local node into our system.
12:36
Speaker A
So this is the command you have to write, very simple.
12:39
Speaker A
NPX Hardhat node.
12:41
Speaker A
And hit enter.
12:42
Speaker A
It will start the application, you can see it will start your local blockchain.
12:46
Speaker A
And it will give you 20 plus account.
12:48
Speaker A
And you can utilize this account to test your contract, to make the transaction.
12:54
Speaker A
Because each one of this account has close to 10,000 fake ether.
12:58
Speaker A
Which you can use to test your.
13:00
Speaker A
And if you want to import any one of these account, all you have to do is to simply get this private key.
13:05
Speaker A
Copy this private key.
13:07
Speaker A
Come back here.
13:09
Speaker A
Click here in your Metamask.
13:11
Speaker A
Switch back to the local host.
13:13
Speaker A
So this is the local host.
13:15
Speaker A
Click here.
13:16
Speaker A
And I have already done the configuration for the local host.
13:20
Speaker A
And I have already imported a lot of accounts.
13:23
Speaker A
You can see all of these accounts.
13:25
Speaker A
I have imported because I was working on the social media platform.
13:29
Speaker A
And I have imported that.
13:31
Speaker A
So you can see all of these accounts.
13:33
Speaker A
So all you have to do is to simply click here and click on this add account.
13:37
Speaker A
And paste here.
13:39
Speaker A
Click on this import.
13:40
Speaker A
And here I have imported.
13:42
Speaker A
And it has zero, nothing in here.
13:44
Speaker A
This is how you can import.
13:46
Speaker A
Now let me show you one thing that what are the configuration you have to do.
13:50
Speaker A
If you want to import local host.
13:52
Speaker A
So come back here.
13:54
Speaker A
I'll say click on this add network.
13:57
Speaker A
And you will redirect to the different page.
14:00
Speaker A
So click here in the network.
14:02
Speaker A
And this is my configuration for the local host.
14:04
Speaker A
So this is the name.
14:06
Speaker A
This is the RPC endpoint.
14:08
Speaker A
This is the chain ID.
14:10
Speaker A
This is the currency.
14:12
Speaker A
And I have saved it.
14:13
Speaker A
So make sure you have to provide the exact value if you want to connect with the local host.
14:17
Speaker A
So that's the exact setup you have to do.
14:19
Speaker A
Right now you can see this is throwing an error because we have not deployed our contract.
14:23
Speaker A
And it's trying to fetch out the information from the contract, that's why it's throwing the error.
14:27
Speaker A
So our application is also shut.
14:29
Speaker A
Now I'm going to simply come back here.
14:32
Speaker A
And our local blockchain is running.
14:34
Speaker A
And by default Hardhat will take this very first account for deploying all your contract.
14:39
Speaker A
All your contract.
14:41
Speaker A
This is the account Hardhat will take by default.
14:43
Speaker A
Now we have to simply execute and run our deploy script.
14:46
Speaker A
So here we have this deploy script.
14:48
Speaker A
And this is what we have to run.
14:50
Speaker A
It's going to simply deploy our contract.
14:52
Speaker A
So if I show you what is the name I have given to my contract.
14:56
Speaker A
I call it create.
14:58
Speaker A
You can call it whatever you want.
15:00
Speaker A
So that's what we are deploying.
15:02
Speaker A
And at the end it's going to return the address of our, of our contract.
15:06
Speaker A
So I'll say here it says that.
15:08
Speaker A
Let's change this text to address.
15:10
Speaker A
Like voting.
15:12
Speaker A
That's what I'm going to do is.
15:15
Speaker A
And now let's deploy that one.
15:17
Speaker A
And this is the exact command you have to type, make sure you have to keep running this one.
15:22
Speaker A
Otherwise the application will not work.
15:25
Speaker A
And the, the contract will not deploy.
15:27
Speaker A
So this is the exact command you have to type, NPX Hardhat run network localhost, then script deploy.
15:32
Speaker A
Because our deploy script inside this particular folder.
15:35
Speaker A
And that's what we are targeting.
15:37
Speaker A
And all you have to do is to simply click and hit enter.
15:39
Speaker A
This one is going to compile your contract.
15:42
Speaker A
And here it's you can see it's taking a little bit time.
15:45
Speaker A
But soon it will give us the contract.
15:48
Speaker A
And here we got this particular contract address.
15:51
Speaker A
This is the address.
15:52
Speaker A
And by default, when you will deploy your very first contract, Hardhat will give you the exact address in your case as well.
15:57
Speaker A
So simply copy that one.
15:59
Speaker A
And you can see I have this particular artifact.
16:01
Speaker A
In that I have the ABI of the contract.
16:04
Speaker A
So if you want to remove it, you can remove because when you will deploy the contract, it will automatically Hardhat will automatically will create this particular artifact.
16:09
Speaker A
Which you can simply take it.
16:11
Speaker A
The ABI.
16:13
Speaker A
And you can simply drag and drop here.
16:15
Speaker A
Because we already have it here because I haven't done any changes in the contract.
16:18
Speaker A
But make sure whenever you do any changes in the contract.
16:20
Speaker A
It will generate a different ABI and that's the ABI you have to provide.
16:23
Speaker A
And that's what you will find here in the artifact.
16:25
Speaker A
So click on the artifact.
16:27
Speaker A
Come back to the contract and here you will have the ABI.
16:30
Speaker A
Simply drag and drop.
16:32
Speaker A
Okay, simply drag and drop.
16:34
Speaker A
I'll call it replace.
16:35
Speaker A
You can see it's replaced.
16:36
Speaker A
So you have the ABI.
16:38
Speaker A
Now everything is set.
16:40
Speaker A
Now we can start our application.
16:42
Speaker A
So I'll simply type NPM run dev.
16:45
Speaker A
And this one is going to start the application on localhost 3000.
16:48
Speaker A
The same port.
16:50
Speaker A
Now we can come back here and reload the page.
16:52
Speaker A
And here we have this application up and running.
16:55
Speaker A
Right now we don't have any issue.
16:57
Speaker A
If I show you the terminal.
16:59
Speaker A
Let me close this one.
17:01
Speaker A
If I go to the console, I don't have any issue.
17:04
Speaker A
Because everything is working fine.
17:06
Speaker A
Now what I'm going to do is, first and the foremost thing I have to do.
17:10
Speaker A
Before I create account or register any voter, I have to clear my Metamask history.
17:15
Speaker A
So first I have to switch back to my account.
17:18
Speaker A
So I'm going to use this particular account.
17:21
Speaker A
The let's click on this switch to my account.
17:23
Speaker A
And you can see by default Hardhat will take the very first account and that's the account I have imported as a account two.
17:29
Speaker A
So I got some fund deducted from this account for deployment.
17:32
Speaker A
Now what I have to do is, very first thing before I do anything.
17:35
Speaker A
I have to clear my history.
17:38
Speaker A
If I don't do that, the transaction will fail.
17:40
Speaker A
And this is the weird problem we have in the local host and in Metamask.
17:44
Speaker A
So whenever you do any changes in the account, you have to clear your Metamask history.
17:48
Speaker A
Otherwise the transaction will fail.
17:50
Speaker A
So click on this.
17:51
Speaker A
And clear.
17:52
Speaker A
Once you're done with that, now you are ready to work on this.
17:55
Speaker A
Here you can see here we have the dropdown menu.
17:57
Speaker A
So let's register a candidate.
18:00
Speaker A
So click on that.
18:02
Speaker A
And here we have this option.
18:04
Speaker A
So here we have that.
18:06
Speaker A
Now what I'm going to do is, I'm going to upload a user.
18:09
Speaker A
So I'm going to simply click here.
18:11
Speaker A
It's going to open my pop-up model.
18:13
Speaker A
I'm going to select an image.
18:15
Speaker A
So I'm going to nominate myself.
18:17
Speaker A
And here it's going to deploy the image.
18:20
Speaker A
So just wait, the image will soon reflect here.
18:22
Speaker A
And finally the image is successfully deployed.
18:25
Speaker A
And you can also check in your terminal.
18:28
Speaker A
Here we got this.
18:30
Speaker A
You can simply copy that one.
18:32
Speaker A
You can paste into a new tab.
18:34
Speaker A
And you can have a look.
18:36
Speaker A
So it's successfully deployed.
18:38
Speaker A
This is the image we have deployed.
18:40
Speaker A
It's working fine.
18:42
Speaker A
No issue we have so far.
18:44
Speaker A
Here you have to provide the name of the candidate.
18:46
Speaker A
Again, I have explained every single thing in the project.
18:50
Speaker A
So make sure to watch this.
18:52
Speaker A
Follow this entire four hour long project, you will learn tons of things.
18:56
Speaker A
All the terminology.
18:58
Speaker A
I have explained deeply.
19:00
Speaker A
Now I'll give my name.
19:02
Speaker A
I'll say Daulat.
19:03
Speaker A
Okay, let me pick here.
19:05
Speaker A
I'll say Daulat Hussain.
19:08
Speaker A
Now I have to give the address.
19:10
Speaker A
So I can take my own address.
19:12
Speaker A
I can click here.
19:13
Speaker A
Copy.
19:14
Speaker A
I can paste here.
19:16
Speaker A
And I can simply call the age.
19:18
Speaker A
Let's call it one years old.
19:20
Speaker A
Quite funny.
19:21
Speaker A
Now I'm going to click on this authorize candidate.
19:23
Speaker A
So click on this.
19:25
Speaker A
It's going to open my Metamask.
19:27
Speaker A
And I will make the transaction.
19:29
Speaker A
So just wait, here it's come.
19:31
Speaker A
Finally the Metamask popped up, click on this confirm.
19:34
Speaker A
And the transaction is confirmed.
19:37
Speaker A
And here you can see we got one candidate registered.
19:40
Speaker A
If you reload the page, the candidate will reflect here.
19:42
Speaker A
There is one candidate.
19:44
Speaker A
It's working fine.
19:46
Speaker A
We have one candidate.
19:48
Speaker A
In the same way you can register as many candidate as you want.
19:51
Speaker A
So it will also display that how many candidates are listed.
19:55
Speaker A
The previous candidate.
19:57
Speaker A
So this will happen only in development, not in production.
20:00
Speaker A
So you can same, you can click here.
20:03
Speaker A
You can come back here.
20:05
Speaker A
You can register one more user.
20:07
Speaker A
And it's going to simply update.
20:09
Speaker A
So just wait.
20:10
Speaker A
Here it got it.
20:12
Speaker A
Now I can simply give the name.
20:14
Speaker A
I can call it Md Shahir.
20:16
Speaker A
I have to give the address.
20:18
Speaker A
So I can simply come back here.
20:20
Speaker A
And I'm going to pick an account.
20:22
Speaker A
So this time I'm going to take this particular first account.
20:25
Speaker A
This gentleman.
20:27
Speaker A
Now I'll to get back to my.
20:29
Speaker A
No, get back to my second account.
20:31
Speaker A
And I have to clear my history.
20:33
Speaker A
Otherwise the transaction will fail.
20:35
Speaker A
Okay.
20:36
Speaker A
Now.
20:37
Speaker A
Got it.
20:38
Speaker A
Okay.
20:39
Speaker A
I have to redeploy the image.
20:41
Speaker A
Not a not a big deal.
20:42
Speaker A
So just a moment.
20:44
Speaker A
Here we got it.
20:46
Speaker A
Now I can give the name.
20:48
Speaker A
I'll say Md Shahir.
20:49
Speaker A
I'll give the address.
20:51
Speaker A
I'll give the age is going to be five.
20:52
Speaker A
And click on authorize candidate.
20:54
Speaker A
It's going to open the Metamask.
20:56
Speaker A
And we'll have this user.
20:58
Speaker A
We'll get this two user.
21:00
Speaker A
Everything is working fine.
21:01
Speaker A
Now we have registered two candidates, now let's register the voter.
21:05
Speaker A
So I'll click here.
21:07
Speaker A
And I'm going to register as a voter.
21:09
Speaker A
So what I will do is, I can simply come here.
21:12
Speaker A
I have to take a account.
21:14
Speaker A
So this this particular account I'm going to use, account three.
21:17
Speaker A
So copy this one and I'm going to register this user as a voter.
21:20
Speaker A
So go back here.
21:22
Speaker A
And I'm simply come back here.
21:24
Speaker A
I'll clear my history.
21:26
Speaker A
Again because I have done the change of account.
21:28
Speaker A
So that's the thing I have done.
21:30
Speaker A
I got the address.
21:32
Speaker A
Now I can simply click here.
21:34
Speaker A
You can see.
21:36
Speaker A
Okay, there is there.
21:38
Speaker A
I have the detail.
21:40
Speaker A
Now click here.
21:42
Speaker A
Now I have to get the user.
21:44
Speaker A
So this time I'm going to get this gentleman.
21:47
Speaker A
So let's select my image as well.
21:49
Speaker A
There is no problem in that.
21:51
Speaker A
So we got that.
21:53
Speaker A
Just wait, here we got that.
21:55
Speaker A
So this is the voter registration.
21:57
Speaker A
And I can call it voter.
21:59
Speaker A
Let's give the address.
22:01
Speaker A
And I'll say one voter.
22:03
Speaker A
You can call it position whatever you want.
22:05
Speaker A
Let's call this authorize voter.
22:07
Speaker A
And it's going to open the Metamask.
22:09
Speaker A
And it will make the transaction.
22:11
Speaker A
So finally we have registered.
22:13
Speaker A
If you reload the page, if you reload the page, it will work fine.
22:15
Speaker A
So we have one voter, two candidate for voting.
22:17
Speaker A
Now let me give vote to one of these candidates.
22:20
Speaker A
So this account three has the right.
22:23
Speaker A
Because this is the address we have assigned.
22:26
Speaker A
So only he can give the vote.
22:28
Speaker A
So let me switch my account.
22:30
Speaker A
And clear all the history.
22:32
Speaker A
Right there.
22:34
Speaker A
Now I can give the vote.
22:36
Speaker A
There it is.
22:38
Speaker A
Now I can simply click on Daulat Hussain.
22:40
Speaker A
I click on this give vote.
22:42
Speaker A
It's going to open the Metamask.
22:44
Speaker A
And again click on this confirm.
22:46
Speaker A
And it's going to make the transaction.
22:48
Speaker A
Just wait, here the transaction is happening.
22:50
Speaker A
It's taking a little bit time, but soon the transaction will complete.
22:53
Speaker A
And you will see it will work absolutely fine.
22:55
Speaker A
And finally the transaction is completed.
22:58
Speaker A
And you can see I have given one vote to this particular user.
23:00
Speaker A
So it's working absolutely fine.
23:02
Speaker A
That whom you have given your vote.
23:04
Speaker A
And if you come back to the voter.
23:06
Speaker A
And here you can see you have given the vote.
23:08
Speaker A
So every single thing is working fine.
23:10
Speaker A
You can see that.
23:12
Speaker A
It's looks absolutely incredible.
23:14
Speaker A
We don't have any issue in our application.
23:16
Speaker A
So this is what you have to do in the project.
23:20
Speaker A
Only changes you have to do in the project in this four functions.
23:23
Speaker A
The this one, set candidate.
23:25
Speaker A
And we have this create voter.
23:27
Speaker A
Upload to IPFS candidate.
23:29
Speaker A
And upload to IPFS.
23:31
Speaker A
Make sure to do all of this update which I explained you.
23:34
Speaker A
And it will work fine.
23:36
Speaker A
So this is the first method if you want to use Hardhat for building this project.
23:40
Speaker A
But for those of you who don't want to use Hardhat and you want to use on the project only on the smart contract.
23:45
Speaker A
Then I will show you the other way.
23:47
Speaker A
So let's talk about the other way that how you can simply overcome this Hardhat.
23:50
Speaker A
So the first thing I would suggest you to make sure to follow this project.
23:54
Speaker A
In that I have used Hardhat, but if you don't want to use Hardhat, you can do simply one thing.
23:58
Speaker A
In the project, create this particular folder.
24:02
Speaker A
In that create this particular file.
24:05
Speaker A
And write the entire smart contract as I have explained in the project.
24:08
Speaker A
But don't install this particular libraries, these two libraries.
24:12
Speaker A
Simply remove these two libraries because if you don't want to use it Hardhat, then why should you install that?
24:16
Speaker A
So that's the unnecessary installation you have to do.
24:18
Speaker A
And remove this script folder.
24:20
Speaker A
Remove this test file.
24:22
Speaker A
Because these are the unnecessary.
24:24
Speaker A
Remove this Hardhat like config file as well.
24:26
Speaker A
And that will work fine.
24:28
Speaker A
So make sure to do all of this.
24:30
Speaker A
And now let's deploy the contract to the test network.
24:33
Speaker A
So simply copy this entire piece of code.
24:36
Speaker A
Now come back to the Remix ID.
24:38
Speaker A
Because that's what we're going to use it.
24:40
Speaker A
So simply come back here.
24:42
Speaker A
Open a new tab.
24:44
Speaker A
And let's click on this Remix ID.
24:46
Speaker A
I hope you guys know what is Remix ID.
24:48
Speaker A
And this is where you can land.
24:51
Speaker A
And you can simply create a directory.
24:53
Speaker A
I can see I have in my default workspace.
24:55
Speaker A
I'm going to create a folder.
24:57
Speaker A
So file, sorry.
24:59
Speaker A
I click on this contract.
25:01
Speaker A
Let's create a file.
25:03
Speaker A
I can call it, let's say voting.sol.
25:05
Speaker A
And I'm going to simply paste the entire contract.
25:07
Speaker A
Simply okay.
25:08
Speaker A
And here we have the entire contract, I'm using this particular version.
25:12
Speaker A
Here we have done the import.
25:14
Speaker A
There is no issue because this particular ID is compatible with this all import of the packages.
25:18
Speaker A
Now we have to deploy to the Polygon Mumbai.
25:21
Speaker A
So what I'm going to do.
25:23
Speaker A
I'm going to simply change my account.
25:25
Speaker A
So I'm going to simply close this one.
25:27
Speaker A
I will click here.
25:29
Speaker A
And I can come back to the Mumbai.
25:31
Speaker A
I hope you already know what is Mumbai.
25:33
Speaker A
I'll come back to my account number six.
25:35
Speaker A
Because in that I have fund.
25:37
Speaker A
You can see I'm having this much fund in my Mumbai.
25:40
Speaker A
So same thing I have to do.
25:42
Speaker A
I have to simply clear my Metamask history.
25:44
Speaker A
Again because I have done the change of account.
25:46
Speaker A
So that's the first step I have to do.
25:48
Speaker A
Now I have to get from free Meti.
25:50
Speaker A
In your case, I already have this much Meti.
25:53
Speaker A
I can use it for deployment.
25:55
Speaker A
But in your case if you don't have.
25:57
Speaker A
You have to get it, then you can deploy.
25:59
Speaker A
So come back here, type Alchemy faucet.
26:01
Speaker A
And you will land on this particular website.
26:04
Speaker A
Click on the very first link.
26:06
Speaker A
And here you will have, you can pick any network.
26:10
Speaker A
Right now we have 40 plus blockchain.
26:12
Speaker A
You can pick any network for deploying.
26:14
Speaker A
So I'll go with this Mumbai.
26:16
Speaker A
Click here.
26:18
Speaker A
It's going to open up this.
26:20
Speaker A
And all you have to do is simply, simply get the address of your wallet.
26:23
Speaker A
Copy this one.
26:24
Speaker A
And simply paste here.
26:26
Speaker A
And make a request.
26:27
Speaker A
And it says that you can't allow to take before 24 hours.
26:32
Speaker A
Because in the morning I have already imported.
26:35
Speaker A
And that's why you can see I have this much fund.
26:37
Speaker A
So you have to wait for the next 24 hours to make a request.
26:40
Speaker A
So this is how you can get it.
26:42
Speaker A
So once you make a request, it will show you a confirmation page.
26:46
Speaker A
And you have to wait for 30 seconds to one minute.
26:49
Speaker A
And the balance will reflect here.
26:50
Speaker A
So make sure you need to have fund in your wallet.
26:52
Speaker A
And that's the wallet I'm going to use for deploying of the contract.
26:55
Speaker A
So once you have everything here.
26:57
Speaker A
Now click on this particular button.
26:59
Speaker A
And here you have to select injected provider.
27:01
Speaker A
So select here, it's going to simply connect with the wallet.
27:04
Speaker A
You can see it will fetch the wallet connected, it will reflect the balance.
27:08
Speaker A
And it will show you the chain ID which you are connected.
27:10
Speaker A
Which is a Polygon Mumbai.
27:12
Speaker A
And now here I have this many contract.
27:14
Speaker A
But make sure to click on this.
27:17
Speaker A
So if I show you this is the Hardhat.
27:19
Speaker A
This is the counter from the Open Zeppelin.
27:21
Speaker A
And here we have this create.
27:23
Speaker A
And that's what I'm using.
27:25
Speaker A
So this is the contract which I'm going to deploy.
27:27
Speaker A
So select this one.
27:29
Speaker A
And now all you have to do is to click on this deploy.
27:31
Speaker A
And it's going to open the Metamask.
27:33
Speaker A
Just wait, here we have the Metamask.
27:35
Speaker A
And now click on this confirm.
27:37
Speaker A
And it's going to make the transaction.
27:39
Speaker A
So let me show you the transaction is happening.
27:41
Speaker A
So this process will take a little bit time.
27:44
Speaker A
Because right now we are dealing on the test network.
27:47
Speaker A
And finally the transaction is completed.
27:50
Speaker A
And here it will give you your contract instance.
27:52
Speaker A
So if you come back here, you can able to see the fund.
27:55
Speaker A
And all the function we have deployed in the contract.
27:58
Speaker A
So you will learn a lot of things when you will follow this entire project.
28:01
Speaker A
Because we have covered so many things.
28:03
Speaker A
So this is the entire function we have.
28:06
Speaker A
You can simply interact and do the transaction right from here.
28:09
Speaker A
But we have built our front end.
28:11
Speaker A
So simply get this particular address, copy this one.
28:14
Speaker A
And that's the only thing you need.
28:16
Speaker A
That's the only thing you need.
28:18
Speaker A
And come back here.
28:20
Speaker A
Now close this one.
28:22
Speaker A
Come back to the context.
28:24
Speaker A
And here you have to simply replace the address.
28:27
Speaker A
Here you have to simply replace the address.
28:29
Speaker A
So this is the previous contract I have deployed to the different network.
28:32
Speaker A
I'm going to simply remove that one.
28:34
Speaker A
This is the address for the Hardhat local.
28:36
Speaker A
I'm going to simply replace with the Mumbai.
28:39
Speaker A
Paste here.
28:41
Speaker A
And the one thing we have to keep in mind that we need the ABI.
28:44
Speaker A
So we still need the ABI so we can interact with our contract.
28:47
Speaker A
So there is multiple way you can simply compress, you can use Hardhat, you can use Ganache.
28:52
Speaker A
There is tons of library which you can use to get the ABI of any contract.
28:55
Speaker A
Once we done with that.
28:57
Speaker A
This constant.
28:59
Speaker A
This setups.
29:01
Speaker A
And the ABI.
29:03
Speaker A
Now we can start interacting with our Mumbai test network.
29:06
Speaker A
So if I open this up.
29:08
Speaker A
I'm going to stop this.
29:10
Speaker A
Because right now we are not using Hardhat.
29:12
Speaker A
Simply stop that one.
29:14
Speaker A
And we have to stop our application as well.
29:16
Speaker A
Let's close all of that.
29:18
Speaker A
Let's close one of the terminal.
29:19
Speaker A
And that's what we have.
29:21
Speaker A
So we are still in the same directory.
29:23
Speaker A
Now we have to simply type NPM run dev.
29:25
Speaker A
And it will work fine.
29:28
Speaker A
So here our application got started.
29:30
Speaker A
Come back in the browser.
29:32
Speaker A
Go back to the application.
29:34
Speaker A
And reload the page.
29:36
Speaker A
The moment you do that.
29:38
Speaker A
This time we are interacting with the Polygon test network.
29:40
Speaker A
So click here and we are connected.
29:42
Speaker A
You can simply come back here.
29:44
Speaker A
And you can log it to log out from your account.
29:46
Speaker A
So click on this.
29:48
Speaker A
And here it will simply log out.
29:50
Speaker A
And it will open up this Metamask to log in.
29:52
Speaker A
So everything is working fine.
29:54
Speaker A
Okay, what is the password?
29:56
Speaker A
Okay.
29:58
Speaker A
Not at all.
30:00
Speaker A
Finally I got the right password.
30:02
Speaker A
You can see things are looking pretty fine.
30:04
Speaker A
Now I come back to the candidate registration.
30:07
Speaker A
I can click on that.
30:09
Speaker A
It will take me here.
30:11
Speaker A
And I can simply pick an image.
30:13
Speaker A
I'll pick my image.
30:15
Speaker A
I have to select the address.
30:17
Speaker A
Because this is the address I will use as a nominee.
30:19
Speaker A
I can give the name.
30:21
Speaker A
I'll say Daulat Hussain.
30:23
Speaker A
I'll give the address.
30:25
Speaker A
And I'll give the position is going to be.
30:27
Speaker A
You can type it whatever.
30:29
Speaker A
I'll say blockchain developer.
30:31
Speaker A
And you can click on this authorize candidate.
30:33
Speaker A
And it's going to make the transaction.
30:35
Speaker A
It's going to open up the Metamask.
30:37
Speaker A
And click on this confirm.
30:39
Speaker A
And here the transaction is happening.
30:42
Speaker A
So you can see the transaction is still happening.
30:44
Speaker A
So just wait.
30:46
Speaker A
So make sure to follow this.
30:48
Speaker A
You will understand everything.
30:50
Speaker A
That's everything is explained in the project.
30:52
Speaker A
So just wait, still the transaction is happening.
30:55
Speaker A
Because this time we are dealing in the actual test network.
30:58
Speaker A
And finally the transaction is completed.
31:01
Speaker A
And you can simply reload the page.
31:03
Speaker A
And here you can see we got one user.
31:05
Speaker A
And that's what it's reflecting here.
31:07
Speaker A
Blockchain developer.
31:09
Speaker A
Now anybody can give vote.
31:11
Speaker A
So this is how you can execute this project.
31:14
Speaker A
Many of you have question that is this project still relevant?
31:17
Speaker A
Yes, it is.
31:18
Speaker A
This one is one of the most important project you can add in your portfolio.
31:22
Speaker A
So I hope you guys have understood that how you can execute and what are the changes you have to do in the code base to execute.
31:26
Speaker A
And this is the updated code and this is the old code which we have written together.
31:29
Speaker A
And if you want to get the final code, you can simply come back to the blockchain coder.
31:33
Speaker A
Here you will find tons of project we have built.
31:36
Speaker A
More than 35 project we have.
31:38
Speaker A
All of this extensive big project that will teach you a lot of things.
31:43
Speaker A
So come back here.
31:45
Speaker A
And simply come back here and you can simply, I'm going to attach this particular video right up here.
31:49
Speaker A
So you can simply follow that.
31:51
Speaker A
And if you want to deploy this, so in this particular video I have explained that how you can deploy this particular application to internet.
31:55
Speaker A
So you can follow that as well.
31:57
Speaker A
So all you have to do is to click here and get the startup file.
32:00
Speaker A
And start working on the project and follow this.
32:03
Speaker A
So hope you guys have understood every single thing which I have covered.
32:06
Speaker A
And if you want to take your skill, the learning to the next level and building one of the most complex project.
32:11
Speaker A
And learning about the Solidity smart contract framework like crash courses.
32:16
Speaker A
That's all I have in this particular course which I have launched for the blockchain developer.
32:20
Speaker A
Which you have to check.
32:22
Speaker A
It's pretty huge.
32:24
Speaker A
We have got an amazing response.
32:26
Speaker A
From a lot of developer.
32:28
Speaker A
So you can see.
32:30
Speaker A
It is a complete ready to build and join organization and project.
32:35
Speaker A
I want to drag your attention to the modules I have.
32:38
Speaker A
So here you will learn every single thing about the Solidity course.
32:42
Speaker A
We have more than 60, 60 videos.
32:45
Speaker A
Like close to 60 videos we have in which we're going to learn about every single syntax.
32:50
Speaker A
We're going to do the practice of the smart contract.
32:52
Speaker A
Then we're going to learn about the NFT marketplace.
32:55
Speaker A
It is one of the biggest project.
32:57
Speaker A
In that you will see we will write more than six to seven contract for different business model.
33:02
Speaker A
And we're going to combine it all the contract in one central place to build a ready to working business in the blockchain.
33:08
Speaker A
So that's all the things we have explained.
33:10
Speaker A
Here we have the crash course that what you will learn like HTML, CSS, React and Next.js.
33:14
Speaker A
Tailwind, Hardhat, Metamask, Web3 providers.
33:18
Speaker A
So we have tons of things in this particular course.
33:20
Speaker A
So I would encourage you to take this one.
33:23
Speaker A
That will teach you a lot of things.
33:26
Speaker A
And currently it's going 35% off for the newer.
33:29
Speaker A
So you can simply join that one.
33:31
Speaker A
So that's the only thing for my end, I hope you guys have got an idea that how you can execute this file.
33:34
Speaker A
If you still have any confusion, any doubt, do let me know in the comment section, definitely I'll try to help you with that.

Get More with the Söz AI App

Transcribe recordings, audio files, and YouTube videos — with AI summaries, speaker detection, and unlimited transcriptions.

Or transcribe another YouTube video here →