New Ethereum talks, every Monday. The week's conference uploads by event, in your inbox.

Loading player…

ApeWorX 🛠 Learning How To Ape

ETHGlobalSun, Oct 9, 2022, 12:00 AM

Join Evan of ApeWorX for a workshop titled, "Learning How To Ape." This workshop is part of ETHNewYork 2022, a three-day in person hackathon that will feature hackers, mentors, enthusiasts, sponsors and speakers who are all gathering in New York June 24-26, 2022 to talk about the future of money, finance, the web, ownership, the way software works and the way power is distributed. We're excited about a new frontier. ---------------------------------------------------- Follow us: https://twitter.com/ETHGlobal​ Check us out: https://ethglobal.co​m Email us at: hello@ethglobal.com

Transcript

[Applause] [Music] uh language for writing smart contracts so if you like the python framework you'll love the the viper language for writing your contracts we have some additional information uh about testing up on ape academy that will help you test your smart contracts so let's take just a second and look at ape academy since i've already been talking about it a bunch so while this this talk is only about half an hour long right with some room for questions inevitably if you're using it you're going to want to go back and reference something that either i've said or something that you want to do you want to deep dive some information that's where ape academy comes in we've currently got some featured tutorials including one that was just released today my co-worker chris works really hard on creating a lot of these tutorials and uh we're gonna actually hands-on go through deploying a erc20 contract in just a moment and while we're going to go through that really quick this will be a great place to come back and actually explore information about them so please check out ape academy so one of the features that we also have is something called ape template so if you don't really know where to start on a contract and you want some rough framework for yourself you want something that works out of the box and that you can easily customize this is where a temp template really shines for us so essentially when you download ape the plugins we don't decide for you what plugins make sense for the kind of project that you're working on right if you are never touching solidity or you're never touching cairo why should we kind of bulk up your system with additional plugins that you may never use so this allows you to really customize and pick what things that you want to focus on so with that being said to use template we're not forcing uh users to go ahead and and have that as a download it's it's an add-on for you we do have a recommended plugins list that you can download if you're just getting started you're like hey yeah let's go for it so to install a template we'll watch a little video here in just a second and we're going to focus on the erc20 token there's a standard for it hence the erc20 the files that are generated there's a token.vi vy file which is a vipre file and that is the erc20 standard this is for a fungible token we've heard a lot about nfts but you know what was an nft before an nft it was fungible right hey so these are identical tokens another contract that we support is an erc 721 which is the nft standard once again that's a non-fungible token and therefore unique and it has metadata associated with it that allows for linking assets and other other things you can see on the right hand side here that it is on the right for you all right or is it just for me okay sweet um kind of the file structure that is created when you use the template so let's let's build this real quick so i can type in eight plugins and point that to an install of template should be fairly quick here and now that it's installed i can use it by calling a template and pointing it to the github repository that i wish to connect to this could also be an http address and this uses cookie cutter so anything that is in square brackets is kind of a default value anything that i type in will override that default value and so a lot of the interfaces that are going to be used in this token contract you can decide whether or not you wish to engage with right whether you want to pre-mint whether or not you want something mintable or burnable or permitable so i just let the defaults happen there and we can see that it's created the file structure for us so i'm going to take a second to step away from the videos here and actually look at the structure hopefully this is big enough you can kind of see it everybody we good all right so this is that same demo file that we had on the video earlier and we can see the contracts folder this is everywhere when you utilize ape that you're going to store your contracts you can have nested folders within there but kind of starts with contracts it's fully configurable so if you don't like the word contract and you want to have i don't know letters or code snippets or i don't know whatever you want to call it you can customize that it's one of the great things about our tool set is it's highly customizable so just briefly looking at it we can see that where i overrode the words demo and dmo as the symbol for the token left 18 decimals as a default value and um once again a shout out to chris if you use ape academy and look at his video i had that up here earlier yeah on how to make an erc20 he really goes into depth there's both a transcript and a video here of all the components of setting this up and then telling you kind of the breakdown of the contract itself and even giving some tips about how you might use it or what it might mean to implement a certain interface the other thing you have here is the scripts folder so this allows you to use ape run to run your scripts and that will automate a lot of your processes if you wish to have a more interactive experience we have ape console that we'll see in a moment when we do querying that allow you to do more of a hands-on interactive environment with locals available to you so the scripts folder that we have here has a deploy currently script in it that's very simple this is just going to ask me what account do i want to deploy with and then it is going to do the deploy action for me the other thing that's really nice about using this template is that you get some things pre-built inside of it as far as the tests go we give you some fixtures straight out of the box so that it can support these pre-made tests around some of the questions that we were asked earlier like do we want it to be able to be mintable do we want it to be burnable right so the tests are already kind of built for you out of the box and the last thing i want to cover at least in this screen is the ape config yaml so inside here you can basically configure your your project to interact with the ape framework and create a lot of overrides as well we see that right now all i'm doing is specifying that i have a dependency of a plug-in that is the viper plug-in that will help compile to the abi code by code that i need to deploy we'll see this compile and one thing you'll also note is that we're going to use confirmations so knowing that the block can change just a little bit as we're adding to it right we want to make sure that it's at a stable point before we consider our contract to be fully deployed if we wish to override any of these we can actually do that here in the uh yaml so with that said let's try it so i'm going to go um i want to run this script that i've written right or that's been generated for me the deploy script so i can say ape run and i want to do deploy and the thing is i'm not ready to deploy this to mainnet yet just yet i would like to use a test chain right so i'm going to use the network flag network just to position this to which chain i actually want to use what what provider and what network and what ecosystem so i want to use ethereum and i would like to use rink b if i could type and lastly i would like to use alchemy as my provider so it's bringing up some accounts that i've already set as personal accounts and i've given an alias to so that i at least know which account works for me i'm going to select my account and i get a signing prompt here which at least allows me to look at the gas so beforehand i can be like yeah that's acceptable to me i would like to do that i will sign i'll enter my passphrase please don't steal it will ask me if i want to leave this unlocked i might have additional things that i wish to do and i don't want to have to unlock it every single time for now i'm going to say no and now what i can see is it has begun the process of making sure that it is confirmed on the block we can already go ahead and look at this ether scan link etherscan is another plugin that we support and the internet's just a little bit slow so we'll wait for this to load yes so we now see that it has successfully uh the transaction itself is successful the next thing we would want to confirm once we wait for the the two confirmations here is that the contract itself might be hitting that a little hard huh with the retries um is that the contract itself has deployed so i can go back to etherscan and check that my token is now available and we see demo token erc20 dmo is the symbol so we have actually if you all want to even go out on the test net on rank b right now you can see that i just deployed an erc20 token what no claps [Applause] thank you all right so we talked a little bit about the plug-in architecture let's dive just a little bit deeper because one of our bounties is writing a plug-in so you might say evan all right what's this plug-in thing about we got ape core which is basically the glue and defines how these components are going to interact with each other you have some core plug-ins that come kind of out of the box as soon as you download a that are ethereum geth pm which is a package manifest sorry had a brain fart there package manifest uh plug-in and then each tester which helps to set up and supply some of the locals that you you can utilize in the testing environment so then we have what we call supported plugins that are written by ape paperworks employees like myself they kind of fall into some different categories we have compilers so these are language based these this is what's going to convert your viper solidity cairo into an abi or contract type byte code right we support out currently support hardware wallets uh ledger and tracer this makes for a really great way of not exposing your private keys while interacting with the chains we support l2 ecosystems like phantom and starknet which i do want to give a shout out to one of my co-workers for making the first non-evm plug-in jules who happens to be with us today and uh we also have provider plugins like hard hat you saw me use alchemy earlier in fura and foundry is currently in alpha we have a lot of projects that are currently in alpha and we'd love for you all to have a project in alpha beta gamma production whatever right so you're saying evan how do i make a custom plugin well let's walk through that real quick so the first place to start if you want to go for this bounty or you're interested in plugins i would say is to look at some examples of plugins that we've already written so if you want to know something about like ape solidity you want to write a different kind of compiler for languages i would take a compiler api and kind of begin looking down that path providers maybe something like infuria using the provider api tracer using the account api or if you want to make c a cli extension ape tokens wraps the token list and provides that through the cli so here are the like bare minimum requirements right you've got to start with ape underscore give your plugin name generally whatever the plugin is about right and then you kind of pick your own adventure here this is an and or you can do both things you can choose to do one thing but you've got to implement one or more api classes from the ape dot api module and or make a sub command and point it to your entry points in your project setup if you're looking for ways to kind of organize your file set and look at the standard that we've already kind of created we actually have an optional project template in github that you can utilize so as for the adventure path of implementing the api classes here's a quick example of using the alchemy like we saw that i used earlier you want to import the api class and then make that the base class so unfortunately i cropped off the line numbers here but where it says alchemy ethereum provider and it has web3 provider and upstream provider those are where you're utilizing the base your base class with the apis right so a web3 provider allows access to the web3 chains and an upstream provider allows for forking and you can see kind of here even though i've collapsed everything you've basically implemented the abstract methods for connect disconnect establish or not establish but estimate gas cost and send transaction so the details of how these things are done you decide as long as the interfaces connect together right it makes sense the next step to that is registering the api class which this is a separate file and we just see that we have a list of networks that we're providing within the alchemy mainnet robsteen rinpe which you saw me utilize and so on so forth and then we just yield after registering the plug-in ethereum being the ecosystem name whatever the name of the network is which in this case would be um alchemy and then the provider itself if you're creating a cli extension you can look at an example like ape tokens which wraps a token list and we can see some some click commands here and click groupings and the next part of that is just to register your entry points so between lines 67 and 70 there we see entry points and we're just saying ape tokens as a command is actually going to point to the ape tokens library looking at the underscore client or cli file and then pointing to the cli method and the final thing i'll leave you with is how to query the blockchain requirements here just that you're connected to an active provider we're going to look at this real quick in ape console which is an interactive python environment that has locals such as chain there's much more but we'll point you to um additional things in the ape academy for the rest of it but essentially it returns a data frame that lets you do some really neat things so let's do that just really quick if i can find my there it is okay so ape console this time i'm doing a network of ethereum main net and let's do infuria all right so i currently have an active session here and i want to set up a few things so i'm going to copy paste here so the first thing i'm going to do is set up my stop block which is going to look at the chain and get the very last block and get the number of that block so if i want to know the last block there we are then i'm going to set up my start as being 50 blocks before the last block and then i can do something like looking at the average gas used over those 50 blocks or i could do something like looking at the average time of creation over those last 50 blocks like how long does it take for a block to be generated we're up to 17 seconds this morning it was 14 so that's fun or we can do even more complex things like set up visuals with matplotlib so if i generate blocks and i go back over the last 20 000 blocks in steps of 1000 because i'm wanting to aggregate some data here and i use matplotlib for the visualization and then a little magic here and let's show it we can actually create some graphs based dynamically on the [Applause] blockchain all right and what's my time looking like i got two minutes or so uh the last last thing i want to do is um give a shout out to the bounties that we're running so if you want to do any kind of smart contract project using eight we have a kind of first place at 3 000 second place at 200 200 500. if you write a plug-in which we kind of went through 3000 for that one and going over like the blockchain data that we just did that's 3000 for coming up with a really good story utilizing those uh analytics any questions yeah um so the the question is about the ape console what kind of environment essentially is that and it's essentially an ipython that has additional locals injected into it so you can access the ape-specific functions but you do have the full python environment available to you any any other questions all right well i will see everybody at the karaoke later please be sure to hit us up on discord check out our github read our docs we're kind of cool just saying but i'll talk to you all later

Automatic transcript — names and jargon may be misspelled.