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

Loading player…

Building with the Safe 4337 Module - ETHGlobal London 2024

ETHGlobalWed, Oct 9, 2024, 12:00 AM

Join Germán Martínez from Safe for a workshop titled, "Building with the Safe 4337." Learn about the Safe 4337 Module, how to enable it and execute sponsored transactions using Pimlico infrastructure. This workshop took place at ETHGlobal London 2024, a 3-day hackathon held at the Truman Brewery in London from March 15 to 17, 2024. The event brought together the most skilled web3 developers, designers and product builders from all around the globe for a weekend-long adventure to advance the Ethereum ecosystem! ----------------- Follow us: https://x.com/ethglobal Check us out: https://ethglobal.co​m Email us at: hello@ethglobal.com ----------------- Follow us: https://x.com/ethglobal Check us out: https://ethglobal.co​m Email us at: hello@ethglobal.com

Transcript

[Music] good to see familiar faces from before thank you for attending uh my name is Herman I'm a developer relations at safe and today I would like to uh share with you what we are building regarding the ERC 4337 how how we are integrating it with safe uh thanks to the safe 4337 module so first of all I would like to ask uh if you have heard of it before please raise your hand okay very good uh and I guess in the last couple of months even year we've heard a lot of new terms regarding uh the ERC 4337 right and now uh is our turn at safe to uh integrate it to have support for it uh in this Workshop I will talk uh a little bit about the benefits of the ERC 4337 but I see that most of you are familiar with it then I will cover how the safe smart account structure or architecture allows this I will show what the save 4337 module is and how it is connected with the different actors uh and and the 4337 stack and finally at the end we will will see a demo uh executing a user operation getting it sponsored uh with the permissionless JS library and the Pim Lio infrastructure so let's start with the uh or some of the benefits of the ERC 4337 and apart from the ones that are inherit in um for the smart accounts we have for example flexibility of payments where users can decide how the uh how to pay for the gas fees they can pay in uh ERC 20 tokens they can pay in the native token they can even get their transactions sponsored by a third party there's also freedom of authentication because it enables different ways of uh authentication like uh multi signature or pass keys or maybe Quantum proof uh [Music] mechanism and also it provides decentralization avoiding uh the lock in of a single relayer technology by uh supporting different accounts and different providers so let's see how the safe smart account architecture looks like it all starts with the uh with the core contract the account itself the safe and you may know uh safe it's a modular smart account this means that it supports among others modules and fallback handlers there are some more that we will not cover in this Workshop But Here For example modules allow to extend the functionality of the save uh by uh implementing some logic in this uh module and modules have access to execute transaction in the safe they can be used for example to implement recovery mechanisms different ways of authentication and very soon we will see how they will help as well uh integrating the 4337 also we have the fallback Handler the fallback Handler is a contract that can be enabled in the safe and whenever uh a call is received in the in the safe account if there's not a function implemented that is called in the in the contract it will fall back to this contract the fallback Handler and see if it is implemented there and if it is it will execute it there this is very helpful when we want to integrate standards that are uh or or support the standards that come uh out in the community and they are not implemented in the main account but they require the implementation of new uh functions like this case uh regarding the sa 4327 module we need to enable it as a module and also as a fallback Handler the module will allow uh this module to execute save transactions and the fallback Handler will allow to receive uh some calls that are sent to the smart account but just uh to clarify the difference between these two slides it is just one module that is enabled uh with two different roles so uh let's see now how the save 4337 module uh works together with the account and also the other actors so here we can see uh first of all this is the validation step later we will see the execution step uh but we can see the different actors in The 4337 ecosystem we have the bandler uh the entry point an account in this case the safe smart account and then we have a Target depending on the uh user operation and the transaction that is executed so it all starts with uh banders submitting user operations uh to the entry point then the the entry point will iterate on all of them and first validate them and secondly execute them so first of all let's say we have just one user operation it will be sent to the uh account here the save proxy your personal account will receive a call uh of a function that is a validate user operation if you remember uh safe is not implemented or giving support natively of the CRC but uh using the module so we have the say 4337 module implemented as a fallback Handler that will be able to handle this call so the safe proxy will forward the user operation validation to the module and now the module will do uh two things first of all check that the uh user operation hash was correctly signed by the owner of the account and secondly and if needed it will trigger a payment because it is also a module and it has uh the the ability of the grant to execute save transactions uh to perform the the fee payment to the entry point after successful validation the entry point will now call the account to execute the user operation so calling the execute user op again this method is not implemented natively in the safe so the safe proxy will forward the validation to the sa4 337 module and now the uh the module will call uh the save to execute this using the EXA transaction from module and finally the save will actually execute this transaction whatever it does so some resources that can be helpful for you just sharing for repos the first one is the safe smart account uh where you can find the contracts of uh safe all of them are in the safe Global organization the second one is safe modules where you can find the implementation of the save 4337 module and some examples using it there is the safe deployments where you can find where the uh what are the addresses where safe is deployed depending on the networks and the last one the safe modules deployment you can see where the uh safe4 337 module is deployed what networks and what is the address so now let's uh do a quick demo uh sponsoring a user operation with safe and pimo using the permissionless JS Library so there are uh some steps we need to do if you we need to do if you are familiar with uh pimo can you raise your hand okay cool uh first of all we need an API uh an API key that will allow us to interact with Pim Lio API to interact with the different actors of the uh ERC 4337 like the pay masters the banders ETC and we need a private key because we need a signer to deploy a smart account a safe in this case once we have this two things uh the permissionless JS Library allows us to create different clients like a public client we are using uh the nosis uh chain as an example but others can be used so the public client will allow us to query that Network then the bandler client using the uh API provided by pimo and our API key we can uh call the API methods related with banders and the same with the pay masters once we have all these clients uh initialized we can now create Aigner or whatever you want to do this uh but this is the simplest way the the permissionless JS library is providing a function uh private key to account that will generate Aigner but again you can use uh your prefer way and now here is the interesting thing there is one function the signer to save a smart account that will counterfactually uh give us or or it will return a counterfactual save this means that is a a safe object that is not deployed yet but we already know the address and uh to do that we can pass different parameters some of them are optional some of them are not it's important that we use the version of the save the 1.4.1 which is the one supporting uh the CRC and regarding the address and the salnes the salnes is a random number we can use to generate different addresses of our save or future safe and the address uh we can skip it in case we already uh sorry we can skip it if we don't have a safe and we want to deploy it or we can use it if we already have a save and want to initialize it so once we have the safe account object we can create a safe account client and this will work using BM like a wallet client but with our uh smart account now and this is uh returned by the create a smart account client where we are passing some uh properties the ones you see after that we can uh get the gas prices using the badler client and the method get user operation gas price and the last thing if we want to execute it uh we can use the safe account client we initialized before call the method uh uh send transaction and here we can uh Define our transaction if we want to send some 0.00 something native token to a specific address we can uh specify some uh properties related with the gas and we will get the transaction has if we didn't have a safe deployed it will deploy the save with the for 337 module set up and execute the transaction we are triggering if we already had a safe deployed it will just uh execute this uh user operation the cool thing with this is that uh because we are using the pimo infrastructure we can use the dashboard to put some funds there and pay for the transaction fees in all this process and we don't need to worry about that so here we have uh uh well like the the code you just saw uh I have commented the address because I don't have a save and I'm using a random saln when uh defining our user our save so I can just run this and I just have Aigner and some keys access to a network via the pimo API here it calculates the safe address which is not deployed yet and at the very end uh it executes the transactions that I defined previously so that is for the demo and now we have a surprise for you during the hackathon I hope you liked that we are offering uh to you a sponsored user operations so um yes if you are planning to hack with any of these chains like nosis arbitrum base cell optimism or polygon we are providing some uh some codes you can use in your uh in your implementation of the permissionless library uh sorry you can scan this QR code uh this will uh send you to our uh hackathon success guide with this announcement then you can get the the this um this sponsorship policies it's not working okay and um for the hackathon bounties we have two of them we have 10,000 the best one uh which has allocated 8K uh is for the four best applications that integrate the save 4337 module and there are some uh requirements for example deploying or connecting existing safe accounts executing safe transactions and supporting safe version 1.4.

1 and use the save for 337 module those would be would be the requirements for the first Bounty and the second one would be uh uh for the best safe forcaster frame some requirements like deploying or connecting existing safe accounts executing safe transactions and the frame should be uh shared on F on farcaster and available for us to check uh nice to have if you also want to integrate the say 433 module 4337 module uh in the farcaster frame that would be uh great so uh we are on Twitter at safe we have some docs at docs. safe. Global we have a updated them with uh more information about uh the 4337 if you want to check them Discord Forum so thank you very much for attending [Applause] [Music]

Automatic transcript — names and jargon may be misspelled.