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

Loading player…

1inch Presentation

Ethereum DenverMon, Oct 9, 2023, 12:00 AM

1inch presentation at the buidl palace 02/03/2023 Follow them at https://twitter.com/1inch

Transcript

but haven't actually jumped in on the technical side or the solidity side okay stay a little bit closer okay um so yeah so if you have uh more experience than that this will be a lot of review but you still might take away some tips or something interesting from the presentation so before we get started there is going to be a post presentation document it'll be at this QR code or bit.ly ethereum tooling you can grab this now I'll also have it at the end of the presentation as well so you can grab it then it's going to be a placeholder right now but when the presentation is through I'll publish all of the information on it and that will have kind of a summary of everything I talk about today in the presentation as well as links to other useful resources or anything else that I found interesting so I'll leave that up for like 10 more seconds and then yeah it'll be uh it'll be back later okay so uh a little bit about me I'm a software developer of eight years most of that was spent in web 2 but for the past two years I have been a contributor to the back end and Community teams uh at one inch and my first ethereum conference ever was actually East Denver 2020. um back then I didn't really know anything besides the high level usage of ethereum and I studied it like with podcasts and things like that but I didn't really know anything about the development side or the community side or anything so my friends and I decided let's check out ethanbury 2020 and we were really Blown Away by the community the projects the passion and we ended up doing the hackathon while we were there even though I didn't really know solidity at all and it didn't really work at the end but I found it interesting and it kind of really influenced where my career path would go after that conference so that was the inspiration for this talk today was to create something that would have been useful for me back in 2020 for anybody else who's new to the space today so an overview what we're going to talk about today is we're going to go a little bit about into block explorers we're going to talk about development environments we're then going to go on to transaction simulators and then we'll talk about some useful tutorials that I would like to share so first off with block explorers we're going to talk about or we're going to look into the state of antane contracts and if these contracts are verified we'll look at their source code their ABI or application binary interface and their public functions and we'll talk a little bit about what verified means when we get there okay so the first block expire we're going to look at is probably the most well-known one and it is etherscan there are others but this is the one we're going to look at today in the example and that's at etherscan.io hopefully that is big enough hopefully that's big enough so anyways this is the home page of etherscan there's a lot going on there ether's price the market cap transactions summaries about the block uh the most recent blocks the most recent transactions published on the blocks what we're going to focus on is the search bar at the top and what we're going to do is we're just going to type in the name of a well-known contract and that is going to be the die stable coin so um super quick summary on stable coins they are tokens on top of ethereum that try their best to stay pegged to some fiat currency in this case Dai is trying to stay paid to the US dollar and it is made by the maker Foundation or the maker maker protocol um not all contracts you want to find on ethereum can be found through the search feature like this but Google actually does a pretty good job of finding contracts for you so you could type in die etherscan here you could find the one inch router by doing this so if you can't find them directly on a block Explorer Google can sometimes do a really good job of finding these or I should say it usually does a really good job of finding these so once we jump into the die contract we'll see things like the max Supply holders total transactions on here but we're going to be what we're interested in today is the source code so when uh developers want the community to know exactly how their contracts work they can publish the source code to block explorers as well and that lets you actually view exactly how these contracts work at the solidity level or whatever language they use to publish these contracts and that can be really useful for understanding contracts as well as debugging if we scroll a little bit further down in this section of the code we're in the contracts tab with the code sub tab we'll see the contract API and the contract API is also really useful for when you're trying to talk to contracts from maybe third-party tools or third-party libraries so it knows exactly what the inputs and outputs of all the functions on these contracts are and we'll have an example later that will actually use the Abi if we go over one sub tab to the right to the read contract tab we can see all the public publicly available read functions on these contracts so right here I just did a quick example with the balance of function on this contract and I plugged in a contract from uh one of the pools on uniswap and you can see at the bottom there there is a un256 value which is a very large number and that shows us exactly how much dye is controlled by whatever contract we put in and this number is really big and that's a Nuance of ethereum where the decimal Precision is actually metadata on there so if you want to get a rough approximation of what this value is you would remove 18 decimal 18 digits on the right to get a to get a somewhat human readable approximation and just looking at one more uh example on the read side we can look at the total Supply as well this is also going to be a really big number and it shows exactly how much dye is outstanding in total for this contract if you go one more tab to the right to right contract this gives us all the public write functions as well so these are going to be ways that you actually send transactions that interact with the contract usually to change state in some way to do that you would uh um through etherscan directly they do let you connect your web3 wallet to it and then you would post a transaction to metamask or whatever browser wallet you have installed um as I said earlier there are alternatives etherskins the most well-known one it's also closed Source there are open source Alternatives just a couple is blockscout.com and Beacon chain so if either scans down or if you want to use something more decentralized you have options there as well okay on to development environments um development environments we're going to look at today is uh for writing solidity compiling solidity as well as deploying contracts on Sandbox environments using a local node as well as on ethereum directly so the one we're going to look at today is remix and that's at remix.

