# The anatomy of a web3 application: A janitor’s dream - Johannes Kern | Nerif Network

- Channel: [ETH Belgrade Community](https://streameth.org/eth-belgrade-community)
- Date: 2023-10-07
- Duration: 20:44
- Watch: https://streameth.org/watch/yt-IjPsWtPRQLU
- YouTube: https://www.youtube.com/watch?v=IjPsWtPRQLU

## Transcript

just one second there you go so yeah uh well welcome everyone um thanks a lot for introbook then as he said you know my name is Johannes and I'm with nerif and basically what we do is we make web 3 developer experience suck a bit less and today I want to show you basically why web3 devic sucks but I assume many of you already know a bit why it is the case just because of personal experience and what we can do about it to to change that now how does a d-app actually look like on a kind of more abstract level and if you think about it right you have always some kind of blockchain some kind of back end if you want to say where the data is stored where things are processed which is your infrastructure and then on top of that you have your smart contracts um your business logic your actual application and then the other thing you need you need a user interface or something with what the the users the end users of your application can interact with this set of smart contracts with your business logic now that's just a very abstract kind of representation of of how it would look like but reality looks quite a bit more like this and just a question to you guys who in here is a builder who's on a technical side for me to understand it's a quick raise of hands are cool very good very good so you know that right if you want to build an application that is Rich to use that has more than just kind of the Bare Bones you need all those parts you might want to send out notifications uh you might want to do cross chain interactions you might want to deploy your application multiple chains because you want to reach kind of a wider audience or you want to make it gas efficient because you you know easier might be too expensive for certain certain parts of your application so you put it on a layer two but then you have to move it back and kind of keep those two things somewhat in sync you also might want to have to integrate off-chain stuff or send option things or do just multiple things that's like a real headache and I have a very good example here so you know I talk a lot about tacos I love tacos that's why but so we actually started this kind of as a way to build uh our little uh developer Community because that's what we're all about right we want to bring biddlers together to to build better applications to to have a good time to make web 3 successful and uh when we started this event series and we actually changed that because of exactly that problem we used a tool called unlock protocol now unlock protocol what it is it's actually really cool it's a set of smart contracts and and kind of a use interface which allows you to create event ticketing based on nfts so far so good it enables a lot of things which you can do then with that you know a token gating of groups token gating of future events and and and problem is that the user experience is just not there yet and that is not necessarily unlocks problem that is a problem which we have on the infrastructure side and I'll just show you one one example you know I I can't open that here now but um we had that problem that you can deploy your your contracts on unlock actually across different chains you can you know do it on ethereum you can do it on polygon the issue was that let's say for like a low value event like a taco dinner you don't want to spend 50 dollars worth of gas to make the tickets so kind of mainnet is out of the question so what we did we deployed it on polygon oh so far so good then the problem came okay people wanted to Mint their tickets and actually back then we we charged a little bit first ticket so he was like was it 10 usdt or something and typically you know when do people get those tickets it's when they're at events on the road with their phone they don't use their computers and um we had a problem that well actually I ask you so how many of you have a wallet on your phone everyone okay how many of those who have a wallet on their phone have something on ethereum like some ethereum assets usdt eth on mainnet okay how many of you have Matic on their phone well actually quite a lot that's it's surprising but what we saw is that a lot of people you know they had some eth or something but they didn't really have like also they might have some magic somewhere but not on their phone so they couldn't actually get the tickets because they would have had to bridge those Eve into polygon first and I just broke the user experience completely so it didn't really work we had to stop using it but one of the kind of the outcomes of that is that hey you know actually there's this cross-chain interactions these automation matters and that's what really what we do at ethereum so what can kind of what to do about that right I mean we can sum up those non-core parts right they're not really core to your smart contract they make development a headache they're also really expensive um typically about 20 of the maintenance costs not of development was doing maintenance costs in a large more mature d-app is this kind of keeping this Plumbing alive keeping it up and running updating it just you know working with it and it's very repeatable every application uses some of those same processes everyone wants to send out a notification everyone needs to do some kind of maintenance so we said hey let's automate it and that's what we did so we built narrative Network and what is it um it's a tool which kind of sits by your side as as you build so you know you have vs code or your ID of choice you might use remix for deployment and testing uh you have some you know Security Suite like hard hat or truffle or whatever your you know your flavor is and then you have nerif which just kind of makes those little interactions for example being able to connect a application of polygon to payments on on ethereum mainnet or other things very very simple how does it look like this so it's two parts right we have um built a network which is not a blockchain but it's a it's a separate physical layer and and what it does I think I even have oh that's pretty cool um what it what it is it consists of several nodes and they have a consensus mechanism in between themselves and what it does what it allows to do with uh some cycle not psychological cryptographical Primitives it it works completely trustlessly so those nodes they make sure that whatever you deploy from the app which is what you will just see in a minute um is executed exactly how you program it and you can you don't have to trust any centralized part you don't have to trust don't really run any counterpart to risk you don't run any platform risk on that if you go a bit deeper right uh that's kind of the the very basic consensus mechanism if you will um is that every node executes kind of those smart contracts and not smart contracts those those workflows you deploy and they create a signature um and this signature alone doesn't do much but then we use a concept called threshold ecdsa I'm not sure maybe some of you have heard of it which allows the network as a whole to create an aggregate signature which is valid only if at least two-thirds of the nodes basically provide the same payload and the signature that or their signature to that same payload and the cool thing is this is then verified on chain so you don't have any kind of point of trust you have to have in between in here and it also makes it super super gas efficient so we can run this kind of this whole network and it doesn't causes any gas because all the computations here are done off chain but are only validated on chain and it is as efficient as if you would basically directly um executed on chain with and not have this whole network behind that okay um enough of the theory let's build something so I just want to you know very briefly show you how kind of this whole thing work and and uh what I will build now and actually have a video I'm not going to build it but because I don't have a computer but uh is is a lottery contract and it's it's a game it's it's straightforward it has two functions um as a user you can put money into the smart contract and uh once for example every week we're now going to execute once every minute just for demo purposes but at once every week you want to do an automatic drawing where all that money which is in that smart contract gets pulled and gets sent randomly to one of the winners the winner of the lottery um it is deployed on on polygon Mumbai but the whole thing is cross-trained so you could do that on any chain or even in between and allow players to play from different chains um so yeah so please production play the video oh that's nothing to change here sorry so I actually have to check up here so we have the contract um which you can see it has a function um oops it has I have to see it myself here is it so you have the function enter right which allows you to pay into that application and then you have a function um player success it's just we'll see that in a second which um checks if there's enough people you don't want to execute it for gas reasons if there's less than two people and we have one called pick winner which is randomly selects all of the players and pays out the money to kind of one of them so we have now defined this so we can go to the native application just log in and this is the overview page and we will create a new workflow we'll call that Lottery and all we have here we have triggers so all the workflows are are basically triggered by something it can be event on any chain now we're using a chrome rule because we want to use we want to execute it once every minute so select that configure it once a minute so just put in one one minute there and then what we want to do first we want to actually read the chains so we want to first check hey is there enough players in that game to make it work so we select the chain polygon Mumbai the whole thing is live on five chains so you can really you know mix and match there I'll get my contact address of that application paste it and then I execute these player's exist function and it returns a Boolean called exist and that just you know if it's true it's more than two people so I can do that I are now a condition and I just you know check if that variable I got this exists is true if this is not the case we don't have enough players so we don't want to waste gas so we just we go out and if there is enough players now what we want to do we now want to make a state change so we exec the transaction and we exactly same chain it's polygon Mumbai right because you're only interacting with one smart contract in this example it's the same address now we have to put a gas limit because we're actually you know executing that function and changing the state and we use the pick winner function and that's actually all I need to do to automate that and to have a very rich and kind of fully working uh application on the nerve Network I'm deploying it now to the network takes a while I've just cut it out here actually so that's it so you can see it's going to change to active in just a second perfect so now we have this workflow which is executing once a minute and checking if there's enough players and if there's enough players it's gonna pick a winner so let's do that I will now go to my user interface which is just etherscan I connect my wallet and I execute the enter function with a zero point pneumatic I will then change my wallet and play with another wallet also is here to Matic so now I have two players in that game we can see that in the overview like they entered both and if we now go into the internal transactions we can see nothing happened yet but if we wait a minute and we can go back to see that on the narrow side as well we can see oh now a picker winner has been picked and if we go into the transaction we see that 0.4matic have been sent to the winning wallet and that's the old the whole Magic right and this kind of allows you to obviously build a lot more complex applications as well you can switch back to to my uh my presentation please um and and just kind of have the back end and all that plumbing of your your uh your D app just taken care of so that's kind of what I wanted to show you and I want to open up for some questions maybe have some ideas um or some you know insights and one super important thing the whole thing is live it's currently wait listed so it's not publicly accessible but because you are so cool and all came to my talk uh I would love to give out some um you know priority access codes here so if you kind of go on a wait list and you use that referral code you will be put on somewhere on top of the list and you can get access quite quite soon to to narrative and really try it out yourself and you know always very very happy to hear some feedback from you cool thank you so much two more things after talk and the ones who haven't been here if you have not been approved yet for the taco tonight please come to me let's do that but first let's discuss actually a bit about narrative uh so any questions from from the audience so far all clear voice not sure if that's good or bad um sure yes please uh so to to sum up everything we went through in the demo right now can you compare like what would the ux for the user look like with them without nerif sure so what we let's imagine what we would have to do to build this um without narrative so you would have to have some kind of server running somewhere because the the thing is the the boxing doesn't exhibit exactly execute itself so if you want to do a drawing once a week you have two ways on to do that you can either kind of build a let's say an incentive where um the the contract is built in a way that you know the first person who executed within that time frame gets 10 of the winnings that's what is actually usually being done at the moment where you kind of incentivize those things a good example might be in defy the liquidation mechanisms right it doesn't liquidate itself someone has to actually go there and do it or the other way is as you as kind of the company running this luxury you could run a server where you have a crunch up on top but then what you need to do is you need to either run a note or use a sub graph or a kind of something where where the blockchain data is actually pulled and then every time you have a chrome job which starts that which talks to the blockchain checks hey um does you know is there players in in the game um and then you also have to have a wallet on that server which has some money on it because you don't have to execute that transaction so you have to also build a secure kind of ecosystem where you manage your wallet you have to manage make sure that there's always enough kind of money on that wallet to pay for gas and this is extremely Simple Solution it's a simple simple thing to do but imagine like how many components do you actually to build to just make this work it's yeah probably about 10 too many and then you have to maintain it because you know things are outdated or you have to uh you know keep let's say if you run a node or or depending how you set it up right um or there's like your wallet is becoming unsecured so you have to make sure that the kind of debug fix and and and and and because this is kind of generic infrastructure which we need to have with nerif anyways and most like the whole secure part so kind of the the billing and payment is all on chain because it's a set of Smart Country which wouldn't make sense to build for yourself because it's going to be very expensive from a gas perspective but for us it doesn't matter because we scale it we have the same infrastructure kind of for everyone executing applications uh it it's it's even more secure substantially more secure than running it yourself it's the same idea of you know I was uh I mentioned it I was spending quite some time also in kind of the investment space in the building space and there was always this question well should we have our own servers or should we basically use a Cloud Server and I always claim hey actually probably the Microsoft security Engineers they're quite a bit better than the security Engineers which we don't even have in-house so it'll end up being more secure even though it's on the cloud so it's it's it's kind of goes into the same same direction thank you welcome any other questions so far or any ideas what you could build with it actually very good I think everyone is just you have a question I'm not quite sure if it's the right question because I missed the beginning of the talk but uh probably you know open Zeppelin has a tool that's checking transactions on the blockchain um is full narrative would be suitable for for that or is it a complete another use case to mitigate security or I don't know maybe other use cases it is partially comparable um you could say it's kind of a a small subset of what narrative does so you can in a sense you can build the same with everything or you can build it with the opens I think they're called functions right opens above yeah um but it does a lot more and because you have this separate physical layer this infrastructure um it's kind of more all-encompassing and decentralized follow-ups to that super awesome thank you so much thanks a lot for coming and yeah I'll be down here so if come here come here with your tickets foreign
