Decentralizing your web3 backend with Hilmar Orth - ETHDenver
Ethereum Denver·Mon, Oct 9, 2023, 12:00 AM
The web3 ethos of decentralization and censorship-resistance are under attack. Every project that has centralized dependencies faces similar risks of having to limit their operations, censor certain users or even worse, being forced to shut down. In order for web3 apps to fulfill their potential of building systems that go beyond the reach of traditional intermediaries, institutions and nation states, an unstoppable, decentralized computation network is vital. This talk will explore why and how you should decentralize your web3 backend in order to build truly unstoppable web3 applications capable of onboarding with next 1 billion users to web3 without compromising performance & reliability. Speaker: Hilmar Orth - Co-Founder & Legendary Member, Gelato
Transcript
so to the agenda I will go quickly through the backend architecture of most web3 apps today and then how you can build it in a more decentralized way using gelato um I had another talk by the way I guess yesterday um where I went into one of our services in a bit more detail so um this will be a bit more high level regarding like various components that we offer so how do most web free back-end architectures look like today once I started a couple years ago building my free applications what I sort of hoped it would be is that hey I just built a front end then I have my smart contracts and then that's it and all the logic and the state is sort of handled there and I can build a front end on top and it works out of the box but unfortunately that's not the case for most of our three applications and this is because and this is due to several issues that sort of smart contracts have or the features that they don't provide you with and first of all as we also heard in the previous talk smart contracts they can't really self-execute their business logic themselves right so if you would like to execute a smart contract function like doing a swap on uni swap or what not at some future point in time these smart contracts just won't execute that logic themselves right they need a transaction to be sent to the network to then call that particular function and then it only executes um so you'd always need like a basically a back-end server running somewhere that initiates that transaction and gets it mined um furthermore these smart contracts they are unfortunately living on blockchains which are isolated from the rest of the internet so smart contracts they don't know the state or what the data might be on another blockchain or they don't know how to access data from let's say an API right and if you think about let's say you want to do a swap and sell one million dollars worth of ease to usdc you probably would like to know which decks or which exchange you should route the transaction through right and you have services for that like one inch or power swap these tax aggregators that you can use to find the best way but usually smart contracts can't really communicate with that right and so you need some sort of way to connect your smart contracts with the off-chain world and actually allow them to utilize data that lives outside of the blockchain um and then of course we all know that like ux wise letting your users interact with the smart contracts vanilla vanilla like we're sending transactions themselves is highly complex if you want to onboard new users they need to write on seed phrases store their private Keys need to buy eat on an exchange then come in and then they can even start to interact with it so if you want to have a smooth onboarding experience smart contracts are very difficult unfortunately for you and then of course data like blockchains are very hard or very make it very difficult to read especially historical data so if you rely on if your application relies on showing like the prices over time Horizon of the last two or three months then you can't really do that by just like reading the current state from the blockchain right you need to get historical data via events where you have to either run nodes or you have to run like indexes and so if you think about all these problems this is how your back end sort of in practice will look like uh usually so you have your smart contracts you got your front end and then you will have to run a blockchain indexer with blockchain index that's basically just a server which at every block or every time a certain event is submitted on chain takes that data and stores it in like a red sdb for example where you have like a rest API to then query that data at a later point in time on your UI for example then you will have to run like certain processes like these cron jobs these job scheduler type of processes that monitor the state of your smart contract and and see when a certain transactions should be executed right so you might want to buy ether once it drops below one thousand dollar on uni Swap and you need to currently check constantly check the prices there to then initiate the transaction at the right time and initiating this transaction at the right time requires then once again another infrastructure which is the trend action relaying infrastructure which handles like the connection of writing to the blockchain where you send a transaction and then you have to make sure it actually gets mined in time because if your transaction takes an hour to get mined it usually will revert at the end of the day and won't get mine so you need a reliable system there and obviously then you want to get notified when this happens right and you need to get an email or telegram modification or whatnot and then um yeah you have your uh you have to store your private key somewhere in the cloud which is always uh Troublesome and then of course the whole point about of chain data you want to run servers that maybe call apis to then feed that data on chain for you at certain times yeah so as an example like there's this project called arakis um and it does decentralized Market making and should just give you like a sense of what they need right so they have their front end they have their smart contracts which are like vaults um they have like router smart contracts where you can you can enter and exit these walls and in these walls you can earn fees and then there are they deposit money from you in uni swap V3 pools to earn you an apy and so how does their back end look like because we work together with them so we know um so they have like various parts uh one is they have to run sophisticated algorithmic Market making strategies of chain which are basically run um they call like a lot of apis like coin gecko apis they analyze historical volatility volume on dexes all that data is of course not available on chain right you need to access this this data by events or other means of chain and then they need to compute the data and the time at which they can rebalance their liquidity in these walls on chain right and of course they want to present all of that information it is useful to their LPS and users on chain right on their UI so on the UI they need to show them the historical prices of these walls they need to show them the historical returns that LP is received when they entered and exit these volts right and APR calculations are completely reputable to go into as well so there's a lot of math back and forth and then they need to show okay when did people deposit in there when did people withdraw from there Etc and then of course they actually need to send the transactions to run these strategies on chain right rebalancing the pools and once the pool gets rebalanced they need to get pager Duty alerts and maybe a price suddenly dropped by 50 on chain right they need to get notified that this happened because this might affect their strategies and then they have these emergency stops right maybe it's better to just stop the strategy right here before it loses a lot of money and they need to send transactions in that scenario again on chain right so there's very beefy heavy infrastructure that they need to run and of course there's a bunch of problems around that right if you do that all yourself you need to manage scale and maintain a lot of server resources you need to manage multiple rpcs for example Iraqis they're live on like four or five different chains right um and you need to some of these chains are very unreliable RPC so you need to have like three of them um rpcs give you the connection to read and write to the chain right and um yeah you need to fall back between them to make sure you've always a stable connection if you then choose to actually use different sort of service providers you have to pay a bunch of different people um and especially if you have to build applications multi-chain all these servers that you saw before you have to basically replicate them by four and then have to run on polygon and ethereum on BNB optimism um and then what's what's like the Crux of all of that is that actually these developers that are building these decentralized applications or protocols somehow become then again the central part failure in the system because yes the smart contract is accessible by anyone but without all that data with all all of that sort of infrastructure you probably practically as a user cannot interact with it right so basically if that infrastructure gets shut down or you don't get access to that anymore you are out of luck and you can't really interact with these applications like others can do so it's not really a decentralized application anymore and so how do you decentralize your back end with gelato and this is basically what so we have focused on since we started um and what we are aimed with gelato to do is we Empower we try to empower Builders to augment their smart contracts um to create reliable user-friendly scalable web free apps without sacrifice decentralization censorship resistance this is our mission and this is so like how you can think about it gelato tries to deal with a lot of the things that I just explained to you around like automating relaying accessing to off-chain data and helping you basically have one single place where you can run all of this infrastructure in a decentralized way and then have easy to use apis to like other places like ipfs where you can store data retrieve data and so on so you just write your smart contracts you can use gelato your front end and then you combine it with like ipfs or something and you're good to go and how does relative work so what we build is we build a network of nodes that we call digital Auto validators and they run a certain set of services for you and these services to different things I will go into these services in a moment to explain you like the differences there but basically what happens is you've got these nodes and let's say you want to automate the transact you want to automate a certain recurring task on your smart contract protocol what you do is you can create a task on chain that emits an event the gelato notes will pick that up you will they will spawn server resources for you off chain and sort of run it for you come to consensus on what data should be used to execute your transaction for example and then take that sort of science data that means that incorporates what transaction should be executed it will send it to a second party in a system called executors and executors are like these sort of agents that just get your transaction mined on all the different chains very reliable so they get signed data and they just put them on chain for you and then these transactions get routed through like a protocol which like a smart contract protocol which lives on all these different chains and it has some Security checks like hey did these validators stake sufficient jail um to actually validate that the signature that the data is correct um are they whitelisted Etc do they use this right gas price do they charge you the right fees and if yes then this transaction will get routed to the Target contract which then gets mined on whatever chain you want and as like the first big service that we actually started with um is um what we call gelato automate and you can think of it as web free Crown jobs and what they do is they enable you to do trustless on-chain smart contract Automation and we have over 300 projects using this in production already today to do a bunch of different things from yield farming harvesting vaults for example urine Finance or BP Finance or Paka they all use this to constantly monitor their monitor their vaults and then when they can reinvest the fees back into the positions they when they compound their fees they do it automatically by gelato and gelato notes they basically go to gelato they say hey I write a smart contract which defines the conditions upon which I want gelato to execute a transaction and that lets gelato know which data to use to execute that transaction and then they create a task this emits an event gelato notes pick up this event and then run that logic and yeah actually security transactions on your behalf and through this we already executed over 2 million transactions um over the past year for a variety of cool use cases and um yeah this is this was like the first one the second one is simply like part of the automate service which is the getting the transaction mined part and so basically like a you can think of what it's like a writing to the blockchain API um which enables um if you combine it with certain smart contracts you as a user interface to offer your users gasless transactions which is super cool because uh one of the big pain points I mentioned at the beginning was that um yeah the user onboarding experience is very cumbersome and web free right and asking asking your users to actually buy e somewhere to then send transaction and pay for gas there's always a hustle so with our relay service what you can do as a sort of nft project you can just enable gases transactions or gasless nft minting gases nfts transfers um and if you actually combine this with a smart contract wallet like the safe that we heard about before and like an on onboarding web like a web free social onboard SDK like web3 auth you actually have what is called account abstraction out of the box and we actually recently partnered with the safe team to build the safe core SDK that they recently announced which is basically using gelato relays gelato relay Services Under the back in the background to send transaction and you can deploy ignosisafe smart contract Wallets on behalf of the users and combine it with three auth and then you have a really nice onboarding experience that enables your users to skip the whole seed phrase part and having to send transactions and resubmitting transactions all this canvas and stuff and then this is actually what I talked yesterday my presentation about this is our new service that we recently launched which is which we call Web free functions and you can think about them as like taking this automation service that we have to the next level and allowing you to access off-chain data as well to send then transaction on train but not only sending transactions but also do all sorts of other just off-chain logic like sending notifications storing data and some databases or whatever you basically want to do and these are very similar to Cloud functions we call them decentralized Cloud functions and how they work as you can see in this diagram here is that you as a developer like you would have right like like you would normally write a um a cloud function you can just write a typescript file where you say hey please um call this one inch API and if there's one inch API returns that I can buy ease below one thousand dollars then please take this data from the one inch MPI send a transaction and then also send me an email that I just received that I just bought ether below one thousand dollars and then store the amount that I got in like a Json object in locals in in my storage and so you you write that file you deploy to ipfs now this file is on ipfs and now you go to gelato you create a task pointing which is an Unchained transaction which points to that ipfs hash this ipf has hash signals where this logic is located in ipfs and then gelato notes all around the world will spin up this logic run it for you and like so like a serverless way and then come to consensus on the data that should be used to execute these transactions and then once uh as once the search Logic gets executed they will send a transaction and then the school sort of goes through the sort of process this flow that I explained previously and you have cool use cases for that like Dynamic nfts where you can add nfts and you can sort of manipulate how they look like in ipfs and change them over time based on certain conditions and rules you can use like apis like one inch for example or you can say hey I want to resolve my prediction Market or my sort of gambling application on chain when like a football game was like some team one versus the other right so basically connecting your smart contracts with real world data in a programmatic way and coming to an end here we our aim is always as gelato to get as close as possible to ethereum when it comes to trustlessness and security especially when it comes to like the off-chain data that we that we use to then execute transactions on it's it's very uh yeah it's important that the data is correct right and that you can trust these the system so that's why we are just rolling out our staking and slashing system we basically have whitelists of node operators that run Lido nodes for example as well they have to acquire gel and stake it if they misbehave or use wrong data or computation then they get slashed and we're actually looking into further going Beyond just having our governance token as crypto Economic Security we want to for example also get the entire ethereum stake with the Heinz gelato with systems like eigenlayer for example that we're investigating and then we investigating ZK proves that you can submit the proof that you run a certain computation which in certain cases is a bit difficult especially if you go to non-deterministic data of chain but they are like we provide a very flexible system so you can sort of say if the data that I need for transactions non-deterministic you can just rely on one node and say hey this node I trust to do it for me and if you can actually have if you have determinism then you can say hey I need to have at least 50 of the stake for example to sign off on this so this is like on our roadmap which I'm quite excited about these are a bunch of our projects they use us today um amazing projects that really innovate um in web free and really help us drive mainstream adoptions so super grateful to be able to work with all of you guys together and if you're hacking this weekend still we got boundaries ten thousand dollars worth of bounties to use all sorts of our services and build cool applications so yeah definitely come and hack thanks
Automatic transcript — names and jargon may be misspelled.