Encode Club x ETH Safari Hackathon: Tenderly Workshop Part 1 (Correction)
Encode Club x ETHSafari Hackathon 2022 · 7 Sept 2022 · 17:51
Nenad Vitrović from Tenderly records a corrected walkthrough after a contract verification failed during the live Part 1 workshop. The video shows two properly deployed contracts added to the Tenderly dashboard and verified privately, then used to inspect a failed transaction, re-simulate it with new inputs and state overrides, and run simulations on a fork. It ends with automating verification and forks inside a Hardhat project using the Tenderly plugin.
Speakers
Topics
From Encode Club x ETHSafari Hackathon 2022, hosted by Encode.
Transcript
hey guys it's done it again so my goal with this video is to amend the issues that we've seen in the in the live demo and um let me first explain what happened so I did do a last minute change to the code so instead of uh the original type that I put in here which was unit eight I decided to promote it to you in 256 which I did in almost all the places apart from this one so this led to all of those issues that we've seen indeed uh the verification couldn't happen so it was a bunch of unfortunate events on on my end and right now we have proper contracts deployed to a test Network and
I will briefly add them to the tenderly dashboard and I'll Speed the video up in this section so you don't have to really re-watch all the whole thing so here we go based on the contract address in here and specifying the network it was in the contract is unverified and I'm gonna hit add contract I'll add the second one as well so going back here it's the shop coming in based on the contract address and again the network it was verified on adding the contract all right so we added the contracts and now we need to verify them if you really want to do this manually
I'm guessing that's at a point where you don't want to incrementally keep developing your contracts you're pretty happy with it uh you can hit verify select the paste source code and well paste the source code now the thing to notice is that this is the contract starting with nine eight B and so on so let me see which one of these it is so 98b this is the shop so I'll take the entire file foreign I should select the actual contract from the source file which was used to deploy the one we
started verifying so we're verifying the shop here and we're going to make it private so this means that this contract is not available to everybody using tenderly so it's not a part of let's say public registry it's just a part of your project and if I hit next of course the window that we've seen selecting a compiler version and leaving all of these on default because we didn't I didn't actually specify any optimizations or change the evm version and when I click finish after just a moment we can see that it's privately verified and I'm going to repeat the same process with the
warehouse so paste in the source code the source code is already in here going next again doing the warehouse and will verify it privately and if I click next this brings us again to The Familiar window and we go finish and we have our two contracts in there now I will make a couple of transactions in here so I'll go to shop and buy two pieces the fact is Warehouse is limited by having 50 items in it total Supply is 50. so I'll just forcefully execute a failing transaction so we can see it in
the in the dashboard but imagine that this one happens this one happens the failure happens for different reasons coming back to tenderly I'll go to shop and view transactions and here we can see the 2 and we can see that the function by failed in in this invocation and succeeded in this one I'll go to the the successful one and again we can see that the event is decoded to come back to the source to check where it's submitted from we can go here and it shows us the source of this contract so we can see that the taken event is emitted at this line the state changes of course didn't happen
uh that did happen because we're examining the successful transaction so we can see that the total Supply uh got decreased uh that the balance of the minor got increased and that my balance the balance of of uh my signer got also decreased coming back to transactions and going back to to this one that failed it said wanting too much so we can hear c um uh the execution trace of this transaction it's really short compared to the one of the unit Swap and if we go back in here and if we go back in here we can see that it got reverted because the amount was greater than total supply
all right so we have to we have to check in the overview what was the exact value of the input data and it was 444 so that's way too much uh to make the transaction succeed we can do re-simulate and in uh when we do simulations as I mentioned and failed to demonstrate uh we can actually specify any values that we want for the input parameters so I'm putting 32 here that's something that can go through and when I go simulate transaction it did succeed and you can notice this executed really really in a in a short time
so we can examine that after we deduct we deduce 32 items from the total Supply we're left with 16. and this is what transaction simulation does now the next thing would be to run it on Fork but before we get there I would just like to go and re-simulate so we can add 444 here but I want to show you another thing so since this is a simulation we can control anything about it and as I managed to show in the workshop we were able to change the gas gas price value and so on but another thing is we could do state overrides and here we can actually change the
state of any contract that is involved in this transaction and right now we could see if we want to we could see how would the transaction execute if the warehouse had total supply of something that is greater than 444 instead of uh how how much was left 48. so to do this we just activate a state override we select a contract we wish to override and we can set the storage variables and here you'll get a list of all the storage variables available in this contract and you can specify the value that you wanted to have so for example 555 hit add and when we go simulate transaction
it will actually succeed now when we go to state changes we can see that the transaction of somebody buying 444 pieces was executed but the storage slot called total Supply within this contract its value was set to the override we we applied so this is another way that you can do simulations in this regard and if we want to go run on a fork this means all right so we did the state override we executed this transaction so when we go around and Fork this very same simulation or the simulation of the
execution of that original transaction that failed is available in here so here again we can see it's 444 it passed uh and again if we go with the new simulation the parent of that simulation is the latest one and I'm gonna I could go here executing something on the shop or the warehouse itself so I'm I could take 33 and if I hit simulate transaction it pretty much executes as expected and if we go back here the total Supply is 111 which is the value that remained after the first simulation executed and this is the new
value 78 the one uh the the number remaining after we simulated this new transaction so that's about simulation and forks and this is the example of the actual proper execution of verification process but as I mentioned um if you are in a development Loop and you want to do do these um if you want to incrementally develop your smart contracts you can do that either by using the sandbox so the one that was shared or if you prefer to work in hard hat with hard head you could
easily add support for that now let me show you how you can use the tenderly hardhead plugin to verify contracts automatically we'll go to a hardhead project and this project is available on GitHub actually containing all of these examples and different modes of verification so here the only things that you would have to do in your project would be to add a tenderly entry in the hardhead configure exporting and you would have to add the project the project name the slug actually the username that's your username and you would have to set private verification to true
now if your project has multiple words that's actually a slug and you can copy it here from the address so it will be the demo and this would be your username the second thing to achieve automatic verification would be to add a config parameter to the tenderly plugin so you would have to explicitly call setup and you can control whether or not it's automatic verification in play to be explicit it would be the best to actually specify this over here now to actually run a verification I'm going to run this script and this is how your script could also
look like so you would get your contract or contracts you would have to wait for it to get deployed and that's it at the point where this function is invoked the tenderly hardhead plugin would actually be aware that to deploy the contract to the network and it would automatically verify it integrally so let's do that it's npx hard hat run Scripts and this is in greeter automatic yes and we'd have to specify that we're using Robson all right so if we go back to Chrome and if I
refresh the window we'll see that we have our greater verified privately and of course we can view the source code and since we didn't make any transactions yet the list is empty and the last thing I would like to show you is how to use a fork within a hardhead project in order to achieve that you would have to add a network tunnel Network and here you would have to place the chain ID the chain you port and the Json RPC URL of the fork so let's come back to tenderly and first of all let's create a fork on mainnet for example it's completely arbitrary
and just give it a name something that that resonates with you and you can either use the latest block or select any Block in the history the selection of the block helps you in the following way the current state of the mainnet at this block will be available to the fork so if you want to select a particular point in time in the past of the mainnet you can do so by specifying the block you would like to work from and when you hit create this is what you get an empty fork with zero simulations now in order to use it in hard hat you would need a Json RPC
URL uh most likely the dev plan you're using doesn't show this URL over here but the key information is the fork ID that you can find in the URL of your browser and we should go back to the hardhead config and simply replace this placeholder with this value that we got so this is the prefix of the Json RPC URL RPC tenderly code Fork slash vid on the fork and of course double check if your chain ID over here matches the Trinity of the network you forked and I'm going to save this one
and let's do a deployment of the very same greeter but this time we'll specify the tenderly Network as the destination so if I hit enter and wait just a bit and this is not sped up not one bit it says that the contract is verified and deployed to this address and if I go back to fork and reload the page I am seeing the contract over here this is showing us actually the transaction that created the contract and here I could create a new simulation now here as you can see we have the greater contract as an option and I can select set greetings say hi Mom
and hit simulate transaction and as we can see it executed the input parameters are decoded there's greeting hi Mom there are State changes present and if we go back to the contract section we can actually see this contract is present and verified uh coming back to the fork screen sorry to this main Fork screen if I go into contracts I can see all of the contracts that got deployed and verified and I'm stressing this deployed and verified on this Fork so there you have it this is a way you
can deploy your contracts from hard hat and pretty similar seamlessly use tenderly forks for very fast executions of your for example code deployments or we could even go go into the execution of transactions here and those would end up on a tenderly form [Music] foreign
