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

Loading player…

Gasless Transactions: The hard way, and the easy way with Rahat Chowdhury

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

In this workshop we will cover the basics of gasless transactions. We will start with breaking down what exactly a transaction is, signatures, wrapping transactions, and passing the cost of gas to another entity with these techniques. This will be followed up with an example using the new Biconomy SDK to showcase how much easier it is with current tools to implement gasless transactions.

Transcript

both the hard way and the easy way um I think the kind of like note that I'll probably reiterate it a couple times during the presentation is that gasless transaction is kind of like the entry point or I view at least to better ux in web3 um mainly just like you know onboarding folks who have never interacted with web3 before so we're going to be looking at ways to kind of like interact that interact um and I forget words right now to implement that within our uh adapts a little bit about me my name is Rahat I'm head of developer relations over at by economy I've been a former hip-hop artist I've been a front-end engineer for a few years before going into web3 I was a solidated developer for a few different nft projects and got into devrel uh about a little over a year ago now and yeah why are we talking about gasless transactions so gases transactions like I mentioned before again are the entry point it's a better ux and wet three right and a little thing to note about gases transactions they're not completely gasless they're gasless in the sense that the end user that you're serving within your dapps may not have to pay for gas on transactions that they want to execute you can whitelist certain functions on your smart contract specifically for that purpose or for a specific user sub base as well and again the main reason for this is because web3 is filled with a lot of ux issues and this isn't like UI issues there's plenty of UI issues everywhere but the whole like concept of you know creating a wallet to going to a um you know centralized exchange doing some Fiat onboarding getting making sure you have enough gas to do a transaction for someone who is not native to web3 that's a lot of work to get them to start using your application so the agenda today we're going to start off by covering signatures signatures will lead into meta transactions which are what enable you to have those gasless transactions in the first place let's look at an easier way to implement that through improve DX with dichotomy then we'll explore some deeper ux with account abstraction so starting off with ethereum signatures an ethereum signature is basically just a cryptographical proof that a transaction was created by a key holder so off chain this is this would be on your front end you would sign a object or transaction some piece of data using your wallet and using your um private key you would cryptographically um you know obfuscate that and someone on the other end can then verify your public address is attached to that signature which proves that you are the one who originated that signature now signature is going to use a couple different ways it can be used to give permission to do something pass data or prove that you just initiated a specific transaction so one specific way of implementing signatures aip712 this is a standard that you can follow and this allows for both off chain and on-chain verification we'll touch on that just a little bit more and ultimately what that leads into is unlocking meta transactions which are signatures for relayers relayers are what are are the um kind of entity that is going to take a transaction that is signed by some user on your front end it's going to load it up with a specific amount of gas and execute it on behalf of that person so if you kind of look at it like let's say there's a completely free nft mint right someone signs a signature on front end that signature has data specifically about whatever function needs to be actually executed as well as specifications like the nons ETC that is all sent to some other smart contract using eip712 to forward that and you can do that using ethersjs web3js there are built-in functions for sending those um those signatures along and essentially you can have this other entity execute that transaction on their behalf so let's look at it from like the point of view of an inertia 20 token transfer a few things that you need for a neoshd20 token transfer is a sender address where is it going a recipient address a amount of tokens that you actually want to transfer and the token contract that this token is associated with just the basic things to make sure this transfer can actually go through for that transfers I actually become a transaction you need display things a valid digital signature a correct nonce and the gas that you need to actually execute that transfer as listed in the previous slide now potential gas list implementation when we look at this is rather than just you know sending the erc20 tokens what if we just sign a message on the front end with the details of that transaction so the details that were all listed here we take that we make sure that the nonce is included in the signature to prevent any signature replays so whenever you're actually forwarding a signature over to some other entity to some other smart contract one thing they can potentially do is take that signature reuse it over and over again so having that non so checking for that is going to help you prevent the security issue and we're going to look at an easier way if you don't want to do this to actually implement this so on our smart contract we're going to use an elliptical curve digital signature algorithm to verify the signature so the ecdsa.sol is a smart contract that has functions but allow you to verify that someone who has signed specific transactions on their front end you can go through that verify their public key because they use their private key on the front end to actually sign it and then ultimately a relayer is given your smart your function and executing that function on your behalf and sending you your NFC your C20 or whatever it is you want to do so that's this this is a little diagram of like how you can visualize this again the user is going to go to their web3 enabled front end sign the transaction that transaction gets sent to the relayer and that transaction is then sent to the blockchain so doing all this manually is very tedious very annoying very hard so that's an issue as a standard for doing this erc2771 is a contract interface for receiving meta transactions through what's called a trusted forwarder a trusted forwarder is just going to be a smart contract that does a few things for you it's going to verify the signature for you help you protect against signature replays so you don't have to go with and make sure to do that a lot yourself and um forward everything over to the proper relayer to make sure everything is executed so by economy relayers have been doing exactly this since 2019 so relayers and pay masters essentially allow you to take some of these gas complexities and Abstract it away from the users right so what you would be doing on the byconomy dashboard when you are implementing this is essentially creating a gas tank and filling it up pre-filling it up with a certain amount of tokens to pay for gas so let's say you're on either baynet you'd fill it up if you're on let's say polygon you would fill it up with Matic so whatever the your the token is that is used to pay for gas you fill up your gas tank with that and once the transaction comes through to the relayer the the amount of gas is subtracted from your gas tank so you do have to make sure you fill enough gas in there on behalf of your users so this is what I meant by earlier saying that it's not completely gasless it's gasless for your users but you would still have to pay for that on your own um if you want a like a real world example you can kind of think of that uses gasless transactions is lens protocol they do exactly something exactly like this they have a relayer that's um that essentially takes all the transactions bundle them together pays for the gas on your behalf so that you have that sort of like web 2 experience but you're still transacting on the blockchain so a few other things that you can actually do with this are gas payments in non-native tokens so let's say I wanted to pay gas in usdc I want to pay it in Dogecoin whatever it is I can you can have all that set up as well using the same forwarder techniques you can have limits and allow lists so limits you know making sure that you know no one can abuse your gasless functions you know on the front end as well as whitelisting and blacklisting addresses as needed again for security and protection from abuse you also get better gas estimation for my economy so my economy is actually going to estimate all the gas for you we what we do is like we make sure that everything is bundled in approximately 10 percent cheaper than what etherscan estimates might have cost um the way we do this is like we're able to kind of like stick to that like 50 guess or uh um and even if the transaction fails the bundler will just automatically retry that for you so you don't have to worry about failed transactions it's going to keep trying until it goes through so if you want to check out a code example I actually did a workshop specifically on this a couple different times throughout this week that's a bit dot Lee slash Raha Camp Biddle that is going to take you through a um well it has both a front end and a smart contract smart contract was written by wonderful folks over at polygon and what I did was take that smart contract and build out some gasless functionality around it what that is is just like this erc20 token where that can be earned by farmers and rather than having the farmers you know onboard into web three pay for gas we help them out and basically make sure they don't have to do some of those things so check that out it'll give you a little bit more to play around with as well but um coming back to why we started even talking about this this whole concept of better user experience in web3 so when we talk about doing gasless transactions we're essentially going into making sure we're removing one big friction point for anyone who's brand new to web3 you know my parents my grandparents are not going to want to figure out how to create a wallet how to go to an exchange do Fiat on ramping come to your dab like there's like it's just not a good experience for your end users for your customers who are brand new and at the end of the day if you want your customer base lager you're going to have to go outside of our little bubble of web3 so the next thing we're going to introduce here is erc4337 or account abstraction which recently went live on ethereum mainnet I think it was yesterday the day before um so there's a smart contract that has been deployed um on there to help enable some of this functionality but I'll show you a quote here from metallic achieve the key goal of a construction allow users to use Smart contract wallets containing arbitrary verification logic instead of EOS as their primary account so there's two types of wallets that kind of exist you have um your your externally owned accounts like you know your metamask wallets your mobile wallets or whatever and then you have Smart contract wallets wallets that are basically a given extra functionality using smart contracts and one of the things that we talked about here is arbitrary verification logic what exactly is that if you think about the transactions we talked about before other than the data that needs to be you know supplied to execute the actual transaction you need things like the proper amount of gas the nons ETC once all of these transaction like details are met that's when the transaction actually goes through but what this kind of allows you to do is add additional constraints on top of like whatever those are like what if you want to um you know take a look in your mental and see uh take a bunch of different transactions um bundle them all into one to save on gas that's the one thing that's that you can do here you can continue to do gasless abstractions as well you can continue to do erc20 payments Etc Fiat onboarding within your dap all of these things kind of like become possible because now when you're adding whatever additional logic you want there's different things you can play with before actually executing a transaction so it's a little diagram for a construction in a nutshell the main things that we'll look at are key abstraction gas abstraction and chain abstraction so this the user benefits that come from this is a smoother onboarding for folks who are web 2 native you know you can integrate a sign in with like Google sign in with you know any social login and automatically generate a brand new ethereum address for them just based on that sign up uh from from like their web to authorization they don't have to create their own metamask their wallet they don't have to create anything new so imagine like now you have someone completely new to web3 you created a wallet for them you have a gasless extraction for them they don't need to do anything to start using your application right away next thing on here was integrated PF flows so you know adding the ability to pay by credit card to you know pay for gas to pay back credit card for buying an nft all of these things become possible because now again with those additional constraints that additional arbitrary logic you can do whatever you want this is all based on eip437 like I mentioned which is called account abstraction it's a framework that replicates the functionality of the current transaction mempool to a higher level system right so when we look at evm code it's used to implement both application and verification logic of a user's wallet so you can initiate and verify transactions with AAA you're expanding the potential of additional ux designs allowing users to leverage Accounts at a higher level the whole point really the way I kind of look at it is like you're adding additional logic giving users the ability to interact with your DAP in the way they feel more comfortable doing so just giving them that choice so again just like kind of going through what we can achieve through a kind of traction with three social login was one of the things I mentioned uh Fiat on-ramping within your dap both gasless and paying gasoline erc20 so the initial way that we looked at doing gasless transactions was through erc2771 you can also achieve that through account of Attraction you don't need that kind of traction to do it but it is something you can do and then again bundling multiple transactions together to save on gas you can easily Implement any of these use cases with our newichotomy SDK which is specifically an SDK around account abstraction you can get started at by economy.gidbook.io there are a few different tutorials on there but actually recently did a um tutorial on how to use this for doing social login within your dapps and creating the wallets so definitely take a look at that and those examples there will be more workshops tutorials and examples coming out very shortly as well so I would love to open it up for any questions I know we kind of spread through this a little bit I wanted to go over some code but 30 minutes is not really enough time to do that so would love to open up to any questions folks might have okay uh yeah great talk um I just had a question around the relayers um are they all controlled by um by economy is there any like uh risk or like security issues like if by economy gets like goes down or like gets sanctioned or something is that like a risk that developers would have to take on yeah so uh we are on the road to decentralizing that right now it is centralized so you have everything kind of like put up by the economy we are working on um putting out a relayered network so that you would be able to have like more choices on that well awesome thank you all very much for coming to the talk [Applause]

Automatic transcript — names and jargon may be misspelled.