字幕列表 影片播放
everybody.
This is Gregory from DAP University.
So today I'm gonna show you how to write your first Blockchain application.
I'll show you how to create a to do list is powered by a theory.
Um, smart contracts.
I'll show you how to create your first Ethereum smart contract with a solidity programming language or right tests against the smart contract deployed to a Blockchain.
It will also create a client side application for the to do list.
So if you're new around here, be sure to subscribe to this channel and click the like button down below.
And also, you could download my courses for free on the Web site over dap university dot com forward slash free download.
I've got a link to that data the description below and also on my website.
You can find a fooling article to accompany this video.
You can actually fall that step by step and you're following this tutorial, and I've also got a link to that in the video description.
So before we start actually building the application, let's get a high level overview of how Blockchain application power by smart contract actually works.
The hat is a Blockchain work And how does a Blockchain application work?
Well, I've chosen a to do list for this tutorial because that's really common way to learn any new technology, and I want to use that to show you how a blotch application works.
So first, let's look at how it to do.
This would work as a Web application, and then I'll show you how it works as a blotch in application.
So put my white board up here to demonstrate.
Normally, whenever you access a Web application, look a to do list.
For example, you use a Web browser and you connect to a Web server over the Internet and you access, you know, all the code and all the data from this Web server.
So, like this, you basically connect from your Web browser to the server and on the server.
It contains all the clients.
I've files like html CSS and JavaScript, you know, contains all of the back end code for the server, right in the business logic, you mart right?
And any data that story application is stored in the database, right?
And pretty much any other to do list tutorial that's out there is going to show you how to write your clients at application and HTML CSS and JavaScript.
And then it's gonna show you how to basically use a business logic on a Web back end that creates reads, writes updates to do's.
And it puts them inside of a database like this, right?
And all that's, you know, on a central server.
And that's how you build a to do list on a wet application.
So how would you build a to do list on a Blockchain?
Well, it work a little bit differently.
So instead of connecting directly to a server, you know, we're gonna access our to do list via browser, and we're gonna, you know, connect to client side application that we will build.
This will just be a simple client application on a Web server.
But this client application isn't gonna talk to a Web back end in a database.
Instead, it's gonna actually talk directly to the block chain and on the block chain.
We're gonna have code that's gonna be written with ethereum smart contracts that will contain all of the business logic for our to do list and all the to do items are gonna be stored on the block chain itself.
And that's fundamentally how AH black shin application would work and how it's different from a traditional Web application.
So that might bring up a lot of questions, like how to be connected.
A Blockchain.
And how does the Blockchain work?
What even is a block shape?
Well, pause here and tell you a little more about that.
So what even is a Blockchain, right?
Our clients?
That application's actually talking to a Blockchain right here, so it's actually a separate network, okay, and a Blockchain is a peer to peer network of nodes that I'll talk to one another.
It's a distributed network, so there's actually different Computers are machines that talk to one another, and we can connect to an individual node on the block chain in order to use it.
That's what our Web applications doing here, so all of the nose on the network participate in running the network.
They all contain a copy of the code on the block chain and all of the data on the block chain and all of the data on the bloc chance contained in bundles of records called blocks which are chained together to make up the block chain and all of the nose on the network also participate in ensuring that the date on the block chain the public ledger is secure and unchangeable.
And that's what makes the block shame so powerful.
And so what about the code on the block chain?
Well, all the code on the block chain is contained in smart contracts.
So smart contracts are basically just programs that run on the block chain, and they're gonna be the building blocks of blocking applications.
And that's why we're gonna build our to do list out.
We're gonna write a smart contract that will contain all the tasks and a to do list and allow us to, you know, add new ones and complete them and things like that.
So smart contracts were written in a programming language called solidity, and all the code in the smart contract is immutable, Which that means is unchangeable.
Whenever we deployed to the block shame we won't be ableto update that code.
That's important, understand?
Because that's what makes the Blockchain so secure.
Whenever we put code in the Blockchain, we know we can trust it.
At that point, it's called trust Lis for a reason.
Whenever it's all in the Blockchain, we know that no one will change it.
And therefore, we know that to do list will behave the same way every time.
And sometimes I actually think about smart contracts.
Kind of like micro service is on the web.
They're on the block chain and they read and write data from the block chain and they do stuff with it, you know, they execute business logic.
All right, Now go back to the drawing board and kind of give you a refresher about how our applications gonna work again.
We're gonna connect to the application with a Web browser and we're gonna build a client side application in h e mails CSS and JavaScript and that client applications going talk directly to the Blockchain.
And that's why we're gonna put our smart contract will create a to do list within Ethereum Smart contract written solidity and will compile it and deployed to the Blockchain.
It will also connect to the Blockchain network with our personal account within Ethereum wallet in our browser, and I'll show you how to get that set up in this tutorial as well.
So now you see now block Shame, works and how we can build our to do list application on the block chain.
So let's jump in to start programming.
Here's a preview of the application that will develop in this tutorial.
This will be a to do list power by an Ethereum smart contract or will be ableto add new to do items and we'll be able to check items off of the to do list.
And before you get started, you need to make sure you have no Js already installed on your computer.
You can see if you have no installed by going to your terminal and having no dash V you can install know with the package manager like home brew or you condone it directly from the Know Js website.
The first item in the Blockchain developer toolkit is a personal Blockchain.
We're going to use ganache as our personal Blockchain.
For this tutorial, you could head over to truffle framework dot com for a slash Kanosh, download it and quit this download link and whatever you've downloaded, it makes you install it and when you open it, you've got a local Blockchain running.
So what is ganache.
You know what is a personal Blockchain?
Well, a personal Blockchain is like a real Blockchain network.
You know that's connected to the public or anyone can connect to it.
But it runs on our computer.
It's, you know, a closed network and ganache, basically, you know, is a process that runs on a computer that spins up this block chain and runs on a server.
So we can use this to develop smart contracts.
We can run tests against ST Week or on scripts against the network develop applications.
Actually, talk to this block chain is really helpful, and it's an invaluable tool.
And the Blockchain developer toolkit.
So, um, if you opened a Nagy, you'll see 10 accounts listed here.
These are the addresses to each account on the side, and you'll see you know, these balances, you'll see 100 ether.
And this is the Ethereum Cryptocurrency that each account has and is required to, you know, pay gas fees and the network and stuff like that.
All right, so that's an overview of the ganache personal Blockchain network, and we're gonna leave ganache here set up in our project because we're going to need it running in order to develop our project.
The next dependency is the trouble framework.
We're going to use the truffle framework to develop a theory.
Um, smart contracts with the solidity programming language.
You could install truffle by going to your terminal and typing in P M install dash G truffle at 50.2.
And it's important that you use this exact version in order to follow along with this tutorial.
So truffle is a suite of tools that allows us to develop smart contracts.
Right.
Tests against smart contracts deploys mark contracts to the Blockchain.
It gives his development console, and it also allows us to develop client side applications inside of our project.
So it does a lot, and I'm gonna show off all those features in this tutorial.
The next dependency is the meta mask extension for Google Chrome.
Remember that the Ethereum Blockchain is a network and we need a special browser extension in order to connect to that network.
And that's where mega mass comes into play.
Metal mask will allow us to connect to the block chain with our personal account and actually interact with the smart contract that will develop in this tutorial you could install madam asked by going to the Google Chrome Web store and searching for meta mask and clicking install.
And once you've installed it, just make sure that you enable it inside of your chrome extensions like this.
You could also see the little Fox icon in your extensions tab.
Now let's create the project.
I'll start by quitting a directory for a project like this E th just stands for theory.
Um, so I'll enter into that newly created directory, and now, once we're inside of here will actually create a new truffle project.
But before we do that, I just want to make sure that you're using the correct truffle version.
You can check your truffle version like this truffle version, and you want to ensure that your version is the same as mine, which is 5.0 dot two.
So it's not.
Go ahead and check out the dependency section is video to see how to install the specific version of truffle.
So now we'll initialize Any trouble project like this will just say truffle, innit?
All right.
And now we've successfully unboxing your trouble project, and now I'm gonna actually create a package dot Jason file in order to, you know, pull in some development dependencies for the project.
Those a touch package that Jason.
All right.
And now I'm gonna open this product inside of sublime text.
That's the text editor I'm using.
So let's go to the package of Jason File.
We can actually see the product director over here and could see the newly created package at Jason File.
And it's empty.
I'm gonna paste in the contents of this file that will use for this tutorial.
And you can actually get this package that Jason filed by cloning this repositories on the get, huh?
Blink and the description down below.
All right, so here's the dependencies for the project was gonna go and say this.
Like I said, I just paid to these in here, and you can see we have a few dependencies like the bootstrap framework will use this for building out.
Um, the clients at application.
We got some dependencies for testing this mark on tracks a server for running the clients at application, and you know, some other truffle specific development dependencies.
And I've locked these versions so that you can keep following this tutorial in the future.
So make sure that all these versions match what I have here.
So now I'm actually going to install the dependencies for the project like this sort of say in P M Install.
All right, it's another installed.
Now let's go back and you're a project and actually create the smart contract file that will use to build a to do list.
We'll do that by going to the contracts directory, and you can see there's a smart contract that exists inside of here.
This is actually a smart contract that comes bundled with truffle that manages migrations to the network, and I'll explain that here a little bit and now create a new file inside this directory called to Do List that soul so you can see that do list is capitalized to do list, and it's in the same project directory here.
So now it's actually create the smart contract that will manage that to do list for the application.
The first thing you want to do inside this file is actually declare their version of the solidity.
Programming lingers that we want to use.
We'll do that like this was a problema solidity.
Who's a carrot?
Most say version 0.5 dot zero, and we'll end this line with a cynical in.
All right now, the next thing we do is actually declare the smart contract.
Do that with the contract.
Keyword is a contract, and we want to call this car tracked to do list to the same name of the file said to do list.
And we followed that with some opening and closing curly braces and inside of years were actually write all of the code for the smart contract.