[ETH Seoul 2023] Building truly resilient frontends for web3 in 2023 by Deniz Yilmaz & Adam Goth
ETH Seoul 2023 · June 2023 · 31:36
Deniz Yilmaz and Adam Goth of Jetstream, an independent product team in the MakerDAO ecosystem, explain how to build resilient web3 front ends. They review past incidents caused by front-end, DNS and hosting failures rather than smart contracts, then cover hosting on IPFS, running an app locally, open source and modular code, flexible RPC choices and redundant data sources. The talk ends with a cheat sheet for judging any dapp's resilience.
Speakers
Topics
From ETH Seoul 2023, hosted by Kryptoplanet.
Transcript
foreign [Music] wow it's so good to be here still kind of crazy to realize that we're in Seoul very grateful so thanks to Erica and the team for inviting us my name is Dennis I'm known as Xerox Dennis online this is my teammate Adam we are with Jetstream jet stream is an independent product team that's part of the maker Dow ecosystem and today we're going to be talking about how to build resilient front ends because that's what we're focusing on at maker we're building open source components that you can use to build and deploy and host and maintain uh open source front ends for the makerdale ecosystem
so I'm really curious like how many of you uh have ever like built of um some some kind of web app or like a front end the few over there of course some teammates but also some others nice that's good because uh yeah I mean I hope this will resonate and maybe we can have a little discussion after after the presentation itself before we actually dive into the details I want to start with some headlines that might be familiar to those of you that are in the ethereum ecosystem yeah some of these are quite bad so I actually hope you're not involved in any way um I'm pretty sure you all remember these this one this is the arbitrum airdrop
yeah that's actually not that long ago so what all of these headlines have in common is that um they were all caused by some kind of vulnerability or single point of failure that's not related to the blockchain or the or the the back end right the smart contracts for operating fine um there were there was actually something wrong with either the front end code or hosting infrastructure or maybe something like DNS or any tooling that they were using and it's kind of the point that we're trying to make because what we've been seeing in the web 3 ecosystem for yeah as long as we're in the space is that there's this hyper focus on the blockchain and smart contracts being like trustless and and uh yeah very
resilient but then we built these these front ends and these apps and we're just using AWS and we're using all of these resilient or these yeah let's say centralized and quite fragile uh um yeah infrastructure and service providers and the thing is this if that if any of those dependencies fail in any way right if there's some kind of uh yeah if it's overloading because you have a lot of users or if there's some kind of vulnerability higher up the stack then that's actually going to make for vulnerable users but also the Dao it can be uh um yeah can be at risk um so we actually believe that we need more resilience higher up the web 3 stack and that's what we're building towards and the good news is that uh
yeah at this at this point in time the web 3 let's say infrastructure and and tooling landscape is very rich compared to a few years ago so yeah there's actually a lot of ways to build resilient front ends which is uh yeah what we're focusing on so we get this quote a lot of times like why why don't you just deploy your front-end code on ipfs right it's that's like a very like overly simplified uh statement I mean it works if you're if your front end is very simple and it just it's just like a static uh web page for making smart contract calls but if there's something more complex that you're working on right if your app is more complex so for example if you have a lot of data sources and you need to aggregate all of the data in
the app and you have to like um yeah use Frameworks or you're dependent on like Dynamic server-side rendering or maybe if you're like depending on on Legacy infrastructure right if you're if your app relies on things that are still running on web 2 infrastructure then you can deploy the client-side code on on ipfs but it's not going to really achieve resilience right you need a more holistic approach so our team we have first-hand experience with uh with this because we've been working on the maker governance portal which is the official governance front end for maker it's quite a complicated application because it's not just a simple front end for making smart contract calls it's actually some kind of dashboard where people can view all kinds of blockchain data but also historical blockchain data
and like metadata that's not hosted on the blockchain and it's obviously a very critical application to the health of the maker Dow ecosystem and also to the users and yeah the app like the V1 was built quite a long time ago before we were really talking about front-end resilience and before we had things like I don't know subgraphs and things like that right so we ended up using centralized infrastructure for some of that and also things like related processes so for example the processes related to managing profile data for the delegates that's kind of relying on on things like get up so if there's problems on any of these
dependencies then that would directly impact our application um and yeah we've been very aware of that and I'm very happy to say that the future for maker is going to be more focused on resilience uh maker dollar has been undergoing this kind of shift on an organizational level but also on a product level yeah there's going to be more published in the upcoming months but basically the new strategy is called endgame and one of the Newfound principles for maker is to have more resilience both in the organization but also on things like front end and also of course on the protocol level as that's what it's uh what it's been known for so yeah front-end resilience is a default requirement in the maker Dow ecosystem as part of the endgame
strategy and we're actually pretty sure that um this is going to be a default requirement for the entire web3 space over the next decade and it's kind of refreshing to see that at this conference we've already seen quite a few talks about building resilient and composable front ends I mean Alias talk that was more focused on the near ecosystem of course but it's just very refreshing to see that we're not only talking about the blockchain and blockchain security but also looking a bit higher up the stack yeah I'm gonna hand it over to my teammate Adam who's gonna talk a little bit more about our approach towards building these uh resilient front ends okay so if we look at a simple diagram here of your typical web3 app you of
course have your backend layer which is going to be the blockchain network of your choice and then you have the front end layer and within the front end layer there's sort of three areas of consideration you have your application code base so this is going to be all the code that's producing your UI and contains the logic for interacting with the protocol in the back end you have your hosting infrastructure so where is this code living where is it being run from and then you have all the data within the application itself which informs the user about the protocol and about the
transactions that they may be about to make with the protocol so we can dive into some of these um so when we're building new apps for makered out we're really focusing on building the app to be compatible across multiple hosting options so of course you're going to have your traditional web 2 hosting uh this is the default this is pretty much how all web apps are hosted um and a lot of times when we're using a web3 app it's our an interface it is still hosted on web2 infrastructure which is fine it works until it doesn't until there's problems but uh so when you're building the app we think it's
important to consider making it compatible for hosting on web3 infrastructure so today that's things like ipfs rweave tools like Fleek that allow you to deploy these applications to these types of decentralized like file storage Networks but this is something you want to think about from the beginning because there are some limitations if you want your app to be able to function properly on these in these environments for example like you can't rely on having a web server or like doing any kind of server-side rendering for your page so you're essentially just serving static pages and so when you're building and
designing your app these are things that you want to consider ahead ahead of time um in addition to using your app on a hosted server somewhere or network somewhere we think it's also important to give the user the ability to run the application locally on their own machine and not have to rely on someone else hosting it for them somewhere so um usually this looks like cloning the repo for the project from something like GitHub doing some small configuration and then using the command line to run that locally and if you are familiar with these things it's usually not super complicated especially if there's good
documentation but you do have to be familiar with like using a command line and not all the users um have that technical experience so taking this a step further we also decided let's see if we can get people a way to run the app on their machine and you know a local environment but so that they don't have to know how to use a command line and so using a package that was created by virtual it's called PKG um we actually found a way that you can from the project output like a single file that you could then make available for the user to download and um
once they have this file all they have to do is open it on their machine and the app should work the same way would work in a hosted environment so I have a short little demo just showing that um the really simple script it basically just takes the uh the built website like the folder with all the files for the app and then uh produces these files that they can run and if they download that all they have to do is open the file it'll open up in their browser on their local host and assuming it was configured correctly ahead of time everything should just work out of the box for the user and it's running on their own machine they don't have to worry about um yeah a hosted instance of it somewhere
um so yeah the takeaway here is like give your user some options make sure that it's not the apps not only available in one uh specific place and if that goes down then there's no way to access that application moving on to the application code base um there's a few things here that are mostly standard best practices in the space but of course you want your application code for the front end we believe it should be open source I mean these are applications that handle a lot of financial value um everyone should have an idea of like what what code they're trusting when they send these transactions um and it helps to have obviously well
documented code base so that it's easy to read for someone who's just jumping in and wants to see what's going on there as you mentioned it should be written so that the configuration is not overly complicated um hopefully doesn't rely on like hard to obtain API keys or database credentials things like that and then modular and extensible code so an example of this specific to makered out is that um when interacting with the maker dial protocol there's a lot of smart contracts involved and it requires like a good amount of time to familiarize yourself with all these contracts um which functions to call and how to call
those functions like passing the arguments that are formatted in a certain way and there's really a lot of overhead there if you're not familiar with it and so we abstracted a lot of the complex logic into these easy to use react hooks into its own package um so things like interacting with uh governance interacting with vaults DSR almost anything related to the protocol we're providing a package of react hooks to make this like pretty straightforward for an average person or average developer I should say and um yeah so if someone wants to make some additions to the existing code base it
shouldn't be that hard even if they don't have that pre-existing knowledge of the contracts that need to be used and if you wanted to build a new front end to interact with the maker protocol in any way this should make it a lot easier I mean you you don't have to spend all the time learning about the contracts behind the scene so the idea here is make it easy to replicate these front ends make it easy to make changes for Developers and then lastly uh application data is obviously an important part of the app and there's a few different types of data that you have to consider when you're loading data into the application so start with
real-time chain data this is kind of the most straightforward this is going to be data that you're getting like the live state of the blockchain you're getting it directly from an ethereum node or yeah this is typically inferior or Alchemy or something like that but when you go to an app like uniswap or something for example you don't really have a say in which node that you're sending your data to it's usually provided by default um Pi the creator of the app and usually that's fine but there have been times where like certain nodes go down or certain providers are having a hard time handling traffic and so we uh decided it would be a nice feature to
have if um the user could in their configuration maybe set their own RPC node that the application will talk to so have a short demo for that as well this is um this is just a page within an app that pulls uh price data from maker oracles which is stored in smart contracts so it's just a simple call to read smart contracts value you can see that um by default it's going to cloudflare eth which is uh a public provider that's available but if you navigate to our settings page um there's an RPC section and for each chain within the app we
have an option where you can use the public provider or you can change that and put in a custom one and you can actually send a test make sure things are working you can see there that it went out to we put in an Alchemy URL here and now if we navigate back to our application and go back to like the oracles page you can see that it's fetching the data but now it's it's sending those requests to the RPC URL that we inputted um so yeah it gives the user a little more um more freedom in into where they want to actually get the data that they're they're interacting with um on the page
next you have index blockchain data which is uh like your historical data so these are things that happen on chain but was maybe a week ago months ago years ago and uh it's this data can be pretty difficult to like fetch directly from a node it's not that efficient um you you might have to sift through logs and logs and logs until you find what you're looking for and so the solution to this on almost every app is that if you know you want this data from in the past then when it happens throw it into a database so that next time someone comes to the page all we have to do is ask the database like hey give us
that information it makes for a better user experience but like if you think about where that data is sitting um like for us and uh on the governance portal the solution that we came up with years ago was to have a monitor to watch for these events and when it happened we put them into a database but that database is just sitting on uh AWS server and um you know AWS yeah it's online most of the time but it's possible that it can go offline AWS AWS has had outages and another thing is that if people want to run their own version of the application um they need they either need access to this database so it has to be totally open or they need credentials to read
from it um and it's not easy to for them to create their own copy of this database it's um it's hard to do and it you you know it's it's also expensive so we found that a stronger solution for historical data is to use a network of decentralized indexers there are a number of projects working on this I think some graphs from the graph is like the most well known at least at this point and they do have a hosted service which is which is basically probably sitting on AWS server as well somewhere I guess but they also have a decentralized network that they're building out which is which today works and so
we find that this is a much stronger solution uh for building yeah resilient decentralized front ends because it's no longer relying on one database sitting somewhere out there that if it goes Offline that data is no longer available but now it's an entire network of people that are indexing this data for the users and if a person wants to uh you know create their own application for the protocol and wants access to this data it's there it's oh it's you know it's on the decentralized network they don't need um they don't need an API key or they may need an API key but they don't need like credentials or something it's not it's an open it's an open database for
them so um lastly we have off chain data which is a lot of times like used for metadata an example of this within the maker context is uh like for vote delegates uh vote delegates are represented by a smart contract on chain which allows people to deposit tokens into it and then the delegate can vote in the protocol with those tokens but the contract itself contains no no information about who that delegate is so things like their name their profile what they stand for and people who are delegating their tokens they want to know this stuff so
we have to find a way to attach information to them and often it's pretty expensive to put all this data on chain so people end up using um yeah any kind of content management system really like could be GitHub could be I don't know whatever CMS you can think of but um yeah we use GitHub in the past for attaching uh data to delegates and then we have run into issues where uh either GitHub was down or we were getting rate limited trying to ask GitHub for that information and so you know the smart contracts were still there but anyone who came to the portal wouldn't know who they're giving their tokens to so
um we did some research to try to find for a more like uh resilient solution to this and what we came up with is leveraging a decentralized file storage Network like ipfs um the reason for this is the barrier barriers to the barrier to entry for ipfs is pretty low compared to some of the other solutions that are similar it's very easy to run a node and pin files and there are also a lot of pinning services available that are not that expensive that you can also leverage too so you can have multiple ipfs nodes pinning files for you and then there are also multiple gateways to access this so
um you know that if one node goes down there's likely another one with this file and um as long as you know it's pinned somewhere then you should always have access to this file uh there's one complication with this is that when you store content on these uh centralized file networks like basically they give you a hash which serves as a Content identifier for being able to find that information or find that file and it's immutable and metadata is often changing so what happens then if you want to update um the metadata someone's profile or add
some something new to the file um you can't really modify the file and still know have the app know where to find it in the app code itself so a solution we found is to attach this data about about the latest metadata unchain to something like an nft and so like ens domains are nfts and you can attach uh like text records content hash to these nfts and so we have a system now where uh every time we update our metadata for the protocol we send a transaction to a protocol owned nft an ens domain and we store a reference to the latest
metadata so when the app loads all it has to do is check this nft get the latest um ID for the latest metadata can fetch it from ipfs we know that it's going to be available because it's uh you know stored on multiple nodes and this way we have a way to be confident that the app can always have this metadata available even though it's not directly on chain we only have a reference to it on chain um yeah so Adam just talked about um off-chain metadata and also talked about how to use things like nfts to yeah to make that uh happen in a more resilient way another approach we've
been looking at is uh trying to understand how we can potentially move some of that off chain metadata actually on chain there's actually quite some tooling that you can use for this for now working with the hats protocol team to try and understand how we can move some of the governance metadata for maker Dao actually on chain the cool thing is that so the thing that ads protocol has built it's like an nft standard for tokenized roles and and responsibilities so instead of having some kind of off-chain metadata set that describes all of the roles and like things like names and profile pictures of all the actors in the in the in the governance system you can actually use something like this
um so yeah the the truth will always be uh uh will always be on chain and then you can have a subgraph index the the heads tree and make sure that you always have like an up-to-date version of the of the truth right of the organization in that sense and you can even take this a step further by then also using this for things like multi-sig access and like maybe even Discord access so you can really use this as some kind of like um yeah way to map out and manage your your organization and what's especially cool about this from our perspective is that you can also have a more granular approach towards managing the metadata because as Adam said like the metadata often changes right that's that's the the main thing about the governance metadata
especially um so if you can have for example delegates and voter committees manage their own metadata Fields like I don't know like names biography that kind of stuff then it's going to be uh you're going to be less reliant on some kind of mandated actor or gatekeeper to manage and upkeep all of the data and you can do that in a more granular way and also have it represents on chain directly so that's another thing we've been we've been working on yeah so another important principle here um is to be very transparent about which data sources your app uses and maybe also let users decide which um yeah which data sources to trust like it really depends on who you're talking
to if you're like talking to some kind of anon death who is very keen on their privacy and they're they're really they really don't like trusting any let's say infrastructure layer then they should have the the option to uh yeah to to only use those data source right or at least be informed about the fact that they're using other data sources we came up with this concept called trust levels which is a way to like uh explain to the user the Reliance on certain data sources and also the degree of risk that you're taking or the degree of trust that's involved um for that data source yeah so we have a quick demo of this concept what it looks like today but still evolving but if uh we're on our
delegates page here and as the uh Mouse moves around you see the screen indicator you can click on it and it says data source information tells you um this data is sources not directly sourced from on chain but instead from aggregate data from centralized or decentralized indexers but then it actually lists exactly the source of the data that's on the page and so in this case it's coming from a sub graph and it says trust level one um yeah you can actually go to the source but if you click trust level one to see um to get more information about it it'll tell you like what trust level one means and then you can view the settings so here within the settings uh you can read
about the different trust levels that we've defined and you can also change them so by default the app has the highest trust level it basically says we trust anything that the developer has put in here but uh it can be changed you could maybe say like I don't want anything from like random third party or go down as far as like I only want data that is coming from a call to a node an RPC node out there and so if we change it back or we change the level to zero if you navigate back to the delegates page now you see These Warnings around and it's pretty obvious okay like what is this and if you click it it says you know
this data includes sources that are not trusted by your current trust level of zero again shows you the source but highlights that like you have you've said that you don't necessarily trust this data source and so it's still something we're evolving and working on the ux4 but um yeah the idea is like being very transparent about where the data is coming from yeah and this is obviously a proof concept app so it's still uh yeah we're just using this to explain what we're working on but yeah we're really looking forward to yeah implementing this further in the app and also like more granularly so you can really I don't know like hover over any data points that you see in the app and then immediately understand where the data came from uh have a way to easily
explain like the amount of trust involved for that data source and also allowed to immediately like a few that that data foul or whatever in in a different environment so yeah to wrap it up um basically it's all about redundancy right so we talked about having compatibility for a range of like hosting and delivery options so that both the front-end operator can decide like do I want like a fully regulatory compliant web to hosted instance but you can also go like the decentralized route and and use web free Tech or maybe even distribute the app to users themselves so that they can run it locally without any dependencies on hosting
also make the code very easy to fork and deploy right so make sure it's well documented make sure it's it's easy to configure so that you actually don't have to rely on a single instance and you can expect the community to pick it up and Fork it and make some tweaks and actually have some kind of ecosystem that's really what we're trying to achieve for maker also for your RPC right so make sure that you allow people to to uh yeah to make changes to which RPC they're using maybe even make them aware of the fact that they're relying on an RPC endpoint provider and for the decentralization Maxis allow them to connect to their local eighth note um of course leverage web 3 stack further up the stack right so if you're dealing with uh multiple data sources to try to find a way to uh not rely on
centralized web 2 infrastructure which is very prone to things like outages but also like censorship and make sure that um the um let's say platform or tool or infrastructure that you're using make sure it's redundant right for example we talked about ipvs we've also looked at some other file storage networks in the space but ipfs is definitely the most mature one right it has a lot of gateways and there's there's a lot of redundancy inside of that ecosystem and that's really what it should all be about it should all be about redundancy in that sense and that's what the the approach that we're taking for maker we want to leave you with this little cheat sheet that we've made like you can use this to assess the let's say
resilience of any uh front end in the web 3 ecosystem so I don't know if you're using if you're in crypto you use adapt maybe ask yourself these questions try to understand Audi app is working right and where the data comes from and yeah this will make you more aware of let's say the amount of trust involved when you're interacting with adapt right because even in crypto you're not talking directly to the blockchain right usually you're using this app which is usually very complex it's not only like a static front end for making calls it usually involves a lot of data sources and a lot of Reliance on infrastructure and yeah I think the first step is for us all to become more aware of this and more critical
and then hopefully uh yeah as we said before front-end resilience will become a default requirement for the space yeah so if you want to stay up to date about our work and also uh yeah make sure to know whenever we launch the front ends for make a dial follow us on Twitter where jet stream XYZ we literally just let's say rebranded our team so we published our proposal to the make it out EC system yesterday so it's quite exciting time for us um yeah and we're now happy to take any questions or maybe have a little discussion um about the subject so thanks a lot foreign [Laughter] [Music]
Related talks
- Who Can Turn Off Your Ethereum App? A Full-Stack Walk-Away Test
- Using Holochain as a Validated Data Layer for On-Chain Transactions | Joshua Vial - Holochain
- Fully On-Chain: Internet Computer
- David Vorick : Decentralized Frontend and Storage Hosting for Dapps
- Decentralization Is a Lie (Until This Works)
- Making IPFS Work For You – Matt Ober
- Juan Benet - Building Web3: Filecoin + Ethereum Better Together
- Decentralized application and devices with Aleph.IM and Ethereum
- TrueBlocks Workshop | Thomas Jay Rush | ETHDam 2023