othereum.org this is a fully in browser IDE and it's usually a great starting place for when you're new to solidity so if you go to the website you get greeted with this main page and for developers this is very similar to vs code or IntelliJ or any other IDE you are used to using um there's a bunch of buttons at the top left where you can navigate the top left one will be the file explorer View and then below that we'll look at two others which is the compiler View and the deployment view so sticking just on the file explorer view we'll see kind of a structure here a file structure at the top left and we're going to drill into that a little bit and we'll see a file called one underscore storage.sol if you go to remix right now it'll have this example project there available for you as well so you can just jump in and you'll see the same thing on your page when you go there yourself so really quickly we just kind of look at this super simple contract it shows us what compiler versions this contract is for it also gives us the contract name just like a class name and other programming languages we have a field value called a number which is a type un256 and then underneath that we have two functions one is a write function called store and one is a read function called retrieve um so other than the color coding which you've probably already noticed the ID also has a built-in compiler as you would expect so I put an at symbol next to the value number and I hit control s or command s to compile it and immediately there is a red exclamation mark that kind of shows us what's going on or or that there's a problem with the contract if we click on that we will see uh its best uh best guess at what's going on or what's wrong with the contract in this case it's a pretty easy error to fix but sometimes they can be pretty bad but that's true for most compilers as well if you look over at the left there's a red number uh red number one next to one of the buttons that's the compiler view uh the dedicated compiler view so we can see at the bottom there's that same error that we had before which was uh the issue with the at sign and if we fix that we can hit controller command s again and then also we can just actually select the contract explicitly and hit compile and it'll do the same thing okay going down one more button on the left we're going to go to the deployment view what you'll see right away is the environment is the remix VM and this is a Sandbox just for compiling solidity and testing things in isolation it doesn't have any knowledge of any uh anything else going on on the blockchain so we'll just go down to the deploy button make sure that one underscore storage is selected and press deploy and we will see a transaction in the terminal at the bottom letting us know that the green check mark that everything went through successfully and if we wanted to get more details about this particular transaction we could hit the drop down arrow here but we're not going to do that right now and we will see in the deployed contract section at the bottom left this contract has now been deployed so we'll open that up and there will be two buttons there that will be kind of an oranges button that says store and a blue button that says retrieve and those are going to map to the functions that we went over earlier with this contract so if we click the retrieve button directly we'll see at index 0 there was a un256 value of zero which is what we would expect and if we go up and we type in 5 and then click the store button we will write that data into the contract and if we press retrieve one more time the index 0 variable of Type U and 256 is now five so the contract worked as we expected in a sandbox environment so the next thing we might do let's say the contract might be talking out to the die contract we looked at earlier and we only get the total supply of that well we could actually use something called Foundry provider on remix and that's going to connect to something that has a lot more information about the blockchain so really quickly we'll talk about what Foundry is this is going to be a tool that you install on your local computer it is to make you have a more Rich environment for actually testing and developing the tool within Foundry that we're going to use here is called Anvil and that just spins up a local node on your computer that has knowledge of the state of the blockchain and then we can connect to it directly from remix and we'll talk about this a little bit more in a second but assuming you had an anvil running on your computer you could collect The Foundry provider button it will give you one more window kind of giving you a little definition of what Anvil is and you'll see at the bottom it's trying to connect to localhost 8545 that's where Anvil would be running if you had this set up you'd press ok and then you would see on the left new account values as well as no more deployed contracts and that's because you're no longer in the remix VM you're now talking to your local Anvil instance and from here you could deploy it and you can actually make calls out to the state that you would expect to be on ethereum or any other ebm chain and then the last one we're going to look at is injected provider this says metamask for me I don't know if this changes depending on your browser wallet but if you have uh in this case yeah in this case it's going to say metamask for me so from here what you're going to do is if you press deploy it's going to try to connect to whatever Network your browser while it's connected to and it will give you a summary of what the transaction is going to be posted to the chain is going to be and in this case I'm just going to connect straight to ethereum mainnet and press OK and post that transaction through metamask and then we can look at the transaction summary on etherscan and it'll give us the address of the contract that's now deployed on mainnet um so we're not quite done yet as we talked about a little bit earlier you still want to verify this if you want people to be able to see the source code that's pretty easy on etherscan you just press the verify and publish button once you go to your contract page it will ask you questions about the compiler type the license type and then it will also ask for the source code directly and since this is this is a single file it's quite easy to do and then you put that in hit hit submit and then your contract is officially verified as well now Beyond remix there are a lot of other a lot of more command line tools and ways you can set up development environments locally that does not actually use your browser at all or does not use the the browser Ides at all the one we talked about briefly is Foundry Foundry has a whole Suite of tools Anvil is just a local node instance but there's a lot more there's other things like brownie which would be more for people who are familiar with python environments and want to stay using in a using something more similar to that there's hard hat truffle and probably more as well each each having their own pros and cons but I would suggest starting with remix first and then once you started to do bigger projects or you want to have more tools available to you start looking into these and seeing which one makes the most sense for you um next we're going to talk briefly about transaction simulators so these are really useful because you can test the outcomes of actual transactions on the blockchain this can be useful if maybe you're trying to interact with an unfamiliar contract maybe you're trying to collect an airdrop or you're trying to do something with your nft but you don't know how to read solidity or you do and you still aren't quite sure what the contract does because people can obfuscate that pretty well you can actually simulate this transaction and see what's going to happen on the other side this wouldn't protect against Mev but malicious contracts you would you'd definitely see it if if you use a transaction simulator this could also be useful for wallets you don't control maybe it's a wallet with a really large balance that you want to test something on or maybe it's a multi-sig and you want to make sure the transaction is going to go through correctly before you get all of the multi-sig signers to come through and just waste their time on a failed transaction and then one that I use these a lot for is detail debugging they're really useful because they're kind of a visual debugger that lets you step through kind of at your own pace and if anybody's used a command line debugger you'll be very happy when you see this so the tool we're going to look at today is called tenderly this is at tenderly.co and uh this tool is um this is their main website when you go there if we jump straight down to their simulator button at the left we're going to jump in here and it will take you to a summary screen of all the simulations you've run I blurred these out because this is actually my account yours will be blank if you first come to this page and we're just going to jump straight up to the new simulation button at the top right um here uh here's kind of the beginning of this process we're going to tick use custom contract and we're going to plug in that storage contract we looked earlier that I deployed to mainnet so we plug that in here we skip over the input data value and we go straight to or used fetch contract API now if you verify the contract and you've waited a while tenderly will probably pick this up automatically it doesn't always work so we're going to pretend it doesn't in this case and we're actually going to go get the ABI explicitly so tenderly knows how to interact with this contract so we'll go to the page where we deploy the contract we'll go down to the ABI section that we talked about earlier we're going to copy that and then we're going to plug it right back into this field here and then hit import and then sure enough we see the store and retrieve values that we had earlier so we'll go ahead and we'll click on store we'll plug in five again and we will go down to the bottom right and click simulate transaction there are a lot of ways you can customize these transactions on the tenderly but since this is a simple contract we'll keep the example as simple as possible and just leave everything as default hit simulate transaction and it'll run for a couple seconds and then you'll see the summary here so we see a success and if we actually go up to the state state tab on here and we click on that we can see that the storage contracts field number has changed from zero to five so we know that the storage thing worked on the actual chain as we expected but what if we want to actually see the result of that like we want to retrieve it back from the contract well each simulation by default runs in isolation and then you're back to the whatever the base state of the chain is but they have a feature for that as well called run on Fork you can click this button it will read on the transaction again but on a forked version of the blockchain and then you can run subsequent transactions that rely on the state from before so in this case we'll click on new simulation again now that we have a fork where the initial store call was made and we'll fill everything out that we need to and this time we'll call retrieve now on here we'll see another success message hopefully and then we'll also see that the output was at index 0 a value of five so the number has been updated to five we retrieved it and that was successful now we can also go from here into the debug review and this will give us a view of exactly what happened in that transaction at the top left once you go into the debugger view you'll see that there was just one call to retrieve these actually can get pretty hairy if you are making calls to more complex contracts or more popular contracts there's usually a lot of sub calls that are happening too but in this example there's exactly one call and it's to retrieve if we go over into the actual code view you'll see it actually highlights the exact line where the retrieve call was made and below that we can see information about that call so which what the function name was called the op code the caller that actually made the call as well as the inputs and outputs at the bottom next to input you'll see hex here that's just the function selector but don't worry about that too much we see the return value of 5 which is the part we care about now again for people more familiar with richer debuggers you might be used to seeing all the state that's on a contract when you are going through the debugger tenderly gets pretty close with their evaluate feature basically at any point in time during this transaction simulation you can kind of click and you can click the evaluate button and you can ask for any information that's actually on the contract so here we'll just type in number because that's the field that we've been changing and reading so far and it says okay at this point in time at the entry point of the retrieve call I'll evaluate number and what I got back was five and that's what we'd expect because the state of the contract currently is written to five so this feature works pretty well if you try to do like two two complex of an expression it doesn't work all the time but it's always worth a try because it's really useful to be able to see the state of the contract okay and then on to the last section which is tutorials um the first one we're going to talk about is crypto zombies this is pretty well known at this point and has been around for a while it's at cryptosomes.io it's a very gamified approach to learning how solidity Works which is actually pretty useful and pretty fun um and I think they're still updating this project I think it's pretty alive I think they're trying to keep it up to date and make it as useful as possible if we just jump in and we look at the start course you can see there's various chapters they show you what percentage of them you have completed and if we just click into one you'll see that it kind of gives you a visual explanation of what you're making and then on the left it'll talk more about the specifics of it including like the math behind it and what your kind of goal is with the solidity and then it'll give you kind of an integrated development environment so here it's even more simple than remix in this case it's just making sure you're writing the solidity code correctly so that means that you don't need to worry about compiling you don't need to worry about deploying you don't need to worry about any of the dependencies it takes care of all of that and just make sure that you're learning the solidity syntax okay and then the next we're going to look at is on ethereum.

org they have a community tutorial section um here people from anywhere can submit these tutorials they add in tags to them and then they also say like how hard they might think it is or anything like that and you can just browse through by tag and figure out which ones you find interesting and then the last one is ethernet and this is from open Zeppelin this is more security focused you'll be deploying these contracts directly to a test net and it will have challenges where you have to go through and either hack or break these contracts in some way it's kind of like a challenge a set of challenges for you so here's an example on the very first contract it's going to have you try to claim ownership of the contract and then reduce its balance to zero these can actually be pretty tricky especially if you're newer so in the accompanying document that I'm going to link again at the end there's a tutorial uh series that will go through and help you through all of these so it'll be much more of an interactive tutorial rather than a a series of challenges and yeah that's uh that's everything for me um so thank you guys here is the links again if you want to go back and look at the document that kind of summarizes all this as well as give you links to all the tools I talked about tutorials and anything else and uh yeah so uh I'm I'll hang around and answer any questions anybody has and yeah we also have a booth upstairs so come come visit us there if you want to talk to us too thanks I'll leave this up for a little bit

Automatic transcript — names and jargon may be misspelled.