Forking Mainnet for Fun and Profit Greg Nagy; Matt Luongo Tally; Elan Halpern AlchemyGreg Nagy; Matt
Ethereum Denver·Sun, Oct 9, 2022, 12:00 AM
Transcript
what's up everyone i'm alan i'm from the alchemy team you can recognize all of us by these jackets i think isaac's right there so if you see anyone wearing these jackets we're all from the alchemy team um but yeah super excited to teach you guys a little something about forking mainnet today um greg do you want to introduce yourself hello guys uh i work on the tele project and it's really interesting and we just faced the big big problem and this is a solution for that so let's get into it awesome um and just to get a sense how many people are actually engineers in the room okay wow this is the majority cool so this will be pretty relevant then so quick overview of what we're going to talk about one is the problem with mainnet development especially when you're in that development stage and you're trying to figure out what you want to build number two is the solution so the solution that we're proposing for you to kind of streamline your development workflows how that solution works and then we can jump into questions and so this has the potential to be a hands-on workshop if you guys have a laptop and want to pull out your laptop and follow along you're more than welcome to you can also do it after if that's easier so here's the problem testing in prod when we're building a web3 application on the blockchain you want to be able to test it actually on mainnet you want to be able to use it and interact with real applications but you know although we all claim that we test in fraud nobody really wants to test and prod and why is that well we want to interact with these real dapps on mainnet while developing right you know we have these test nets on ethereum those who don't know test nets are kind of replicas of the real ethereum main net but it's with kind of this fake test ether so you're not actually risking spending real money but that's not the real thing and if i want to build an application and deploy it to mainnet i want to be able to test it on that environment so you want to interact with mainnet but you don't want to waste thousands of dollars in the process right testing out a contract deploying it finding out that there's a bug and then just like spending all this money on that contract is a huge pain point for developers who want to be able to test in prod what are some examples here so if you're a d5 d-gen and you're trying to test out a smart contract and maybe front run or maybe mess with the liquidity pool you want to probably try to use fake money first and figure out what the implications of your transactions will be before actually spending like you know thousands if not millions of dollars testing on these main net contracts or if you're just a smart contract dev you want to deploy and interact with these contracts on mainnet without risking spending so much money or having to kind of like fall back and redo your smart contract after it's already deployed what's the solution here number one fork may net locally and i'm sure a lot of you guys actually do this in your development processes i feel like main networking has been pretty common at least for the people who build with alchemy um but this is a really really good solution the nuance here is you can fork mainnet locally give yourself 10 000 east to just kind of mess around with and then you can interact with real dapps on mainnet in the user interfaces and we're going to show you exactly how to do this so we're going to give a quick demo that greg put together um that super awesome you're going to see like what we mean by this what does this actually look like in practice thank you awesome intro thank you so um this is a work in progress kind of a proof of concept so i prepared with the video uh actually too here we are using uniswap actually the deployed version of uniswop and we also have 200d almost which makes us really happy because we do not want to waste our own money who has ever deployed to mainnet and tested development there has anybody ever done that okay and oh hang on and and just to be clear here like he didn't you know fork uniswap's front end and like build this on himself he's actually like pulling up unit swap and just interacting it with it with 200 worth of 200 200 each to actually play around with in his wallet yep and doing the same on kaoswap wrapping it into wwe so you can see that we are actually interacting with deployed contracts we are signing transactions with taliban and we are doing whatever we wanted oh that's good okay this is not getting better here we go the day is saved nice okay uh it might not be a big deal but it actually is so a bit of idea how does it work behind the scenes so we use hard hat to fork mainnet and it was a lot easier a couple of days ago i mean until sunday or saturday or sunday because uh then for some reason uh forking mainnet with hard hat uh anything other than 1337 chain id started to cure the process and the fork just became unresponsive uh there was all these buzz about this issue in discord in scaffolding telegram and whatnot so i was just like okay i'm about to present something to you and the main feature that i was building my presentation on is kind of broken so why not create a workaround and let you do uh let you still use it so for this i i had the main network uh 1337 chain id obviously we have our favorite hacker volatility and we have our live dabs yep so the chain id problem actually hardhat has a really good documentation i recommend it to everybody okay so how did we how did i work around it i kind of implemented a man in the middle layer in italy but a bit more about it a bit later but first of all for this to work you need an archive note which led us to this production yeah so alchemy is really where the archive node comes in um alchemy provides free access to archive nodes on all accounts and for those who don't know what archive nodes are they give you access from like all of the early blocks right so most kind of standard nodes fast nodes give you access for the most recent blocks but archive nodes say i'm going to give you data from block 0 to latest you get kind of the full picture these can cost 200 plus on a bunch of providers and can cost thousands of dollars if you're trying to spin them up yourself in addition to three weeks to getting them to actually sync so with just literally like 30 seconds you can get access to an archive node immediately and that's really what allows us to fork mainnet right so we're literally saying hey main net from block 0 from genesis block to the very very last block that just got mined let's copy all that and then port it over locally and so alchemy kind of allows us to do that so the thing is that uh i'm in crypto space for like six or eight months so i'm kind of newbie uh in that sense and uh it was so shocking for me that there is not not a solution out there so my initial uh idea to solve this problem private main network as a service and google did not show up anything and this might be a feature yeah stay tuned so then i started to go into crypto and i started to realize that we are in the golden age of technology where it's kind of like a wide wide west and all the things that i got used to in that too it's not there or we are the guys who are building it so we got to building it so yep we tell you what you get in this solution is all depth and everything will perceive your wallet as connected to mainnet but because of this heart heart bug i had to transform the outgoing chain id to be 1337 and it's kind of like approximating the chain id so depth is a mainnet connection uh but you also have your balance in your wallet and the chain receives the correct chain id so it doesn't tell you that you should not do this it's kind of transparent sometimes it works hopefully later after this conference i get to create a pr4 hardhat to fix this bug so we can remove all of this extra complexity but the main idea will persist so usually other wallets do not allow you to create a private mainnet or private fork with chain id one and delhi will let you do that so you can use it as a developed and you can use it during development and our purpose is to make your life easier yeah and just to just to quickly piggyback off of what greg means here so when this happened our wallet is reading from this local copy of mainnet right this this one that we just copied down and when we interact and connect that wallet to something like uniswap or literally any any dap that you want to interact with it thinks that the real mainnet is the one that it's reading from so all of a sudden my wallet has ten thousand ether in it and unislop was like cool that's mainnet like here go buy this ethgo buy this this thing and you can deploy transactions obviously they don't get mined on the real mainnet right because our version of mainnet is this local fork that we maintain so this is super powerful now you can kind of interact these apps as they would be on the actual main net but you're using this local copy and unisop has no idea that it's not actually the main net yep so we prepared a bit of hacking time and as good engineers it's mainly located in a github request so [Music] does anybody want to follow along and try it with us okay and just a heads up sometimes it works uh this thing depends a lot on current network connection uh on our current state uh of the local fork so this is not hard end yep so real quick is the general premise that you're just like you're forking the wallet to push the mainnet chain id to the app so you're just telling the unit swapped app this is chain id 1337 no i'm telling the uni swap that it's chain id one yeah yeah so most wallets don't allow you to change chain id one they're like chain id one is ethereum main net you can't set something else for shane id1 and what tally allows is say hey yeah you can change chain id1 to a local copy a local fork of the blockchain so you can't do this with other wallets besides tally because greg like made a a pr to tally that says hey switch local chain local chain to one so that we can start to trick these applications into thinking that we're actually interacting with mainnet so you wouldn't be able to do this on other wallets just to clarify fiddler exactly exactly yeah i were to start with this idea especially exactly with fiddler but realize that i need deeper knowledge about blockchain and it's easier to do it intelli because tele is kind of like your entry point or router in the ethereum network so it just made sense and it's javascript yes bugs and edge cases if you want to improve it feel free i will be really happy i'm down to buying a coffee for it okay so uh github.com uh telecash and uh 1002 pull request a bit of outline a blocker issue workaround so how can you set up uh first of all you need an arkamy account obviously because why is it so hard to get anywhere else on a hive note i have no idea anyway so uh i'm not sure if i will do this with you but hey what can we also take any questions that people have as as we're going through the demo oh yeah oh just a quick question can you also pretend to be other accounts outside of your wallet so can you sign for other addresses yes yes absolutely so you can on the network yeah you can impersonate anybody that you feel like uh you can set up any current state that you want uh you can even run transactions uh programmatically uh you can liquidate the pool because you can be the owner of the pool whatever you feel like so the use cases are kind of huge for this kind of setup but it was possible up till now using hard hat but for that you needed to code every single thing that you wanted to do and my idea because the original need was that i was developing the dep integration for tele and how do you test depth integration without modifying and spinning up all your integration partners and checking what they do and even then you cannot probably properly tested because they have no way to interact correctly with the mainnet so and you do not want to burn a lot of heat in the process another question over there yes so the idea is that i would like this tool to be used by every single web developer and telepro uh teleworld becoming the first hacker wallet because this is the most obvious need ever i mean have you ever developed a single page application that had not access to a rest api or the database and did you feel the pain needing to mock all the gazillion ton of apis i have and i hated it and i came to this space and i was just like whoa it's the same again let's solve it big things though test production first just to be able to figure out how it works like does this play into the aspect where normally developers have to bend that and test yeah yeah exactly exactly any other questions you have um support yeah so you know like basically any any request that you want to make so if you want to like keep a local index or store it anywhere you want you could port that all in from alchemy's endpoint um so i don't know if that helps answer your question is there a specific part there's actually going to but index i was planning to do is to do this but to maintain that environment so would the node continue to run i see yeah i mean so yes so short enter yes alchemy's nodes run for free will we run this local copy that you're operating no alchemy you're you're basically like how alchemy fits into this part is like porting over the real main net locally we don't yet support like arbitrary copies of the blockchain so unfortunately that's not yet but i actually have talked about that with the team before since it's like a very good use case for developers who are testing so i'll bring it back up but no we wouldn't be able to like use alchemy for your kind of local local copy so hard hat it's like it's like a couple here it is i think he's you just did it like while we were saying i think while i answered that question it was done and back to the previous question uh running your own node uh and maintaining the state uh for a long time it's kind of dangerous because the main state will change underneath you but these changes won't propagate to your local forks so you have been forked at a given point like started a git branch or whatever and from there on it's living there its own life
Automatic transcript — names and jargon may be misspelled.