Python Web3 Development #2 - Setup & Understanding The Framework & Security
Key Takeaways
This video series covers Python Web3 development using the Cartesi library, including setting up and understanding the framework and security. It demonstrates how to create web3 applications using Python, with a focus on decentralized application development, blockchain development, and security.
Full Transcript
hello everybody and welcome to part two of this series where I'll be showing you how to set up your development environment for writing decentralized applications in Python using cartez now the setup here is a little bit in depth just because of the inherent complexity of writing smart contracts in well any language fortunately once we get it set up it's very easy to work with it and to do our development so please bear with me in this video and make sure you go through the steps one by one don't skip anything thing I promise you will thank me later now the setup is going to be different depending on the operating system that you're on so on Windows it's a bit different Linux Mac Etc fortunately caresia has some really great documentation and I'll link three guides in the description that I highly recommend you download right now first one is for Windows next is Linux and last is Mac now I'll be kind of running through these and sharing with you the differences between Windows Linux Mac Etc obviously it's impossible for me to show you the in-depth setup for all of them as I don't have three operating systems running on my computer I just have one which is Windows I'll make everything very clear but I highly recommend that you actually attempt to go through this document on your own and you can refer this video if you have any challenges or questions about the commands that are being ran so again go down to the description there's three guides one for Windows one for Linux and one for mac and they will show you the setup steps for running your first decentralized application which is already built for you you using cartei that's going to be the goal of this video get a demo application running on our computer get the setup fully finished and configured and then I'm going to start explaining to you how caresia Works a little bit more in depth and giving you some insight into what it is we're actually going to be doing as we start building our decentralized application now another note if you have any issues with this installation please join the Discord server that I'll link below you can actually contact the cartei team directly and they can help you one-on-one with any issue that you have now I have Windows Linux and Mac here I am running Windows on my computer now the prerequisites for setting up the environment are going to be the same for all of our operating systems so you can see that generally what we need is Python 3 node.js yarn and Docker desktop if we go over here to Linux same thing Mac same thing now installing these requirements are a little bit different just based on the way the operating systems function so on Linux and Mac you're actually running in a Unix environment or a Unix shell that means you have access to some specific commands and some operating system features you don't have by default on windows so on Windows what we first need to do is set up our WSL environment in this case WSL 2 which is Windows subsystem for Linux now this is a Linux like environment that will align with the carteia ecosystem which will allow us to do all of our development now for a lot of you you may actually be on Mac or Linux if that's the case you don't need to do that because you already have the correct shell and the correct operating system system so if you are on Windows what you need to do is start by installing and configuring Docker as well as wsl2 so it goes through here right manual installation of wsl2 you need to open Powershell as an administrator run this specific command now for all these commands again just download the guide from the description and you can copy them directly in you then need to switch from wsl1 to wsl2 if you don't already have that installed by running this command restart your computer and after restarting you're going to download the kernel package for wsl2 you're then going to set wsl2 as your default installation and then what you can do is open the Microsoft Store and download the current version of auntu Linux so if you go to store here and you type in the search bar if Microsoft will ever load for me here a bun to as you can see I already have it typed in you can actually download an installation so you can see I have one owned right here I don't know exactly what version this is but this installs this abunto operating system in wsl2 so now I have a Linux like environment on my Windows computer so that's the first step if you are on Windows then what you're going to need to do is install Docker desktop now this is going to be the same if you are on Linux or if you are on Mac okay you need Docker desktop you can see on Mac there's different installations for the silicone chip so the M1 M2 Etc or for the Intel chip now after we install Docker desktop if we are on Windows what we're going to do is just open it up now this will be the same on any operating system so whether you're on Mac Linux whatever you want to open Docker desktop so it's running it needs to be running in the background for everything to work if you are on Windows you going to click on settings and you're going to go to General and where it says use the wsl2 based engine you're just going to make sure that's checked okay so make sure you have that selected that's going to allow you to access the docker command within your wsl2 installation okay so hopefully at this point you have WSL installed and you have the correct operating system once you do that a lot of the commands now are going to be similar for uh both Linux Mac Etc next thing you need is node.js and mpm now you're going to need to do this installation if you're on windows inside of wsl2 so open the auntu terminal now the way you can do that is you can just type A buntu like this okay so it's going to actually show you kind of this virtual operating system system and it just will open up okay so that's if you're on uh what do you call this windows again if you're on Mac or Linux you just open any terminal environment and you're kind of already set up now what we're going to do is we're going to install nodejs and mpm I've already ran through these installs you're just going to copy these commands Okay so you're going to install NVM You're Going To Source The Bash RC you're going to install node and you're going to Alias NVM with node perfect okay if we go to Linux same thing exact same commands Okay we go to Mac a little bit different because we're going to be using Brew to make sure we have nodejs installed great next installation step is python okay so again same thing we want to make sure we're in the auntu terminal everything we do from this point forward we're doing inside of WSL don't do this in your standard kind of Linux uh or sorry standard Windows uh command prompt Powershell whatever otherwise it's not going to work okay so now what we want to do is install python so same thing we're going to pseudo AP up update pseudo APD install Python 3 that's going to install it inside of our Linux environment if we're on Windows if we're on Linux we're going to update and install Python 3 I assume most of you probably already have Python 3 but if you don't you're going to install it right let me just zoom in a bit here if we are on Mac to install python a little bit different here okay Brew install Python 3 okay going back next thing we want to do is install yarn so again same thing make sure you're in the ABN of terminal we're going to add the yarn AP repository and we're going to install yarn okay next install yarn same commands here on Linux and on uh what do you call it Mac here fortunately you can just use brew and just say Brew install yarn at this point you should now have a wsnl environment if you are on Windows you should have Python 3 installed in that environment you should have nodejs installed and you should have yarn you also should have Docker desktop Docker desktop is running on your windows instance okay so we installed Docker desktop for Windows we tick that box we're good on Linux same thing okay Python 3 node yarn Docker desktop installed on Linux Mac OS exact same thing if we have all those three dependencies we are now ready to start running through the steps that are actually going to be the same for all the operating systems okay or at least very very similar so keep this reference open because again you can always go back to it and you can copy the commands now as we see here on Windows very important for a seamless development flow it is recommended to not execute Docker commands with Powershell or the WSL terminal instead open the auntu distribution that you have installed and perform all coding and command execution within that Linux environment so I've been saying that a bunch of times just make sure you do this because that's a mistake that I had plenty of times which is actually why they put it in this documentation okay so what we're going to be doing here is we are going to create a simple appap we're going to run a backend that will interact with the cartez rollups framework which we're going to talk about later and we are going going to use a basic kind of front end or console environment to send some requests just so you can see how we can send data to a decentralized application ridden in Python so I'm going to put this on the left hand side of my screen or sorry on the right hand side of my screen and on the left side I'm going to have my auntu terminal okay I've got auntu open up here I'm just going to open another instance of this and actually to do that I'm just going to type a buntu like that and I'm just going to combine these well let me combine them no it won't okay but I just have two of them open because we're going to need two of them at some point again if you're on Mac or Linux just use your normal terminal environment okay so I'm going to clear the screen with clear and the first thing we're going to do here is we are going to launch Docker desktop to start the engine and run the command to check if this is working so we're going to type Docker build X LS like that now we're going to see that we might get this protocol thing uh don't worry about that what we're looking for here is that we have the Linux risk 64 installed inside of this you can see that I have Linux risk 64 if you don't see that so if you don't see it right what you're going to do is run this command here pseudo APD install Q menu user static don't worry about what that's really doing but we just need this architecture installed in our kind of Linux distribution so again if we go back here now we're on Linux okay same thing exact same command we want to make sure we see that in our terminal like that okay now we want to make sure that we have git installed so you can see I have git installed here if you don't have git you're going to install git on your machine you can click on this link link right here again in Windows same thing Linux Mac and install G now what we are going to do is clone a repository that we are going to use for this tutorial that has some starting code for us now the link that's here is actually not correct I'm going to pop it up here and I'll will put it in the description this is the caresi rollups example repository so it says rollups example right here and if we click on code we can copy that again don't worry I'm going to put that in the description so you guys can just copy it from the description okay but it's get up.com cartesi robs examples. so what we're going to do is we're first going to make sure we're in the folder that we want this to exist in so you see right here like I'm in just my home folder so if I type print working directory I get slome SL Tim now if I want to be in a folder that that I'm able to access from Windows because I'm in WSL what I'm going to do here is uh let me get out of this cd. dot CD do Dot and LS now notice here we got a bunch of stuff appearing what we actually want to CD into here is Mount now this is only if you're on Windows and in WSL if you're in a normal terminal environment you can just save this wherever you want but I'm trying to show you on Windows how you'll be able to access these files so I CD into Mount then I can type out s and notice that I have all my drives so I have CF so I'm going to CD into my C drive notice LS I got a bunch of files here okay I'm going to CD into users CD into Tim CD into desktop and now I'm on my Windows desktop which is mounted to my Linux environment so this just allows me to share files between my auntu installation and my Windows installation which is my host operating system okay now what I'm going to do is just make a directory or CD into a directory where I want to clone so I actually have a directory called cartez on my desktop so I've cded into there now that I'm inside this environment I'm going to clone the repository so I think I can actually just paste this command or actually no that's just the URL and I'm going to type get clone and I'm going to clone this repo okay so that's going to take a second and I'm going to clone this into cartei and now that we have this cloned we'll actually be able to work with this and start setting everything on again on Mac or Linux just clone the repo wherever you want we're now going to CD into that repo so the repo is rollups examples and if I LS you see that we get a bunch of stuff now to make this a little bit easier for us to see we can open up a code editor like Visual Studio code and we can view all of the different code inside of our folder so you see I have rollups example okay and I've got a bunch of folders inside of here that I can start working with erc20 uh Eco rust whatever uh or sorry not Eco echo echo rust Echo python Etc and these are all examples of how to write carteia code feel free to have a look through it you can read the readmes and stuff but I'm going to give you the in-depth explanation okay so now let's open this back up we've cloned the repository and what we want to do next is we want to CD into the echo python repository which contains a very simple decentralized app in Python that we're going to work with so CD into Echo Python and then clear now I want to make it very clear that all the commands I'm running again are from my wsl2 abun to installation if you do this from Powershell or from a terminal if you're on Windows it will break everything make sure you are in your Linux environment for those of you who get on macro Linux don't worry about that okay now that we're inside of echo python we can go to vs code and we can have a look at our Echo Python and if we go to echo. py which is our main python file here we can quickly run through some of the code now it's going to seem a little bit confusing but essentially the way that all of this is going to work is there is a bunch of code that we didn't write this is stuff provided by cartei inside of something known as the cartei machine the cartei machine is going to take any data that is submitted on the blockchain it's going to do something known as a rollup and it's going to send a bunch of requests to our backend now this makes our backend act very similar to a web server it's not quite like that but it's very similar in terms of how we receive and send data so we have our main Loop down here now we're going to run this in a second but essentially what we're doing is we're waiting to receive some kind of request now the request can be one of two things it can be an inspect request or an advanced request inspect simply acts kind of like a get request where we're receiving some kind of request to return some data so someone is saying hey I just want to inspect the state of this machine I want to see for example what this variable is I want to see what players have what balance whatever right whatever the application is doing inspecting allows us to view the state Advanced state is something like a post request or a put request could be a delete request as well anything that might actually modify the state of the machine this comes through as a transaction and what we're able to do is kind of handle this Advanced State request and respond to it by doing something specific we're going to get into this more and more but the way that our cartei machine and really our whole backend which is what this is right here think of this kind of like your kind of pseudo smart contract is it acts as a state machine and this state is held however you want could be in a variable could be on the file system could be in a database whatever you want to do okay the state is held and any time you get a request which is an advanced State you can modify the state or respond to that when you get an inspect request you're going to return some data which is some information about the state of the machine okay and this is a little bit in terms of how carteia works with security since we have these discrete States we're actually able to reproduce these states and to verify that states are correct correct we'll talk about that later on but that was kind of a very quick primer Okay so we've got this back end which is in echo. piy now there's a bunch of other files here we don't need to look at those right now what we're going to do is go back and we're going to start trying to kind of run all of this code so let's open up this okay so there's some explanation here where it says Advance inspect Etc and these are just regular HTTP requests that we're responding to in Python now what we need to do is run the environment now since we're running kind of a blockchain application well the first thing we need is some kind of blockchain network now we're not going to run this on a main Network like ethereum because we're just doing development instead what we're going to do is run this on kind of a test Network the test network is just going to be running locally on our computer once we run the test Network we are then going to run our backend and our backend is interacting with the test blockchain network using the caresia machine so the first thing we need to do from this Echo python directory is run this command so let's copy it in actually I'll just type it Docker build X bake D- load okay from the echo python directory we're going to go ahead and run this now this is going to build the entire Docker image and this is going to get everything set up so we can start running our test Network now the way that things will work is when we run our test Network all of the components that caresia requires to kind of work will automatically be deployed on chain there's a bunch of smart contracts that are kind of running in the background that we don't really need to know a lot about that are allowing us to use this framework so that we can write our kind of dap logic in a normal programming language so what we just did here is we just built the whole image for you it might take a little bit longer I believe I have some kind of cach here in my system anyways we've built that now what we're going to do is spin up what's known as our node okay this is the caresan node which is running all of the again kind of onchain components that we require for our code to work now it's also going to be running it's going to be running a few things okay it's not just that it's running some other stuff for the cartez rups framework I don't want to uh mislead you with my vocabulary but it's just running everything that we need for development okay that that's the way to think of it so I'm going to right click here and just copy in this command and just make sure that you kind of fix all the line breaks here because for example you could see I had this down on a separate line and that would break okay so we're Docker compose Docker compose Docker over ride Docker compose a bunch of commands you don't need to understand go ahead and hit enter and you're going to see that it spins up a bunch of stuff and we get some output kind of popping out on the screen okay what we're viewing right here is our node which is deploying a bunch of stuff that caresia needs and running U kind of a blockchain network for us locally on our computer okay amazing so that is step one we've got this running and we're always going to need this running when we do our development because this is the development server that we're working with right write the development note now that we have this running we can kind of leave that in the background we don't really need to worry about it we're going to open up another terminal now this terminal is where we're going to run the back end this is the one that we can start we can stop and this is where we're really going to do quite a bit of our development so what we need to do is get back into the same directory we were in before so I'm just going to CD into it so CD into Mount C drive users Tim desktop cartei and then what is this rollups examples LS CD Echo python okay I'm inside of my uh directory now that I'm inside of the directory where this code exists again same place that we were here in here what we're going to do is start running our back end so first thing we're going to do is create a virtual environment to install all of the Python dependencies because again we're running this in Python just like we would run any python app so we're going to type Python 3 hypen M vv. venv this is just our virtual environment that we're creating which will store our dependencies you don't always need to do this just the first time you spin up an example so this going to take a second I'll be back when it's finished all right so now that we have created this virtual environment if I type LS you should see that we have a ven V or it's hidden because we have the dot folder but anyways there is a DOT venv directory here probably see it in vs code but that's okay and what we're going to do is just activate this environment so we're going to type Dot and then dot venv SL bin slash activate like that now that should activate the virtual environment and you should see this appearing you're probably not going to see Bass by the way this is just some kind of thing I have in my WSL installation don't worry about that but we have vvy now we're going to install the requirements for python so we can type pip install requirements.txt I'm going to make this pip three and we're going to install all of the ones that we need again this will take a second once it's finished I will be right back all right so all of that is installed and now that we have that installed we're on to actually one of the last steps which is running our back end so we're just going to copy this Command right here and what this will do is simply run this echo. py file but we're just declaring a environment variable that's going to be read by that file okay so that's why we have this text beforehand don't worry about it too much but we're saying the roll up HTTP server URL is equal to Local Host Port 54 this is just the port that this needs to be running on for everything to communicate correctly and then we're running the python echo. file by putting this beforehand again is just declaring an environment variable which will be read by this file so we're going to go ahead and hit enter and you will see here that some stuff starts coming in now you can see that I'm getting kind of some requests and some data that you're not going to see it's just CU I have some stuff cached on my system don't worry about it too much for right now but in your case you should get some output that kind of looks like this HTTP rollup URL sending finish sending finish no pending rollup whatever right you kind of see it's appearing here again don't worry about the stuff that's cached it's just because I had uh some stuff running on my system earlier when I I was testing this okay so now what we have is following we have our node which is running and we have our back end the backend is what's going to handle all of the logic and the node is what's going to take care of essentially forwarding that logic logging it and making sure everything is secure what we need to do now is need to actually interact with our smart contract um application right or with our decentralized application so the way we can do that is we can send one of two types of requests to our back end now let's have a look at these again from our code so you can see that we have an advance and an inspect now an inspect is just querying the state okay it actually doesn't require that we go through the blockchain to do an inspect um it's kind of just like viewing event data or viewing logs of a normal smart contract that's kind of what an inspector request is doing we then have advance and Advance is actually advancing the state and anytime we change the state of our machine this needs to be verified and secure so this actually requires a transaction on the blockchain okay now let me show you how we interact with this so what I can actually do is from any terminal doesn't have to be my WSL terminal I can send a kind of Inspector advaned request to my application so I'm going to CD into the robs examples and CD into Echo python now what actually sorry we're not going to go into Echo python we're going to go into the front-end console the front end console is just a little tool that's built by caresi which allows us to interact with our dap now remember in the previous video I showed you a front end I built in react that was my front-end console right that was how I was interacting with the application you can write your own interacting code or you can just use this one from caresan so I'm going to put this on the left side of my screen here let me just make this so we can see it and we're going to start interacting with the back end now to do that we go into the front end console and we need to install our dependencies this is a normal kind of javascrip package so we're going to type yarn okay just going to install everything that we need inside of the front end console once that's done I'll be right back okay installation is done we are now going to build the application by typing yarn build okay and now that that is built we are going to take this Command right here and what this is going to do is send an input to our back end so I'm going to paste this here I'm going to close this guide now let's open up our back end which is this now I was just testing this a second ago so you can see actually have some output anyways what we typed is yarn input send and then we're sending a payload which is just some text now what our backend currently does and I mean we can read the code if we want to is it simply creates something known as a notice and a notice contains the exact same data that we sent to the application hence the name Echo python we're going to talk about notices reports and vouchers which are important in one second but for now I just want to make sure that this is working so what we do from the front end console is the start input send we send a payload and this is going to essentially trigger the Advan State type of request okay so what I'm going to do is hit enter and when I do that quite quickly once this actually sends you're going to see in my back end that I will actually get a transaction coming through so it says sending hello world this is my first St and then it will say the inputs added now you can see here it says receive the advanced request data here's the metadata here's the message sender and then we have a payload now this is hexadecimal encoded so we do have to decode it if we want to be able to read it that's fine don't worry about that right now we'll look at that later the point is that we sent some data it was received by our backend and if we actually go over here to our host or to our node uh you will will have seen if you look at all of the uh kind of data going on here that a transaction went through so it was sent using the blockchain and it was received here in our back end so our back end is is able to respond to that and do whatever it needs to do again being sent through the blockchain network I know this is a little bit confusing but if all of this works what I just showed you you are set up you are ready to go and we have everything that we need now the last thing I can quickly show you before I start getting into some explanations of what the heck it is that we actually just did is the following so what happens is that our backend so if we go here yeah back end is able to generate a few different types of outputs right if you're familiar with contract development you know that whenever you have a transaction you can't actually return data from that there's no way to return information back to the center instead what you can do is you can emit events right and these events are kind of like logs of what's occurred now in cesi we have three types of things that we can kind of emit or create that can give the user some information about what happened in the back end we can create something known as a notice now a notice is something that's verifiable on the blockchain network they pretty much notify all of the users who are interested in the state of the uh application that something occurred so a notice could be hey this user deposited some money this user withdrew some money whatever something that everyone would care about that we'd actually want to be verifiable that's a notice and you actually saw that what happened was when we sent an advanced request here we created a new notice now these notices we can view we can query them we can have a look at them now as well as notices we can create a report now a report is what's right here and a report is essentially some kind of log some information giving you typically debugging information or it could be some information about the state of the machine something that we don't need to really have stored on the blockchain that doesn't need to be verifiable and that is essentially just telling you what happened in the transaction that you sent or in the request that you sent to the backend so it could be hey there was some issue with what you did so we generate a report kind of like an error message that you might get from a regular smart contract we could also generate a report and say hey the data that you wanted it's stored inside of this report go ahead and have a look at it okay those are the two types of outputs notice and report and we have something known as a voucher which allows you to interact with other smart contracts which we'll talk about later on anyways what happened was is we generated a notice now these notices we can view so if we go back here you can see that we have a command yarn start notice list if I run this what it will do is it will list out all of the notices that have been generated by my backend so we'll give this a second here and we should see that we get some kind of output and it shares with us a list of all of the notices and you can see that we have these notices so we sent a payload right and said hello world this is my first app and you can see that we're viewing it right here now there's a bunch of other notices because again I was telling you I was messing with this later we have notices like accepting a challenge um what do you call it creating challenges remember from the first video these were some of the inputs that we were sending so there's a whole log of them and we can see everything that's occurred perfect so that is kind of the basic idea here behind the setup I'm going to get more into the explanations you understand how this works but for now we can clear this we can close that up and we can start tearing down our development environment now when we tear down our development environment there's a few things that we need to do so first of all we can go to the back end and we can simply just shut the back end down by hitting contrl C Okay contrl C close it down that's fine if we were to start running this again in our node were still to be up here what would happen is it would actually resend all of the different inputs that are stored on the blockchain because they're securely logged and our back end would be in the same state it was when we shut it down so what that actually means is that we can have as many versions of the back end as we want running around the world decentralized as many as we want to and they can all be in the exact same state by viewing the information that secure that's stored on the blockchain but all the computations are done offchain which is what's giving us that kind of performance benefit anyways we shut down the back end and we're going to shut down our node by just hitting contrl C now it's going to stop a bunch of containers here but we're not quite done I'm just going to close this we have this command here and what this command will do is actually tear down the environment for us and remove logs of what's currently stored in this node so that if we start it up again we're kind of starting fresh so it's a good thing to know you always want to be running this command when you're doing like a new cycle of development so you don't have all of these inputs that you did previously logged on the blockchain so we're just going to copy this command in now again there's some issues with the line breaks so I'm just going to fix those there this is again deleting some of the containers volumes Etc so you can see all these volumes are getting removed which is what we want and now we have torn down our environment amazing there you go that is how you set up your environment for writing decentralized applications in Python again please refer to these guides I recommend you download them and keep them because they're helpful to share with you the commands you need to copy and paste if we're getting started again we're just going to start from running our backend so we're literally just going to run the backend we're going to run our node as well okay so make sure that's up and running and then we can just use the front end console and we can interact with our application okay so now that all of that is done let me open up a few pieces of documentation here and I'll start sharing with you exactly what it is we just did and kind of how all of this stuff works so here is a basic kind of overview of the architecture of how this works we have a front end we have some chain this chain is just a blockchain network right something like ethereum we then have our cartei rollups framework and what that consists of is a cartez machine which has the HTTP rollup server and our back end now the cartez machine is a virtual machine that runs on a Linux risk 5 architecture now this machine is very important to the security of cesia which we'll get into later but for now what I want you to understand is that what we focus on as the developer here is the front end and the back end just like we would in a traditional web application the front end is what's interacting with the chain or directly with our Cartesian machine what it can do is it can send transactions or Advance kind of state requests which are aiming to change the state of the cartisian machine this is something that wants to be verifiable that we have to pay for right we got to pay our gas submit that to the network even though it will still be a lot cheaper and then we have inspect which again is kind of like a get request I just want to see what's going on I want to inspect this State I don't need to go through the evm chain to do that I can go directly to the Cartesian machine okay so this are the two types of things we can do right advance and inspect and we're going to look at these more in depth later on inside the caresia machine we have the rollup server and we have the backend now what the rollup server is doing is really facilitating the communication between our back end and our evm chain and it's doing quite a few other things as well but what's important for us to understand is that we don't really even need to worry about what this is doing we just need to focus on our back end so we need to respond to the advance and the inspect State requests but that's all we need to do everything else from the rollups the Securities the disputes Etc will be handled by the machine the rollups framework and the rollups server but what you noticed is that we were receiving requests in our code as just normal HTTP requests right just normal requests and we were actually creating requests that were posting or creating new notices reports vouches Etc so we're able to work in a very familiar environment using an HTTP API which we'll talk about later on from our back end which interacts with the RO up server okay so if we look at our things right we have CES rollups a set of onchain and offchain components that Implement an optimistic rollup solution and provide the general framework for building daps Cartesian machine a virtual machine that runs an entire Linux operating system in which the daps backend is executed so anything that can run inside the cesan machine we can write so we can write in multiple languages one language we can use all kinds of stuff we can use the file system math tools Etc because we can write the whole back end inside of this VM we then have the DAP backend this is the application State and verifiable logic which corresponds to the DAP smart contract the backend runs inside the cartes machine as a regular Linux application front end the application's user facing interface such as web app that is the most basic part now there's a bunch more stuff here you guys can go ahead and read through this just by looking up cartei we have the cartez machine though which I will quickly touch on so Central to cartez rups is the cartez machine now what this does code execution abstraction of infrastructure flexibility and scalability the important stuff here is the following the cartisian machine contains discrete States now the way this kind of works that we run in something known as a risk five architecture this architecture is important and this is essentially the instructions that are being executed by our code now it's pretty complicated but what happens is anytime we receive some kind of request so if we go back to our code here what we do is we execute some instructions on the CPU or inside of our virtual machine okay now these instructions we don't really know exactly what they are as you know normal python developers that don't work in assembly and low-level languages but when I do things like create a variable or send a request or log some information these are instructions okay they're executed now these instructions are discret it means every single time we receive some kind of input or some spe or whatever the instructions we're going to do are going to be the exact same so that means that if we receive some kind of state we know based on what we receive exactly what the next state of the machine should be and we know what the current state of the machine should be based on all of the previous States I'm not sure if this is making sense but we start in some state zero we know what that state is and it's verifiable what the state is okay we receive some kind of input that advances us to another state only that input would have advanced us to that next state now since this kind of makes our backend act like a state machine we can actually verify it any point in time if the states being produced by the back end are valid based on the inputs that were sent and what we do is we store all of the inputs on the blockchain so those are secure and then we can verify that what's being produced by our different machines which are running offchain is correct that is a very very very high level overview of how this works but if we read through here stay TR transitions happen deterministically as I was saying any state transitioning from one state to another state is deterministic it will always be the same now as the emulator processes the risk five instructions changing the state of the system to a new discrete State determinism given the same initial State and input caresan machine will always produce the same output and final state to ensure that the offchain computations can be verified and agreed upon to engage with cartes rups either interact by sending requests or accessing generated outputs now you can read through more of this if you want but the general idea is Cartesian machine acts as a state machine its state is always verifiable because it's discreet and it is deterministic that means if we advance the state by some input any other caresan machine should have the exact same state if it doesn't that means it's a malicious actor it's doing something incorrect and using blockchain technology and consensus mechanisms we can actually say hey what was produced by this caresi machine or someone who is controlling this some node on the network was invalid kind of similar to how it works in things like ethereum or any other blockchain network where if you get some kind of output that is not verifiable that's not correct you reject it right you don't accept that and there's some kind of ways of of handling that and um some validators and stuff like that we don't need to get into all of it but the point is to understand caresan machine State machine can advance its machine discreetly and deterministically which allows us at any point in time to understand if it is valid the state or not valid it also means we can have as many cartisian machines running as we want these are all nodes sitting on our Network and they can always have the exact same state because they're simply reading the inputs which are verified on the blockchain network which is layer one all right so now that we understand a little bit about that let's go over here and talk about the backend API which is most prevalent to us as the developer so what happens in the backend we have the rollups framework which I told you is sitting inside of um our caresan machine and we have our back end again which is running inside of this Lin VM which is the cartei machine what the backend will do is it will consistently send a finish request to the cartez rups framework which just working on a simple HTTP API and when this finished request is sent it will essentially set their idle and it will wait for a new request or a new state inspect whatever to be sent now once we get one of these the backend can perform all of its logic it can store stuff it can delete stuff it can do whatever it needs to do and it can generate outputs that tell whoever is using this decentralized application what's going on the three types of outputs it can create are a voucher a notice and a report we've already touched a bit on notice and reports vouer will touch on in a second okay so you can see here advaned state provides an input to be processed by the back end in order to advance the application State this is what needs to be verified on the blockchain and submitt on the blockchain inspect state does not need to be handled on the blockchain and it submits a query about the application's current state when running inside a ctes machine its operation is guaranteed to leave leave the state unchanged okay we cannot change the state using an inspect request which is why it's fine for us to just submit this directly to the node and skip over the blockchain which makes things a lot lot faster for inspect State requests this input data contains only a payload all right now let's go through and talk about vouchers notices and reports quickly and then we can wrap up this video all right voucher so a vouer is a combination of a Target address and a payload in bytes it is used by the offchain machine to respond and interact with layer one contracts so a question you might be asking is okay well if I'm running this caresia machine offchain how do I do things like redeem an erc20 token how do I interact with an nft how do I interact with other smart contracts or a defi protocol well you do that using a voucher so what you can do is you can submit a voucher you can create one from your dap and that voucher can then be executed on chain now there's some smart contracts written by carteia that do this but you can see that vouches can only be executed when the epoch in which they're contained in is finalized now we're going to go back to that and talk about in a second but vultures are your way of essentially transferring assets and interacting with onchain components next we have notices now a notice is an arbitrary payload inites that is submitted by the offchain machine for informational purposes similar to vouchers when the epoch containing a notice is finalized a proof will be produced so the validity of the no content can be verified on Chain by any interested party now a report is an application log or piece of diagnos information as I talked about like a notice represented by arbitrary payloads report is never associated with a proof and is thus not suitable for trustless interactions so you don't use a report to verify something is correct or what not you just use it for Diagnostic or logging piece of information lastly we have a portal as the name suggests you are using a uh sorry a portal teleports assets from the ethereum blockchain to daps running on caresi rups so let's say I want to send some money to my decentralized application well it's not running on ethereum it is running running on layer two so I need to send it through a portal that portal will then inform my decentralized application hey you received some money and then you can handle the money however you would in a normal decentralized application okay so that's kind of how a portal works and there's portals for sending regular ethereum erc20 erc721 and these other types of erc20 tokens okay now let's quickly go up here and we can talk about nodes and EPO so we have nodes just like we have in any type of blockchain network and these nodes are the decentralized component right we have multiple people anyone can run a node if they want anyone can be a validator anyone can be a reader node in this case or a user now when we have these normal nodes user or reader nodes these are simply just advancing the state of the offchain machine uh and making sure that anyone can publicly see what the state of the machine is so for us to be able to know what the state of our application is we need to have some nodes running just like if we want to know what the state of the ethereum blockchain network is there needs to be some nodes that we can access on the ethereum blockchain that tell us the state exact same thing here except with the offchain component next we have validator nodes now similar to how validators work on ethereum or miners work on ethereum these are going to make sure that everything is honest that there's no uh kind of malicious activity going on and there is actually some kind of incentive mechanism that goes on here in terms of how validators get paid out how the gas fee goes there Etc there's some more complexities in this we're not going to get into this right now we start talking about deployment we can dive into it more but understand that there is an incentive mechanism using caresia tokens for validator notes and then the reader nodes again they're just making sure that everything is available now lastly we have Epoch now essentially what happens is all these validator nodes at certain points in time are going to checkpoint the state of the offchain machine on the blockchain so we know okay at this point in time everything was valid everything was Secure however they don't do this until they reach the end of an OT now an Epoch will contain a batch of inputs that follow the same cycle so you're not checkpointing every single state update you're doing it more efficiently now in order to end an Epoch all of the validators need to reach a consensus about the state of the machine after processing all of the batched inputs now once that consensus is reached they're going to essentially take all of the vouchers notices Etc and these are going to be considered final because they are checkpointed on the uh what do you call it on the blockchain network now during this Con ensus period is when disputes can occur so for example if a validator were to put something onto the network or say oh this is the state of the machine but all the other validator say no that's not the state of the machine like that that's not how it works based on the decentralized and consensus mechanism then they would reject the state coming from the dishonest validator I'm hoping that makes a little bit of sense but there is a dispute mechanism so if any validator sees that a uh state is incorrect coming from another validator they can dispute that state there is a process where they go through some kind of dispute game I'm not going to talk about that in this video and that is essentially the security mechanism now I will leave all of these links in the description so you guys can read them on your own if you are interested so that was the General architecture and key points that I hope you understand a bit of so that in the next video when we start writing code things are in context and you have some foundation for why it is we're writing code in the way that we are now in the next video we'll start writing our back end once we finish that we'll then move on to the front end but I just want to make it clear clear that what we'll be doing is actually using kind of the template that you see right here now this might seem a little bit confusing right the way that we're doing things isn't 100% clear because we haven't walked through this line by line and you can see that we have a function for example to handle inspect requests handle Advan requests we are logging some information we're creating uh what is i
Original Description
In this series I will be showing you how to create web3 applications using Python. With the Cartesi library, this method can be done using ANY coding language. So whether you develop using Python, Javascript, Go, or C++; this video is for you.
About Cartesi:
Cartesi is an app-specific rollup protocol with a virtual machine that runs Linux distributions, creating a richer and broader design space for DApp developers. Cartesi Rollups offer a modular scaling solution, deployable as L2, L3, or sovereign rollups, while maintaining strong base layer security guarantees.
To learn more about Cartesi, visit https://cartesi.io/
Cartesi Discord: https://discord.gg/kusye4BjGk
Cartesi Docs: https://docs.cartesi.io/
Windows Setup Guide: https://github.com/cartesi/DevGuide/blob/main/windows
Linux Setup Guide: https://github.com/cartesi/DevGuide/blob/main/linux/
Mac Setup Guide: https://github.com/cartesi/DevGuide/blob/main/mac/
Cartesi Repo URL (To Clone): https://github.com/cartesi/rollups-examples.git
DevAd Seed Grants ($$$$ for building with Cartesi): https://mugenbuilders.notion.site/DevAd-Seed-Grants-dc0a2420a08c49a983b919aa9246dcbc
Main resource hub for builders to get started: https://github.com/Mugen-Builders
Setup a call with Cartesi for FREE! https://calendly.com/d/4x2-2hx-scf/1-1-technical-with-mugen
⏳ Timestamps ⏳
00:00 | Video Overview
02:00 | Dependency Setup
07:57 | Creating The Backend
13:40 | Code Overview
16:40 | Running Our Local Node
19:10 | Running The Backend
22:20 | Interacting With The DApp
29:15 | Shutting Down The Environment
31:27 | DApp Acrchitecture
38:15 | HTTP API
39:54 | Vouchers, Notices & Reports
42:00 | Nodes & Epochs
44:47 | High Level Frameworks
🔖 Tags 🔖
#techwithtim
#ethereum
#web3
Hashtags
- How To Code In Web3
- How To Be A Web3 Developer
- Coding In Web3 Without Solidity
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Tech With Tim · Tech With Tim · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
A* Path Finding Algorithm(Visualization)
Tech With Tim
Python Programming Tutorial #1 - Variables and Data Types
Tech With Tim
Python Programming Tutorial #2 - Basic Operators and Input
Tech With Tim
Python Programming Tutorial #3 - Conditions
Tech With Tim
Python Programming Tutorial #4 - IF/ELIF/ELSE
Tech With Tim
Python Programming Tutorial #5 - Chained Conditionals and Nested Statements
Tech With Tim
Python Programming Tutorial #6 - For Loops
Tech With Tim
Python Programming Tutorial #7 - While Loops
Tech With Tim
Python Programming Tutorial #8 - Lists and Tuples
Tech With Tim
Python Programming Tutorial #9 - Iteration by Item (For Loops Continued...)
Tech With Tim
Python Programming Tutorial #10 - String Methods
Tech With Tim
How to Overclock a NVIDIA GPU
Tech With Tim
Python Programming Tutorial #11 - Slice Operator
Tech With Tim
Python Programming Tutorial #12 - Functions
Tech With Tim
Python Programming Tutorial #13 - How to Read a Text File
Tech With Tim
Python Programming Tutorial #14 - Writing to a Text File
Tech With Tim
Python Programming Tutorial #15 - Using .count() and .find()
Tech With Tim
Python Programming Tutorial #16 - Introduction to Modular Programming
Tech With Tim
Python Programming Tutorial #17 - Optional Parameters
Tech With Tim
Python Programming Tutorial #18 - Try and Except (Python Error Handling)
Tech With Tim
Python Programming Tutorial #19 - Global vs Local Variables
Tech With Tim
Python Programming Tutorial #20 - Classes and Objects
Tech With Tim
Cool VBS Script to Prank Your Friends!
Tech With Tim
How to Overclock an AMD GPU
Tech With Tim
Best GPU'S For Mining Ethereum (2018)
Tech With Tim
Recursion and Memoization Tutorial Python
Tech With Tim
Ethereum Mining Rig - Hardware Guide
Tech With Tim
Pygame Tutorial #1 - Basic Movement and Key Presses
Tech With Tim
How to Install Pygame (Windows 8/10)
Tech With Tim
How to Trade Your Cryptocurrency (Bitcoin, Ethereum etc.) For Cash!
Tech With Tim
How to Mine Ethereum 2018 - WORKING (Super-Easy)
Tech With Tim
Microphone Comparison - $10 Mic vs $150 Mic (Blue Yeti USB)
Tech With Tim
Pygame Tutorial #2 - Jumping and Boundaries
Tech With Tim
Pygame Tutorial #3 - Character Animation & Sprites
Tech With Tim
Pygame Tutorial #4 - Optimization & OOP
Tech With Tim
OBS Studio Tutorial - Best OBS Settings
Tech With Tim
Linear Search Algorithm - Python Example and Code
Tech With Tim
Make Any Mic Sound AMAZING! (WITH OBS)
Tech With Tim
Binary Search Algorithm - Python Example & Code
Tech With Tim
Pygame Tutorial #5 - Projectiles
Tech With Tim
Pygame Game - Mini Golf
Tech With Tim
Pygame Tutorial - Projectile Motion (Part 1)
Tech With Tim
Pygame Tutorial - Projectile Motion (Part 2)
Tech With Tim
Pygame Tutorial #6 - Enemies
Tech With Tim
Pygame Tutorial #7 - Collision and Hit Boxes
Tech With Tim
Pygame Tutorial #8 - Scoring and Health Bars
Tech With Tim
Cloud Mining vs. Hardware Mining - 2018
Tech With Tim
How to Install Pygame on Mac OSX (Fast-Simple)
Tech With Tim
Pygame Tutorial #9 - Sound Effects, Music & More Collision
Tech With Tim
Pygame Tutorial #10 - Finishing Touches & Next Steps
Tech With Tim
How to Fade Your Screen in Pygame [CODE IN DESCRIPTION]
Tech With Tim
How to Create a Button in Pygame [CODE IN DESCRIPTION]
Tech With Tim
Pygame Side-Scroller Tutorial #1 - Scrolling Background/Character Movement
Tech With Tim
Pygame Side-Scroller Tutorial #2 - Random Object Generation
Tech With Tim
Pygame Side-Scroller Tutorial #3 - Collision
Tech With Tim
Pygame Side-Scroller Tutorial #4 - Scoring and End Screen
Tech With Tim
How to Create A Message Box in Python - Tkinter
Tech With Tim
Is Ethereum Mining Still Profitable - Is It Worth It (April 2018)
Tech With Tim
How to Run MAC OSX on a WINDOWS PC (Clover Boot-loader)
Tech With Tim
Programming Problem #1 - Alphabet Soup (Beginner/Novice)
Tech With Tim
More on: AI Systems Design
View skill →Related Reads
📰
📰
📰
📰
I built a native Android app in an afternoon, and I've never written a line of Kotlin
Dev.to · Tilde A. Thurium
Vibe Coding Is Real Now — Here’s How to Do It Without Wrecking Your Codebase
Medium · Programming
How to build your first MCP server in 10 minutes
Dev.to · GrahamduesCN
Revisiting My Software Engineering Journey
Medium · JavaScript
Chapters (13)
| Video Overview
2:00
| Dependency Setup
7:57
| Creating The Backend
13:40
| Code Overview
16:40
| Running Our Local Node
19:10
| Running The Backend
22:20
| Interacting With The DApp
29:15
| Shutting Down The Environment
31:27
| DApp Acrchitecture
38:15
| HTTP API
39:54
| Vouchers, Notices & Reports
42:00
| Nodes & Epochs
44:47
| High Level Frameworks
🎓
Tutor Explanation
DeepCamp AI