# ETHWarsaw 2023: Ben Price, Gelato - Gasless cross-chain transfers Powered by Gelato Relay

- Channel: [ETH Warsaw](https://streameth.org/eth-warsaw)
- Date: 2024-10-07
- Duration: 20:28
- Watch: https://streameth.org/watch/yt-7yPtalf7FA8
- YouTube: https://www.youtube.com/watch?v=7yPtalf7FA8

## Description

Presentation - A brief talk by Ben Price from Gelato. Learn about Gelato's automated smart contract execution service and its benefits for developers and users alike. 

Follow us for more updates: https://twitter.com/ETHWarsaw

## Transcript

uh my name is Ben and I do developer relations at gelato today we're going to be looking at gasless cross-chain transfers powered by our relay service gelato relay um first of all a quick introduction to gelato gelato is web 3's decentralized backend empowering Builders to augment their smart contracts to create reliable userfriendly and scalable web3 applications without sacrificing decentralization and censorship resistance you might be wondering why we even need you know a web 3D centralized backend stack when we already have exactly that in in the in the form of smart contracts um and this is true but as your application grows and you may want additional functionality um you may find that just isn't possible with the current just smart contract stack so the way we envision gel's decentralized backend um stack to look like is we have you know original front end we have some smart contracts but in addition we can use gelato services to for example allow for smart contract automation using gel to automate so you can have Smart contracts execute for example every second or whenever user defined criteria met um you can use this to check a user's Health factor and liquidate them when it gets too low for example um the second service we offer and the one I'll be focusing on in this talk is gelato relay which um allows developers and users to easily put transactions on chain um in a gasless manner so you don't need native tokens in order to do so um the nice thing is this also abstract away a lot of blockchain complexities um you don't have to worry about resubmitting failing transactions you don't have to worry about block reorgs um and you don't have to worry about finding reliable RPC providers um our third service and the latest service is web three functions which is similar to automate in a way it allows you to access and index on and offchain data so you can use this to interact with traditional web 2 apis and push their data on chain a really common use case of this is pith for example where you can push um price Oracle prices onchain um and you might also have some data storage solution other than storing the data offchain um for example ipfs you can use it to store nfts um it's also worth noting that our web three functions are written in typescript and they're actually stored on ipfs as well so we use it ourselves internally um the agenda for the next sort of 15 minutes is to discuss the cross-chain transfer protocol by Circle um also known as cctp I'll discuss what it is and how it works um then I'll discuss gelato relay again what it is and how it works and also how it's useful in this case and then I will discuss what we're releasing which is the gasless cctp SDK this will make more sense as I go through the first two um and then I have a a sort of live demonstration uh I didn't know how good the internet was going to be so it's actually a live video demonstration um but it should suffice uh so first of all what is cctp so cctp is circle cross-chain transfer protocol and it is a permissionless on chain utility that facilitates usdc transfers between blockchains via native burning and minting and this is taken directly from Circle essentially what it means is that it's a permissionless bridge for usdc um the key thing to note here is that it's native burning and minting so the benefits it has over traditional Bridges is that there's no need to lock and mint tokens so traditional Bridges if you're um bridging usdc from ethereum to Avalanche you have to lock up the um the usdc on ethereum and then you get minted some synthetic version of usdc on Avalanche um the way cctp does it is because it's because usdc is issued by Circle we can actually burn usdc and we can natively mint usdc as well um and what's really nice here is we don't have to worry about you know synthetic tokens whether they have you know backing Etc and also we unify liquidity so we don't have you know usdc locked up on multiple blockchains and then synthetic tokens all over the place instead we just have usdc which is burnt and then natively minted um this also decreases sort of the attack surface um because there's no smart contract sort of like Honeypot smart contracts which hold large amounts of usdc now how does how does cctp work um the first step is burning usdc on the source chain um this will emit an event which circle is listening for and observes um and once they wait for a couple blocks to pass um they wait for Block finality and then they issue an Attis ation signature which you can query through the API um then you can go and fetch this attestation signature and use that to Mint usdc on the destination chain and obviously um the amount of usdc you burn on the source chain is the same as the amount of usdc you're allowed to Mint on the destination chain uh and this is really cool but it has some limitations um those being that steps one and three so burning usdc on the source chain and minting usdc on the destination chain both require a transaction onchain which requires native token tokens um and this is a bit of a hassle because you can imagine if you're moving usdc from ethereum to Avalanche for example you might not actually have avax on Avalanche um in order to actually transfer the usdc um another sort of pain point or limitation is that subsequent transactions on the destination chain also require native tokens so even if you somehow manage to move the usdc from ethereum to Avalanche um you still need native tokens in order to even interact with it so the bottom line is that whilst usdc is free to move around chains the native tokens we in order to actually transact or not so the vision that we have um is that imagine we could move usdc between chains and cover the associated cost using the usdc which is being transferred um so on the source chain we can use some of the usdc were burning to pay for the transaction and then on the destination chain we can use some of the usdc were minting to also pay for the transaction um and then in addition to that we'd like to be able to pay for subsequent transactions on the destination chain also using usdc so once we've moved the usdc from one chain to another we can continue using usdc to cover all of the transaction fees um so we eliminate the dependence on Native tokens and that gives us infinitely more freedom the implications being that usdc now acts as an interoperability layer connecting multiple chains and it also eliminates the need for per chain na tokens so in a sense usdc now acts as um a sort of universal fee payment token or transaction payment token um and this is not just a vision this is possible using gelato relay um gelato relay is a relay service which enables gasless transactions on all major evm compatible networks so the networks I mentioned earlier ethereum and Avalanche and um yeah any any network you can name pretty much which is evm compatible we also support um let's sort of zoom out a little bit first of all let's discuss um what is a relay even um by definition relay means to receive something and then pass it on um in our case more specifically sort of in the context of web 3 it's an EA executing a transaction on someone else's behalf so the relayer receives the transaction and passes it on or puts it on chain now more specifically what is gelat relay um gelat relay is simply a decentralized network of relays so of these relays um otherwise known as executors and it can also be considered a Marketplace which brings together two parties the first party being the developers which want to streamline the user experience by making the transaction gasless and the second party being infrastructure operators which execute these transactions for a small fee so it's sort of a win-win um what are the implications of relaying a transaction um the first and really nice implication is that because the relayer puts the transaction on chain and not the user um the relayer also incurs the associated gas fee and not the user um this is really nice because it gives us unlimited freedom and how we want to handle payments um so obviously the relay needs to be compensated but how we want to compensate the relayer is um yeah we have we have lots of freedom in that so transactions can either be self-paying um we can pay for a transaction as it's executing using any sort of tokenized asset so we can use usdc to cover the transaction fee as the transaction is executing um we're not no longer limited to using native tokens like ethereum or avac um the second mode of payment is by having sponsor transactions this is sort of like a deferred payment um where you can top up a balance um this is our one balance service which allows you to pay for transactions across all networks and across all of our services um and the nice thing is that we're no longer restricted to paying a native tokens like I've mentioned but we're also no longer restricted to paying at the time of execution um the second implication and sort of a caveat in a sense is that the relay who's executing the transaction is actually the message. sender um and not the user from the perspective of the contracts that we're interacting with um so one problem that arises and this is just one is that how can we for example approve usdc spending if the transaction is coming from the relayer if the relay were to execute it the relayer would be approving spending of his usdc not the users usdc who requested for the transaction to be executed um so what is the solution could we just have the user execute an approve transaction in advance so put this transaction on chain and do like an infinite approval um well first of all infinite approvals a sort of an anti-pattern which is not very nice um but sort of the main issue is that this requires gas and defeats the entire purpose of this so what is the actual solution and there are some nice standards in place which we can use um among others for example EIP 712 and ELC 2771 um sort of broadly speaking these are cryptographic signatures which we can sign offchain um and that doesn't require any gas so we can use the private key associated with our EA to sign a transaction and those can then be verified on Chain by smart contracts um so rather than um approving an ec20 token we can use permit on erc20 permit tokens um USD is one of which so here's the flow sort of what I explained earlier but in a in a sort of visual form um we can relay the first transaction to burn the usdc we can then wait for an attestation signature on the front end we wait for Block finality Etc um and then we can relay the second transaction on the destination chain to actually mint usdc uh if we sort of zoom in on just a single relay Transaction what it looks like um this is actually for a gas's nft mint but uh it's just a bit simpler to sort of demonstrate but the same applies for the usdc example as well so we can imagine a wallet which has zero ethereum so it's not able to transact um but what the wallet can do is it can sign it can build this mint transaction and then it can sign it using its private key uh we can then send this over to gelato um either using the gelato API or using the SDK we provide um one of the executors on gel's network will then pick up the transaction and then move it from the offchain world to the onchain world so actually execute the transaction um we can then have for example a trusted forwarder um onchain um essentially doing signature verification um it can verify the signature first of all that's the first step and then it can also recover the original signer of the signature so we preserve this notion of like a message. sender and then we can forward all of this to the nft contract which can then mint the nft to the user since it actually now knows who the user is um and obviously I don't expect anyone to remember all of this in in sort of great detail and you shouldn't have to which is why we're introducing the gasless cctp SDK this is built on top of circle cctp and also on top of our relay service um and you can find this on GitHub um github.com gelato digital gasless D cctp um and essentially this sort of exposes a really simple interface where any dap developer can integrate this into their dap um so you call this transfer method you pass an amount of usdc you'd like to transfer including the fee amounts there's two fee amounts one on the source chain and one on the destination chain and you can specify what Max Fe amount you're allowing on the source chain and then on the destination chain respectively um you also provide a chain ID this is just the chain that you want the usdc transfer to and you also pass a wallet um this wallet allows us to sign the transaction offchain and it also has a source chain RPC provider so we can get some um onchain state from The Source chain uh it's also worth noting this is not just useful for Bridges but also if you imagine an nft Marketplace which is sort of avalanche native um but it wants to support usdc payment from other networks like ethereum or arbitrum Etc um it can easily integrate this and it can offer exactly that or whilst remaining Avalanche native um so there's not much work required on sort of the developers end um here's the full code sort of implementing this example here this is the the snippet I showed in the previous slide um and this works there's not really much more to it it um the only additional code is that we instantiate an um RPC provider adjacent RPC provider and we also instantiate a wallet with a private key and with this RPC provider and then we we pass the respective arguments and transfer usdc in this case 100 um so now for the demonstration the the sort of live video demonstration um I didn't have time to make a front end for this but um this is sort of demonstrating in a hardhead project um so yeah in this case we're moving us DC from one second uh we're moving usdc from Avalanche um to arbitrum and in this case we're moving five usdc and we're allowing a Max view of one usdc on the source chain and one usdc on the destination chain um I'm just showing the Wallet balance before the transfer so on Avalanche we have um five usdc and then on arbitrum we have no usdc whatsoever and we can also imagine that we don't have any native tokens on either of the networks um yep so 5 usdc on Avalanche um if I run this so just to reiterate what's happening is that we've relay the first transaction which burns the usdc on the source chain on Avalanche um and once that's gone through we'll see that the usdc appears uh disappears from our wallet metam MOS takes a second to update yeah so the usdc is now gone we transferred five usdc so we're left with 0. five um and now what's happening is that Circle has listened for this event and now it's waiting for Block finality on Avalanche um in avalanche's case it only waits for one block which is around 20 seconds before issuing the attestation signature um and then once we receive this attestation signature we can use that to Mint usdc on the destination chain in this case arbitrum um so I'm just looking at arbitrum now our balance is still zero but um once this transaction goes through we'll see the balance go up um bear in mind we transferred five usdc um and some of it is used for fees so in this case 4.5 usdc has arrived on arbitrum which means that .5 USC was used um for the transaction fee payments both on the source chain and on the destination chain and it's worth noting that obviously this is sort of an absolute value which is the nice thing about crypto in general is that even if you're transferring you know a billion usdc you're still going to end up paying the same amount so still .5 usdc um yeah just to sort of wrap up as a conclusion um other Services which I mentioned earlier we have the automation service which does onchain Automation and it allows you to perform computation without requiring user interaction so we can use this to for example fill limit orders without the user having to you know sit at their PC and fill it manually um we can use it to liquidate users etc etc um and then our second service which is this web3 function service um these are very general functions written in typescript we store them on ipfs and they're run by our um decentralized network of node operators and these allow us to bridge the gap between multiple chains because we can access chain state from multiple chains and also bridge the gap between the on and offchain worlds so like I mentioned earlier um we can push uh prices on Shain like price over prices um and all of these Services can be self-paying or sponsored by our one balance service so that's up to you as a developer uh thank you for listening uh if you'd like to check out our website it's gel. Network U we have a Discord if you have any sort of questions maybe you want to use this during the hackathon you have any questions feel free to ask us on Discord uh Twitter is um gelato Network and my Twitter is Ben price with the V at the end um yeah let me know if you have any questions thank you there are any Tres if we expose API application because can see how we can do this yeah that's a really good question actually yeah sort of unrelated like you said but um yeah exactly um so what you can do when you set up a relay application is you can specify which functions you want sponsored um so if you only want to allow users to for example if it's an nft for example and you only want to allow them to mint and obviously not just execute any transaction and you know use your balance um you can just whitel list this this mint function on your smart contract um so yeah you do expose the API key on the front end but there's nothing the user can do with it other than mint you nft if that makes sense so yeah okay thank you question you um so we're in touch with lots of RPC providers and we sort of aggregate them so if one of them goes down we'll just fall back to the second one fall back to the third one um so that's sort of more reliable obviously you can do this yourself but it's something you'd have to sort of implement manually and it's quite a bit of hassle especially keeping up with like you know who's the most reliable Etc experience yeah it's similar in a way so that's a great question um you can either pay the relayer back as your transaction executes you can transfer some token to a fee collector and we'll check the balance before and after of this fee collector to make sure that you've paid for the transaction um the nice thing is that in this case you can pay using usdc you don't have to use like ethereum for example or any native token and the second thing is that we have a one balance system where you can deposit usdc on polygon and you can use that to pay for all transactions across like any any um any network and also um across all our services so not just the relay service but also you know web three functions and automate Etc and is there possibility for the appc to do that of the US the users don't have to exactly so that yeah so the first thing I mentioned the synchronous Fe payment the user is paying um but but the second one is um this one balance system where you can decide to sponsor the transaction so you can imagine an nft project wants to make the mint free to like reduce or make it like a very seamless experience um you can also Imagine like lots of Gaming use cases um where you just want the user to be able to start playing your game without having to worry about you know acquiring these like native tokens Etc so than thank you very much yeah okay say again Lou yes we support test Nets um we're on gly I think we're launching other test Nets but yeah we we support lots of test Nets you know Mumbai Etc like all the test Nets pretty much um so we we're not related sort of like that we have like a pretty close relationship but um it doesn't relate to Circle anyone can do this in our case we're just sort of demonstrating the relay service um because usually what you'd have to do if you're just using cctp P you'd have to put the trans like the source transaction on the source chain um to to burn the usdc and then on the destination chain to Mint the usdc and you'd be paying you know gas along the way for both transactions so what we do is we sort of abstract that away it's like one click for you and you can transfer the usdc to a different chain so it's sort of a demonstration of both it's built on top of both platforms any other questions okay uh thank you very much
