Ethereum for Python Developers - Web3.py #1

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey everybody this is Gregory from deaf University this video is all about aetherium for Python developers so if you know Python and you want to get into Bloch shame and you were in the right place and this is the first video in a series about web 3 for Python developers so you don't want to subscribe to this channel if you haven't already to see those videos when they come out and you can also turn on notifications the little bell icon down below and as always if you're interested in learning how to build blockchain technology you can tell my courses for free on my website over at dap university calm for it slash free download and really quickly if you want to become a highly paid blockchain developer then you need my online blockchain developer bootcamp which is coming out of May 15 2019 and you can find out more information on my website at dap university comm forward slash bootcamp and i'll put a link to that down in the description below today i'm going to show you how to use the web 3 library to talk to the etherium blockchain and if you're a Python developer then this library is gonna be you know your go-to library for talking to aetherium it has all kinds of stuff that you're going to need to build blockchain applications and this is gonna be the first video in a series on web 3 and I also actually have a JavaScript version of this course already you can find out my website over daffy versity comm where i kind of show you the web 3j s library it's got you know a full length article code examples and stuff like that so i'm going to you know turn this video into a series of videos it'll probably have an article with it pretty soon so if you're watching this video by the time that articles out you can probably check the link to the description below to find it if it's not there yet just you know be patient and I will probably eventually get around to creating an article for this series all right so what is web 3 well like I said it's gonna be your go to library for building blockchain applications with Python and it's it's a library that allows you to talk to the etherium blockchain it's gonna allow you to read information about the blockchain like the blocks and the transactions you'll be able to actually ascend aetherium cryptocurrency around like crate transactions you're gonna interact with smart contracts deploy smart contracts and a whole lot more so i'm gonna go over all of that in this series but first I wanted to introduce you to this resource you know this is you know web 3 read the docs aiyo where you can find the Python version and you know reference this in addition to all the content that I create for this tutorial series this is a great documentation reference where you can find all of the you know examples for anything you might ever want to learn how to do with the web new library so let's talk about actually how aetherium works and how a blockchain works and how we can interact with it with this library so basically you know the etherium blockchains a network of nodes which basically means that it's a bunch of computers that all talk to one another and all of the nodes in the network share a copy of all the data all the blocks that make of the blockchain are on each computer and they basically you know participate in maintaining the network right and we can talk to a single node on the network right here and act on behalf of the entire network so essentially we can read data from the blockchain we can find all the transactions we can you read information from smart contracts we can you know do all that kind of stuff just by talking to a single node but we need some kind of interface to you know talk to that node and get data from the blockchain and you know make transactions and stuff like that and that's exactly where the web 3 library comes in it's gonna give us a way to talk to an aetherium node with python and you know get data back send data create transactions all that kind of stuff ok and there's a lot more I could say here you know basically we're gonna talk to an aetherium know with RPC which is basically just a protocol for you know talking to it theory of nodes and you can see that right here and that's what you know web 3 handles under the hood so you have to build that stuff yourself you just get it for free ok and so what we're gonna do is use the web 3 library with Python to talk to aetherium nodes and we're gonna basically just get a URL for our ready to go a theorem node so that we can talk to the blockchain directly without having to run a node ourselves it's really nice we can you know kind of get up and running fast without having to download all the blockchain data and keep it in sync and stuff like that so that being said the next thing I want to do is head over to a Furio to get a link to an aetherium node and that's what we're going to use to create our connection to the blockchain it's furious basically as aetherium as a node service which gives us access to the network right and so basically if once you sign up you know we're actually have a new convention here you're going to see a way to create a project so sign up create a project get an endpoint like this don't use my endpoint I'll probably delete this after I create the video anyway but copy that and keep it handy because that's what we're gonna need in order to connect to our theory emmm node all right so let's jump in and actually start writing some Python code and talk to the blockchain with web 3 alright so in order to get started the web 3 on Python you're gonna want to you know have Python installed have a virtual environment set up all that kind of stuff so once you've got all that ready to go we can install web 3 like this we can just say you know pip install what three all right so I've already got it and I also created a requirements txt file in this directory so I'll show you more about that later in this video when we actually turn this into a code project but for now we're just gonna go install everything manually you run it in the terminal on the console all that kind of stuff so what we'll do now is actually take the you know inferior URL that you got from registration step and just make sure you got that handy I've got mine here I'm just gonna put it here so now I'm gonna actually open the console on say Python alright and the first thing I'm gonna do is actually import web 3 like this I'll just say from web 3 import capital web 3 ok lower case we have 3 capital o 3 all right so that worked and what I'm gonna do is take this in fewer you are L copy it I'm gonna say if your URL equals this alright and now I'm going to create a new web 3 connection like the as a web 3 equals so I'm gonna do this say web capital web 3 web 3.8 gtp provider I'm gonna pass in the inferior URL oops all right oops sorry about that I mistyped that I just left the three off of web 3 so yeah what 3 equals you know capital web 3 and we're gonna pass in the HTTP provider like this and then pass in our in fury RL all right so now I'm actually just gonna see if it's connected and we can do they like this we can say well 3 is connected all right it's true so we are actually talking to etherium we can further verify this with a really easy step what we're gonna do is just get the latest blot on aetherium right so the theory was a blockchain made up of bundles of Records called blocks which was chained together to make the blockchain each blocks got a number and we can read the latest block number with web through like this could say web 3 we do the e th or a 3/8 namespace say block number all right and that's the current block number and it might change if I do it again and I've stayed the same but you could like whenever you do this you know your number will be different and if I do this probably 10 minutes from now it might be also be different so I'll show you the next thing which is actually you know interacting with accounts on aetherium right so let me pull up the diagram that I had a minute ago where I kind of showed you how theorem works so whenever we you know talk to the network everyone who uses the blockchain has a unique address so this is a very different paradigm from the regular web like you know if you go to a web application and you sign up you get a username and a password and you're a user of the application well when you use the blockchain you actually are a user of the entire network and when you are a user of the network you get an address right and that address is gonna correspond to your account which has some sort of balance right and that you know balance sometimes called your account sometimes it's called a wallet that's going to have this balance and that's going to tell you you know how much ether orthere cryptocurrency that you have and also you can store tokens and things like that and you can use it to interact with smart contracts but basically we're gonna think about it like an account in a wallet right now that actually stores some aetherium cryptocurrency and with web 3 we can actually like you know find stuff out about the account like see how much aetherium is in it so I'm going to use my real account with my meta mask wallet so I've got from Ed amass this is basically just a wallet for you know talking to aetherium and I have a real account in here you know this is the theory of made Network I've got some real ether I've got almost three eise in here and I want to read information about this account with web 3 Python so what I'm gonna do is actually get the account balance so we can do it like this so I'm gonna go to the terminal here I'm gonna say web 3 CU f not get balanced alright get balanced I'm just gonna paste in my meta mask address that I copied from the clipboard ok say balance all right so we can see this number here we actually got a number back so that looks like a lot that's not actually ether I wish it was ether I'd be great if I had that much ether in my wallet that's actually way so way it's kind of like a penny on aetherium it's the smallest you can subdivide a ether it's actually 218 decimal places but we can actually convert that to ether like this with a utility inside web 3 we can say web 3 from way and pass in the balance and convert it to a thir alright there we go and we can see that number matches actually what's in my meta mask account right alright so that's how you do this in the console and I'm actually going to turn this into a project so I'm going to like open this in sublime text and I've created a new project inside of here we're going to you know use this for the rest of the tutorial series well actually right the code inside of a script and we'll run the script instead of doing everything inside the console over again you'll have to you know open it and load you know your provider every time basically we're going to put all the code inside here so I'll just show you you know a quick example of that we can just run the script like this you can say you know import do the same stuff we did inside the console we'll say import web 3 from web 3 then we can import our if you're a URL like this and now we can instantiate our with your connection just like we did in the console web 3 equals web three capital owed three okay HTTP provider and it will pass in the afure URL and then we can print the block number well actually let's make sure it's connected first will say web 3 is connected and we'll print the block number okay and then we will put the balance say balance close web 3 he's get balance and I'm gonna copy that meta mask address again one more time I don't remember it off the top of my head so do like this okay and then we'll print web 3 that from way say balance I'll say ether okay now let's hope I do all that right let's try run the script say Python at Pui all right yeah it worked so it's connected there's the block number and there's my ether bounce so that's a good example project again I've got a virtual environment set up I've got these requirements in a file here so that we can load web 3 every time into our project so yeah I hope you all liked this video that's all I got for today again this is gonna be the beginning of a series on web 3 so be sure to subscribe to the channel to see those next videos and they come out you know always click the like button down below that really helps these videos get found that more people can learn how to build watching technology and don't forget about boot camp my blotching developer boot camp which is coming out on May 15 2019 and if it's already out you can find out more information on my website / adapt University comm so again I hope you all liked this video and until next time thanks for watching DAP University
Info
Channel: Dapp University
Views: 42,455
Rating: 4.9057899 out of 5
Keywords: ethereum developer, ethereum solidity, dapp ethereum, ethereum app, ethereum development, ethereum dapps, ethereum application, ethereum tutorial, ethereum mist, decentralized applications, ethereum web3, dapp, ethereum contracts, solidity, programming ethereum, ethereum programming language, ethereum coding, ethereum contract, ethereum code, ethereum virtual machine, ico
Id: SAi5rYFh7yw
Channel Id: undefined
Length: 13min 37sec (817 seconds)
Published: Mon Apr 08 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.