Space Warp Summit 🛸 Programming on the FEVM - Zak Ayesh
ETHGlobal·Mon, Oct 9, 2023, 12:00 AM
Join Zak Ayesh from Protocol Labs for a talkl titled "Programming on the FEVM". Hack the future of Filecoin! The launch of the Filecoin Virtual Machine is almost here. Come celebrate this momentous occasion and launch your first FVM application alongside hundreds of developers worldwide. Complete with talks and workshops from ecosystem leaders like Filecoin founder Juan Benet, get ready to explore the frontier of web3 and win over $150,000+ in prizes. ----------------- Follow us: https://twitter.com/ETHGlobal​ Check us out: https://ethglobal.co​m Email us at: hello@ethglobal.com
Transcript
foreign [Applause] [Music] builds up on top of all this I'd like to welcome Zach and uh have him go more deep into building on the evm on the FM welcome Zach hey uh thanks for the introduction and thanks Raul for laying the groundwork I think all the information uh was super helpful for uh the demo I'm about to go through uh so we're running on time so I'm gonna go ahead and just jump right into it uh screen all right yep um if you don't know me I'm Zach ayush I'm a developer Advocate uh with the fvm team um in protocol Labs I've worked in web 3 for almost three years now but you know this is all still new to me this like space changes so much and it's it's all so crazy so you know I'm never Beyond learning more um and you know I'm really interested in infrastructure and web3 which is why I'm here I think decentralized storage is a a very important part of the web 3 infrastructure right and if you've watched any of my talks you've probably seen this but you know I'm always uh encouraging people uh not to get discouraged by imposter syndrome you know if this stuff seems intimidating in advance it is because it is and it's like always changing and it is to everyone um we're all learning as it goes on these are some notes uh I took at a conference with some of my colleagues where I'm just trying to learn the addressing scheme that um uh that Raul just presented about right so um yeah you know if you're feeling like you know this is crazy um just know that we're all feeling that and you know persevere on through it um so uh the agenda today is I'm gonna do uh some demos and remix um we're gonna go over like a basic contract simple coin just to show that like all the remix solidity features work um we're gonna move on to a follow coin Market consumer using that filecoin.soul library that Raul talked about and in hard hat we're going to go and we're gonna mess with a simple uh deal Bounty contract not a daily Bounty contract but uh that is a fun name and uh you know uh Molly Roe will probably already talked about this but uh you know we have launched hyperspace which will be a more uh stable test debt for you to develop on you know closer to uh you know go early if you're used to developing in the ethereum ecosystem and we will be using that in this demo coming up all right so um some resources uh we're gonna go and go into remix I have metamask installed already um but you can go to their website to install it just a little browser extension up here and um I'm going to show you how to add the hyperspace Network to metamask so we're going to go to chainlist.org and we're going to click include test Nets because hyperspace is a test net we're going to type in hypersons and here you go here is the hyperspace you know Network it gives you the RPC address um and uh the chain ID and the currency you just click add to metamask this will pop up um I've already added it so I'm not going to actually go through and do that but that's how you add um the hyperspace Network to metamask all right um and then next thing after you add hyperspace to your meta mask is we're going to want to fund it with t-fill since we're going to need to pay gas for every interactions uh we do on chain right so you can find a hyperspace dot yoga uh I like that top level domain uh but yeah if you just click here hyperspace.yoga and if you're just going to the main page you can click on faucet here in the top right and um remember Raul kind of introduced the T4 or F4 addressing so uh F4 is the official final coin address for all ethereum addresses and I'll test that we just call it T4 but they're the exact same thing and so um we can actually just work with almost all tooling with just ethereum addresses right so it's very similar to normal evm workflows right so we're going to copy my account address uh from metamask and we're going to paste it in and we're going to do uh a hard captured here it's always very specific these are always fun so I need specifically pandas and a forest right so uh this panda is cool but he's in the living room uh this band I think is in a forest that's a penguin and I believe this Panda's in a forest so not quite there yet for us forest forest boom all right send and this will send uh five t-fill uh to the wallet I've already as you see pretty funded it but later on in a stimuli you'll probably see I get five extra okay so um now that you have a metamask with the hyperspace Network and uh some t-fill let's go ahead and go into remix well I already have a little I already have a remix open um but you can go to remix.ethereum.
org uh to get to remix and remix is just a very Nifty uh online IDE it's great when you're starting out or you just want to do some basic tests um with a smart contract and later on we'll use hard hat which has a little bit more advanced features if you're if you're used to working like locally as a Dev um but um here you'll see we have a contract called simplecoin.soul right and all this is is a very basic uh very simple simple token contract right and um just has a mapping for balances and a Constructor that mints the whole supply of tokens to whoever deploys this contract you know a function to send coin and some functions to get balance uh based on the address so let's go ahead and deploy this uh basic contract to solidity we'll check make sure you know everything is compiled properly we get the green check mark we're good to go and at the top here uh usually when you come in you'll actually see uh default to remix VM London we're going to go ahead and click injected provider metamask uh so this will tell um this will tell the uh this hotel remix to send all transactions through our metamask account um while remix via remix VM is just like this local local um simulated blockchain right and remember our Constructor here needs to take in a human 256. so um this is going to be how many tokens we made I'm gonna make 1 200. seems like a fun number and we're going to deploy now um in filecoin in a hyperspace it takes about 30 seconds uh give or take for a transaction to get accepted into the chain and then after that transaction is accepted filecoin has uh what's called the delayed execution model right so the the transaction will be included but until the next block um the state doesn't actually change so it takes about a minute or so between transactions for you to see the state change come live so this uh will take a second so instead of waiting for that to come through I have a pre-deployed contract and so remix has this Nifty function where if you have a contract compiled so it knows the interface it knows the Abi you can put in the address of that pre-deployed contract right here and it will know to point to that contract with the ABI right so here we have our new contract um it deployed and um you know if I put in my address and get balance here you'll see that it shows 1200 so the Constructor went through we have 1 200 simple coin and if I wanted to pull up that old contract again you know this was that other contract the old contract address I can just click this button and pull it up real fast and um you know hey Stan and in this contract I had put a thousand as my Constructor right um so this is just to show that like you know yes uh all those uh basic solidity um functions work and so um Raul uh kind of laid down the introduction to follow chlorine.soul right and um you know again to kind of uh just repeat a bit uh before the Advent of that VM um we'll shoot user interaction with follicle with the follicle and blockchain uh was handled by built-in actors right originally called spec actors and you can kind of think of them sort of like ethereum pre-compiles um filecoin.
soul is a literally solidity Library developed by zondax that allows you to interact with these built-in apis uh via writing code and solidity right so normally like um before this devs would interact directly with clients and communicate in the peer-to-peer Network in the blockchain but now we can we can do it in smart contracts which is awesome uh so let's just like go explore and check out the library and uh later in this presentation for some of these important links I'll link I'll go back over them and I'll have QR codes if you have your phone handy that you can scan and go to these uh links right so we're at github.com solidity um you know they give you some basic info on the readme and some docs but the important things you want here are the contracts and so these contracts right here they represent uh the abstractions of these built-in actors right so we have an actor called the init actor and uh this is its live this is the solidity Library you can use to interact with that um and what we're going to be messing with today is the market API um or the market actor right and this um this contract allows us to get information about storage deals um that are on the file coin Network and pull them into our smart contracts so we can write logic so yeah I want to talk a little bit more about storage deals right um a common question is why why the file coin evm why not just the ethereum evm or any other evm chain um well the reason is you know filecoin has access to these uh Native Primitives called storage deals um and the whole reason filecoin was created was to be the um blockchain that's tailor-made for storing the internet's data right the decentralized storage layer of the internet and now with the fevm for the first time you can program smart contracts around these storage deals that are available on any of these other evm chains um and so um this kind of unlocks a whole bunch of new use cases um that I think you know we'll talk about later and we'll go over a very basic one like data dials um storage lending markets and all kinds of cool stuff um and if you want to see uh some live storage deals we can do that by going to the alpha Coin Block Explorer called Phil Fox so we'll click here it's at fillfox.info right and uh this right now is just for the mainnet follicle on blockchain gives us all the stats that we uh would like to see about that uh but we're going to switch to hyperspace now right now it still says wallaby um but this does point to hyperspace so if I click here um you'll see this is hyperspace.filfox.info uh wallaby was the test net we were using before hyperspace so um that should be updated soon but yeah so um now we're looking at the hyperspace blockchain uh testnet and if I click on blockchain you'll see a section called deal list click on that and we'll see a bunch of deals that have already been made on hyperspace and some of the info around those deals so if we click on deal 794 you'll see that this is the provider right here this is the storage provider this is actually storing the data and this is the client who requested the data to be stored um you know the deal ID that defies this deal the block of it was stored in and uh importantly here we have the peace CID this is the CID that um describes this essentially a hash that describes fully the data being stored it represents the data and you have the size of the data being stored in this provider so now that you know you kind of see some deals let's go ahead and look at how we can use that zondax library to actually pull information into a smart contract from the from the marketplace so we'll go back to remix here and I have created this basic contract here that Imports um zondax's npm libraries so zondocs did package the repo as npm libraries very conveniently and we can pull in uh where we're going to pull in the market API contract right here and the uh the market types contract um oh actually and this this this uh contract I'm actually pulling in from the GitHub directly but you can pull it from uh from npm which you'll see in the in the hard hat kit later so um what does this contract do it's just a simple basic getter contract that calls all of the getter functions you can call on the market api.
soul and stores those information in the contract this is more of just an example uh to show uh devs um how you can access these apis and so we can get things from the deal label we can figure out who the DL client is uh the deal commitment which is really important that actually tells what data uh what the pcid is and what the size of the data is that brings that in and you know all kinds of fun things that we can program around and so uh and then like one function that just calls them all and we just pass in a deal ID whatever deal we want to store uh we pass in that ID and so what I'm going to do um we're on the market consumer it's compiling it's giving some uh just license warnings these are fine um we're uh going to load a previously deployed contract so we don't have to wait for the deploy right so you could go through and deploy new just wait uh I'm going to deploy one of my previously deployed if you wanted to deploy new you'd do it the same way make sure you're pointing to injected provider metamask that you have funds in your meta mask and that will pointed to the right contract and you just click deploy there's no Constructor here so we don't have to pass any arguments when we're initiating this contract all right so we'll just click add address we'll pull it in here and um we're going to store let's store this deal that we're looking at right here 794 right and I've already I've already stored it but uh we're just going to go through the steps so if I type in uh 794 and click store all metamask will come up with a transaction just click confirm and the transaction will go through again you'll have to wait about a minute for the state to update but this contract uh I should have already called um store all on ID 794. so let's see if things line up here let's look at um the DL client actor ID 1337 that's this let's look at the client here yep that's their ID so that is that client let's look at the deal commitment this is really important um so you'll see here that uh the pcid is actually represented in HEX um because that's what our alternative functions take they take bytes uh represented as a hex string and PC IDs are encoded and um I believe these are base64 as well um I believe uh and so we have um this is literally just this peace side CID but bit of 16 in code um and there's some logic later on I can show you in the hard hat kit that actually takes care of this for you um yeah and the size um you know this is in raw uh bytes and it lines up right about here with 32 gigs um so yeah this is the the market uh consumer contract just kind of showing off how you can use the follow coin.soul in a very basic way just to pull in some data okay so um now we're gonna move on and do some work in hard hat right so if you know you're a little bit more experienced as a developer you may be used to programming in a in a local IDE and um programming you know with a command line interface and all that good stuff and um hard hat is an SDK one of the most popular sdks for creating deploying and testing smart contracts using JavaScript so it uses JavaScript to kind of create scripts that lets us automate all of those tasks so in this demo I'll go over the uh a starter kit that we've created for developers to download and easily start programming with hard hat on the fevm and we're going to interact with a a basic Bounty contract that uses file cooling.soul to post a bounty for a specific pcid in size so specific set of data and allow someone to come claim that belt um yeah so here we have uh links to the hard hat starter kit we'll go there in a second I've linked to the Lotus stocks um so in this demo for the sake of time we're not actually going to create a new deal a new storage deal on hyperspace um it's kind of a time consuming process not too bad but in the time constraints of this demo uh but you can go to lotus.fallcoin.
io and go to their tutorials and um they'll tell you how to set it you can set up a local Lotus client um on your computer and you can create deals um on the network using that and in the future um hopefully we'll have uh we hope to have some more convenient uh like UI tooling methods to allow devs to easily do that um and the deal Bounty contract that we're going to go over was originally created in falloutry um by a great Dev goes by Zen I think Raul mentioned him earlier and you can find this original repo if you prefer to program and Foundry um here Lotus web 3 deal Bounty contract and um with that let's go ahead and jump right to the starter kit all right so here is the repo for the fevm hardhead kit under fall corn project and you'll see that we you know have basic structure um a contracts folder um a folder for deploying uh a script for deploying all of our contracts and some tasks a task folder and tasks and hard hat allow us to interact with uh are deployed contracts and a readme so um I'm actually going to stop sharing this window and I'm going to share my desktop okay um and we're going to clone this demo uh this uh hard hat kit in here so if we click on code and copy I have a terminal open here I've made a directory called demo I've well it's probably hard to see so let me increase the font a bit um yeah so I made a directory called demo I switched into that directory now we're going to type in git clone I'm going to post in that link we got and uh that's going to clone the repo in there uh I have a shortcut called code which will automatically open a any directory we point to it in vs code if we just type Fem and tab you'll get the full saying code Fe evm hardhead kit and if you don't have this shortcut installed you can simply just open up a vs code editor and open up the directory using like file and open we'll hit enter and now we have that exact starter kit um opened and vs code and the first thing I'm going to do in here is I'm going to open a terminal you can do so by going up here as well and hitting new terminal and I'm going to say yarn this chart enter and uh you know you may have to install yarn if you don't have it already or npm you can use npm at faster package manager of choice but this will install all of the packages we need to run this repo right and it's going to go through it's going to do its thing and a quick walk through um you know here's that read me that we saw earlier written in markdown our package.json which tells us what packages that yarn actually downloaded and what's very important here is the hard hat config which allows us to like configure our hard hat based on the network we want and all kinds of default behaviors that we'd like to put in there and in this repo we have it already pointed to hyperspace so already it's pointing there it's got the chain ID and the RPC URL already in there ready to go for you and one final thing that you'll need to do um to to before you can start actually doing things uh on chain is uh put in a uh private key so that the the repo can um the repo can actually sign transactions with a key right and an easy way to do that is with a DOT EMV file now I'm going to stress I always stress this um never show anyone your private key and uh never check in your dot EMV file so this is an example just to show you and um the private key I will put in a private key to show you how it's done uh but um you know this is just a test account there's no real funds in this account and I will never put any real funds in this account but um you know if if you give someone your private key uh they will have access to all your funds even on mainnet so make sure you're doing this only with a wallet that you never plan to use uh for actual money so we're going to rename this um from Dot interview.example dot EMV and um we're gonna go to our meta mask and I'm going to click on these ellipses here and go to accountant details and Export private key you have to type in your metamask password and you can grab the private key here and we'll delete that and we'll post it right there I believe it actually needs to be as a string uh so our get ignore should ignore um the dot EnV file so this will not push it to git but again be absolutely sure that you're going uh you're not putting real funds on this private key um and so now that we've got that set up um we can go ahead and deploy our contracts so there's a deploy script here and um what it does is it goes through and looks at each of the smart contracts is put in here so here's that simple chlorine contract we have the market consumer and we have the deal rewarder contract that I'm going to go through um and and deploys them now you may see that the syntax a little bit more or both than you would normally see in a hard hat project if you're used to that but all we're doing here uh and this is just temporary is we're calling to RPC um to get uh the um the priority scene and uh we're putting that in our uh transactions so the forces it to default to EIP 1559 um this should be updated in the future to more standard syntax uh but you know the the chain is changing constantly um so yeah that's what this is doing it just uh reads all of our contracts um and deploys them so to do that I'm going to type in let me make sure this is visible too much we're going to type in yarn yarn hard hat deploy okay so it's going to compile it since this is the first time and uh then it's going to go through and go through deploying each of uh each of those three contracts now this can take some time uh again and so what I'm going to do at this point is I'm actually going to switch from this and I have a hard hot project with uh some contracts that are already deployed so exit out of this one okay and we'll open the swine oh nope not this repo actually right here all right and you'll see um so after the deploy script goes through um you'll see a deployments tab come uh pop up and this points to um you know the metadata for where your contracts are pointed to like what their address is and their API and that's how you know it's gone through and you can find this artifacts um folder here to find the compiled by code of your contracts that actually get deployed okay so um you know we've deployed the contracts we've um you know got everything set up let's go in and let's interact with that Bounty contract let's look at the Bounty contract and then we're going to interact with it so under the contracts uh directory we'll see file coin API examples and basic solidity examples basic slitty examples is where you'll just find simple coin for now if all coin API example is where we'll see find contracts that use um the file coin filecoin.soul right and you see here that we're um oh that's file consumer we're gonna go to deal rewarder right and you'll see here um we're calling in some of those um those apis from filecoin.soul right now we have them in here locally but um I will be pointing them to some npm packages in the future as they'll stabilize and we'll just walk through real quick how it works um The Constructor simply sets the owner to whoever deploys the contract we have a simple function here a fund um it has an argument we could actually get rid of that it doesn't use it for anything um it's just so we can send funds to uh to this contract to store and now um remember the point of this contract is to act as a bounty contract right we want to be able to put a CID and the CIA a pcid and a size and um allow a bounty hunter to come through and look at our contract say hey they're looking for this PC ID of this size I can get that data stored on file coin I'll do that and I'll claim the Bounty that they funded the contract with right and so this function adds CID it takes in the Raw CID bytes and the size of the data and adds it into our state variables and you have to be the owner for this to work um we have some policies about how um we're going to release the Bounty um in this case where if the provider was already accepted a bounty for that exact data we're not going to let them keep claiming the bounty but this is where you can get creative you know this is uh kind of a jumping off point for you as a Dev um to uh to kind of add your own logic to start customizing it and really building out a full-fledged app around this um and we have this function here claim Bounty right and what it's doing is it's actually calling uh the market API and getting that good deal data commitment we looked at earlier and um you know storing it in these variables and then this authorized data function like checks to make sure like was this data actually requested as the bounty and at the end of the method it will um if everything matches and it goes to the authorized and everything's good to go it will send one fill so this is hard coded to send one fill as the bounty um it'll send one fill to the client in that storage deal so remember in the storage Deals they automatically have that client field and we can pull the address from that and make sure the money gets sent there so anyone can call this method but it'll always only get sent to whoever actually created the deal which is what we want um and you can see some lower level uh functions that are used right and so um finally we'll actually want to do this and like interact with the contract right so you can go to tasks to do this and tasks are written in JavaScript so let's look at the add CID task foreign [Music] from our command line in hard hat going to add our pcid and um and call that function for us right um so we're gonna have these parameters kind of do the RPC calls and it's going to call the add CID function on our contract and pass in um or arguments now there's some logic in here um using this this Library cig that actually converts the pcid that we get what we saw on Phil Fox and converts it to the hex format that we need to pass in the easy end right so as an example if we would want to run this we would do yarn uh hard hat add and the task is called uh add CID and CID and for each of these um arguments here we're going to have to add in some info so contract this is where you'll put in the contract address of where this is deployed um I have one pre recorded here contract CID and uh again we're going to put the P side PC ID and this is actually the PC ID of that dl794 that we looked at earlier CID and [Music] um size right and the size of the data so um ideally when we add a CID this data doesn't exist as a storage deal right and you go through and you make that storage deal or someone will make that storage deal but to simplify things we're going to put a bounty for a storage that already exists and then uh you know claim that Bounty right um so you would call that function and it's going to run I've actually already run this function with this exact data um so yeah I went through anyway um and yeah you know it converted our piece ID to bytes and read it out for us and you know just a little notification you know give it some time for the state to update um you can do the same thing with font so yarn of hard hat and there's a task here for a fund and this will send uh one fill to the contract and you can call fun and point it you know Dash Dash contract oh not a pet well thank you post and paste in the address of your contract as a string and hit enter I've already run this so um we're not actually going well I'll run it again send an extra fill of funding and uh finally uh claim Bounty right so and for this one you know it's going to be the same yarn a hard hat I'm going to paste this command in uh for time but yarn hard hat claim Bounty uh it points to the contract uh dash dash contract and we put it as a string and we put the deal ID of the um deal idea of the bounty we want to actually um claim the Bounty for that's the argument right and that in right there we'll hit enter here and that'll clean the Bounty right and that'll send the fund to whoever created again whoever is the client of that storage deal right so the client of dl794 was this person and you know in about a minute you should see their balance increase to 14 fill because uh they will would have been rewarded the Bounty for uh making this deal right and um yeah so um that was a quick overview um on um hard hat and remix and programming on the fevm right and here are some of those important resources again if if you missed some earlier this is where you can find the mock or another marks um the file coin dot Sol Library um in the past they were mocks and now they are a full-fledged Library now here is the link for the hardhand starter kit that I just went through and our new developer forums um we previously had these on discourse they have now been migrated to GitHub discussions um so if you have some questions or you know like please post them there and uh Moby monitoring those and if you're participating in a sackathon which I hope most of you are uh you'll find a cheat sheet being posted in the Discord in these Global Discord um by Sarah that has a lot of these links uh in there as well so thank you uh for uh listening to this demo I hope this was uh very helpful for you and you know tried to compact it all in the time that I had but uh yeah this is the team and if you see us around feel free to message us on Discord uh slack and in those forums and uh we'll be active and uh monitoring your questions during the second time so thanks awesome thanks so much Doug just jumping in for kartik but uh yeah thanks for running all through all that um and I think also like sticks out to me is how much of this is very familiar to just writing typical ethereum smart contracts with like just you know dropping in some different nomenclature and and different addresses so uh really cool to see uh and excited to see what everybody builds um yeah thank you so much for that overview Zach
Automatic transcript — names and jargon may be misspelled.