Combine Gelato Account Abstraction & Serverless with Open AI DALL-E, to gaslessly mint your NFT
ETHDubai 2023 · 16 Mar 2023 · 53:38
Luis Schliesske demonstrates combining Gelato account abstraction and serverless tools with DALL-E to mint NFTs without user-paid gas. The workshop explores automated, off-chain-aware smart contracts and onboarding.
Speakers
Topics
From ETHDubai 2023, hosted by DeFi Dubai.
Transcript
anyways thanks for coming um yeah so maybe let's start with a quick introduction I'm Lewis I'm the co-founder of gelato and I've been dedicating my life to this project for the last four years and yeah who of you here has worked with July before nice nice any anybody integrated it's yeah I think we're in a process in the process yes and what do you what about you in the back I just played around with your G uni contracts early on yeah pretty fun nice cool yeah that's good old times that's now yeah I hope you didn't get rocked in this holiday world
okay so so yeah um then let's start so um yeah all right so basically today I'm going to talk about account abstraction uh and service with three functions um and basically how to leverage gelato to do a contraction why would you want to do that um well it's very slick use onboarding I will show you in the workshop I don't know how nice it is and uh some of those three function system is really like typical gelato stuff it's gelato ultimate for those of you who have never used it to gelato's original product
um is like smart contract Automation and Battery functions is really that on steroids it's like taking data from off chain like you know calling apis anything you want to do and then triggering smart contract automation based on that so now you can have your smart contracts be called based on anything that's going on on the internet and you can also pull any push it to your smart contractor so what is gelato um gelato is my 3C centralized backend we're empowering Builders to augment their smart contracts to create reliable user-friendly scalable by three apps without sacrificing decentralization where decentralized Network so not just after running these nodes there's more
and more no operators and censorship resistance so quickly and by the way if you guys were at my talk this is not the full talk don't worry this is just the short version of it and then we're going to get to the workshop Workshop immediately afterwards so so yeah basically you can think of um I mean there's this sort of false belief that in what three smart contracts are your back end you just need to put a front-end on it it's true to some extent uh motion for some applications that's true for others but over the long run especially as your user base increases on you need back-end components because my complex simply cannot replace an SQL database they cannot replace a graphql API all this
all of these things and also they're not automated and so on and so basically you know gelato does that for you as a application developer you can now have Smart contract automation you could have guesses transaction relaying and off-chain data sort of connection and now as I've recently um and all of my serverless manner so you don't need to host anything you don't need to run anything you just write the code digital Auto Network and then everyone's and for you and validates it for you and all of that so that's basically it we have the gelato validate us they run your stuff if your staff says it wants to be executed they go and dispatch it to the network of executors and those that put it on chain reliably you deploy many
chains from the average larger protocol on chain some smart contracts regulate the the service level agreement between you and the network basically smart contract rules and then they call the Target contract and that's that's it so now to the workshop um today I want to show you how to Mint your AI generated gelato easy to buy enough team with an account abstracted wallet and also um yeah that's a lot of passwords there so so yeah that's what it's all about account inspection with the gas as well as SDK and server has got three functions using open AI so we will dive into how that works so for now um as yeah I'm not sure how I can share
this link but if you visit this webpage what you can already do now is just go there log in with Google or your data mask just click mint and you can then mint your LST and that's the one I mentioned yesterday and basically um yeah I will show you actually how this works already from here but you can do it yourself as well so let me do a live demo you quickly foreign yeah by the way if you want to you can
also just join our Discord although I don't know how to present the invite link so um yeah but if you join the gelato Network discard if you're in there I can share these things there as well also make sure to enjoy with us actually let me quickly I think I have a part a QR code somewhere I think we can check let's go here yeah if you want to scan that QR code you can join the Discord if you if you want to add links to these resources during the workshop I will drop them in there so so yeah everybody wants to join the Discord please do so now um and then we can I can share all these links in this slides and everything in
there all right let's wait give it 10 seconds and then we're off everybody who wanted to join the Discord got a chance anybody still all right cool nice okay so um now back to the web page so here you are basically what I'm demonstrating is a user experience that is leveraging gelato relay and also safe smart contract wallets were three off for the social login and uh yeah so basically here I'm on a website as you can see like I have
[Music] and I'm gonna do continue with Google that's using web 3 North shout out to them I'm gonna log in with my good Pusher account it's always taking a bit but basically what's happening now for those of you who don't know what three off is using my social um oauth talk I believe to store par a share of a private key at your best and then another share of the project is using multi-party computation while it's similar to coinbase wallet and another share of the key is stored in my browser which arguably isn't the best thing but you know they're trying and and yeah so what has
happened here is I've generated a fresh externally account owned account oh 9999 it's a nice address um yeah so and that one is tied to my social login and also there's a smart contract wallet and here we are using Create two deterministic of code and as you can see here I'm pulling on again there's literally nothing deployed there right now let me review this I know it yes yeah so there's nothing deployed here um and what we want to do now is we want to Mint an nft as you can see 101 people meant it already and here I mentioned the AI earlier so now we can select
whether the AI should generate an nft by night or by day so I already minted one by a day so I'm gonna go for by night this time and okay so now I'm gonna hit mint it's literally just a press of a button like a click sign in equipment and let's wait and see yeah I think Ben yeah already minted uh so so this is the the default the image URL on IPS and if we go here you will see that your smart contract wallet actually has been deployed
and you see that here is an East Dubai gelato NFC in the smart contract wallet and this is a noza save and my uoa that I've just generated via my social login is the owner of that smart contract mode desk account abstraction um you don't have to wait for USC 4337 this stuff has existed ever since smart contract existed but but yeah cool nonetheless um but yeah so oh and the AI just generated the image as you can see before I was a placeholder and now the AI went and generated this image and July 2 actually functions in the back end posted this image into the smart contract and now that's my nft and I
will show you how that's done in a moment so here you can see it's on openc although I've noticed openc lagging quite a lot so sometimes they don't show the pictures properly but here they do yeah I don't know I guess won't make me Rich but it's an nft so so yeah um anybody else minted an nft already using this yeah yeah nice cool cool we haven't got anything planned for them yet but who knows maybe there will be some retroactive uh something um yeah exactly yeah all right so and if you're a developer or in general are interested in what's
going on in the background here's the UI and that is showing what happens here it's showing the serverless what we function that generated the the contract that called uh they called The Mint contract and and so on like there's there's a lot of stuff here to unpack um yeah but that's the web free function interfaces here as a developer if you were running one of these serverless functions in this case a function that calls the open AI API and then pause the data you can go here and we are trying our best to make it better every day get more stats on there get real-time logs on there everything you you used to from web 2 right like we want to bring into web3 um yeah so code there's a bunch of stuff here but I want to go into it now
cool so um that's that's the comment section and the guys as well as you saw it was two clicks one to sign in and one to blend and all of what happened here is like it's by the way this is not dark magic like it's it's not it's fair custodial like we don't like we can't do nft like this thing is in USB contract wallet it's an hypnosis save you're the owner we don't have access to it um what gelato did is it triggered the um the mid transaction the gas was minting uh so here we were basically via US smart contract bullets that we freshly generated for you calling the nft contract to Mint and then the nft was sent to you but there was this
default looking nft and then the web free function went saw that something got minted and sold in the UI right and they posted this new image to the nft dynamic Nifty that's that's what happened so gelato did all of this transaction management and actually sponsoring the transactions gelato here paid for this transaction so you can also use gelato and a lot of Education developers on polygon and noses they don't want the users to pay for gas and you can use gelato very easily to sponsor for all of your applications uh gas costs basically yeah so is that run famously does this work yeah so that's the experience and now let's continue with
the slides all right um yeah so if you want to you can post it on Twitter we have a tweet or on the gelato Network account if you want to reflects your image there generally there please do so all right so what you saw was the card obsession with the gas and what an SDK and I want to show you how simple it is to integrate this on the UI if you want to provide your users with a similar user experience um I mean you know if you want to onboard a lot of web 2 users or the to your dad to your game or whatever I I think part of the reason that we're still not mentioned yet is because we still had like 12 words in phrases and all other crap right like you know I have a lot of nice smart people who
are not in crypto and who get completely thrown off at that stage and they don't want to deal with it right so so let's not do that again please next time um and uh yeah so it's a bit of Stockholm syndrome like I sometimes find myself thinking oh it's not so bad meter mass is okay about it but it's Stockholm syndrome is actually pretty bad if you [Music] um so one balanced bonus light yeah this is about uh basically what you saw here with the um with with the payment right like pulling on this like Mindless transaction right how did it happen you had zero crypto on your wallet right uh you didn't have to go with kyc with an exchange and so on and so how did this happen is basically
um the UI that we have here for the hackathon is has an account with Gelato at one balance account where we deposited some USBC into it and that usdc is used to pay for these transactions with an API key basically very simply you'll make a request to the reader API hey I want to execute this transaction via the user smart contract wallet calling the nft here's my API key gelato will look it up we'll see okay you have a balance with gelato let's go and then later on that balance will be decremented based on your gas cost plus a small fee for the network and even cooler is that technically uh you can reuse the same balance on all networks so you can deposit used to see with gelato and then pay for your users
transaction if you're a multi-channel vacation on boarding on BNB Moses [Music] all right and let's dive into some code um by the way I will share all of these things in the E Dubai Discord channel in our gelato Network Discord um this is solidity code and this is the nft contract and um yeah so basically what happens here is the user on the UI basically [Music]
um dispatches a transaction viaja larger relay and it basically has the payload for this Min function and what gelato does is it calls via the user smart contract wallet and that's what the count of selection is right like you can't call a smart contract via a metamask UA right like the metamask UI doesn't have any code on it so you can't you can just transfer stuff but that's it so here that's Construction we generate a smart Conflict for you your the user is this your smart contract that is the entity that regulates your on-shame interactions for you which is super cool because now you have a programmable agent on channel you also stuff for you like for example asking a relayer to pay 40 minutes right that's normally not possible will be the
most because my conflict is possible so so here here the user is the freshly created smart contract models and that calls the main function on this Min click on the UI and in there it's like typical NXT stuff um augmenting the nft we're setting the token URI to the notreviewed UI this is this default image of gelato event event is here and then the web3 function that's the part we haven't seen yet the backend that does this AI stuff that will later on call back into your nft and reveal the nftp universe your token ID and it will post your um the new image hash for this or the
actual New Image encoding for your AI generated gelato Bots is the buy version and here you see an event metadata data update and this is what the UI was listening to so that's why I first showed me the default image then once this was this happened now it shows you the the real image and as you can see here only gelato can call this function because this is sort of and at this point gelato is like a trusted Oracle because it can modify your energy right and that's why only gelato should be able to call this and gelato off chain has a network of executors metadatas and they have to come to agreement on the data validated all of that stuff like so so yeah that's basically it
um on the smart contract level and that already tells you a lot um at this point I will ask if there are any questions so far I'm still gonna show you how this sort of UI element works and I'm also gonna especially dive into the battery function back end but it's probably the most interesting bit here and by the way the code has been at least unformatted sort of hackathon so on but yeah um any questions so far yeah for the main function and the reveal nft like who paid for the gas fees in this demo right now um I lovely guy called who's in our team I asked him to deposit some usdc into the world balance and he generated the
API key and then API key maps onto his usdc in the digital system yeah uh right yes but Dali or whatever it's called not the chat GPT so how's the the exactly because I agree onto results yeah and that's a very good question so in this example um basically this example we have configured consensus so this is like a trusted example um but normally for example as a user what we envisioned with gelato is that you can create your own custom verifier logic we call them in the web3 function
and then every node on the network has to run this verifier and the output will be like you know either you input the data that you want to post and the the verify output will tell you if it's correct or not and then you sign it and then you know we do a round trip in the network every node has to agree on it has reached a majority Quorum typical honest majority assumption nothing nothing fancy and then you know if the majority passes and you can Define like what thresholds you want then then you know it gets accepted in the smart contract this isn't as good of this consensus mechanism as ethereum or something right but but I think it doesn't have to be at this stage it's better than nothing and people try and innovate more and more you can drop it on the password zero
large proofs something we're investigating we're looking into that too for computation verifications on that but yeah I got a question so when the main function is called who is the address Data Center that's the right question for account instruction because the whole problem um before account abstraction is that if you have a meter mass count as that account is your user identification all the Assets in the application will be owned by that account now if you want to delegate interaction with that application to someone else doesn't work because the application will see someone else is the message so that someone else is calling
and so they won't let let someone else modify the the state of the application on your behalf so that's why it's my conflict like you can get around this with beta transactions right they've been around since 2018 or 17. so they are inside and but their problem is it's quite nasty because then every smart contract out there has to be written in a compatible way it's something called esc2771 [Music] um was pioneered by open Zeppelin and the gas station network and so on and it's it's actually it's cool we support it as well but it lacks adoption because you literally have to go to developers and ask them hey please change your contracts hey please really deploy the normal nightstand right like especially
if you have a good project a really important as a nightmare so so yeah that's why it's a bit of problematic and now to your actual question you don't have these issues with a smart contract wallet because they are like this is a modific wallet the smart contract wallet can verify that the signature of the owner has approved this function call and then can call the app and then now open the app your user contract user account so you all the assets everything stored in the app is in the name of your smart contract account and that's my contract account that's multiple parties call it one other thing is what if you lose your key to the smart contract account well you can add another key before right that we have two in there and then you can lose one spot them out so if you don't have
to you know it's not the end of the world if you lose one of your metamasking friends as we saw so that's the abstraction right like we're removing the basically the entity that is your online representation that's the smartphone right now from the nctv that is controlling us the keys that's that's the abstraction we did whereas in metamask your keys are also your representation in the smart contract right so it's mixed together um yeah it was the same question okay all right yeah so who's working with this you know front contact so is it like are you scoring this uh you know information software and this is actually to be honest done
by red tree off so we are only handling the smart contract deterministic deployment and the relaying and the gaslas and the sponsoring and the AI stuff but but this is the actual first part of the social login that's completely outsourced to webtrilauth and they're doing some magic there pretty cool project yeah all right I have a question on the diagnosis set that's actually deployed so the app is actually paying the gas for two transactions right one of the smart does not sit surpassing is a one-of-one controlled by the eoa that yesterday and then the main thing is happening right yes uh how can users reuse that what method for smart wallet
someone else exactly that's uh that's the the hard question and that's part of the reason why we're not actively adding features to this SDK because we're still not sure if you actually want to enter this wallet again because that's completely something that has to be solved at the interface level and you might have heard of a project called wallet connect they're they're basically trying to solve this issue and I think it's amazing what they do but the reality is I think the ux is still bad like you always have to copy paste the QR code and leave like your tab and so on like a normal you know first and user again it will scare scare them talk about it better mobile so having one simpler answer would be you like we
would need a wallet connect integration blah blah but then you're like basically be open to Old connect um other things are like we need to work on standardization around this right like log in with origin maybe lock it with nozzle sales like openc all these steps need to support that nowadays many depths don't even supports my contract was like you have to sign a message a smart company one two seven one or something for that stuff but um yeah it's I think a long way to go so for the studio space right now with this this smart wallet that was deployed at one time he was thinking full design theme yeah
and we can't take the energy but you also have a hard time no no you can you can look you can interact with it via polygon scan and but you would have to recall the payload for the goals to save entry function is harder and I guess if you want to do something with the NXT because right now if you log into openc like you can't log in with the wallet right like you have to actually know the URL of them you can see it there but what you could do is you could go to the nozzle save interface copy paste to a Smart wallet address and then load the save and then then you have an interface and there will control the nft and so on I haven't actually tried this out but I think this should work UI have to support this social login
right in order to imply and I mean in the full version yes um indeed but but there is a manual version where you can visit the UI and copy paste your business you also say address and load it then you don't have to it will be like in a read-only mode on them you're right yes you're absolutely right yeah exactly you can export the private key from battery off I haven't tried that to go on and so the nfcs have been stuck a couple of months but there's still a new name they're just you know take them to a grade all right um but yeah that's where we got stuck to be honest a bit and yeah yeah that's I think where everybody is stuck because like you're here 437
someone that's all like base layout solution none of them are technically interface and the interface is the real problem actually all right um some spice and takes all right so let's let's move on to the UI and now this looks like validity online scripts yeah all right um so [Music] that's the basically if you want to use this on the UI you're just an inheritance gelato SDK gases wallet and yeah wallet config is nothing other than an API keyword which is the one from one balance that you know you can create you one minute
scores take your API key now you can use the relay API and gelato understands that you have money and you pay for transactions and yeah digital login is just a combination of the SmartWater config with the learning config I think logic config is something from Battery Earth you can find that as well in the code here I want to show this code because it's react code and I'm always on the developed by another one like react so let's move on or do you have any questions and if you leaked your one balance key someone could try to use your money to
pay for their transactions but um actually the way it's configured is for example on the UI you can select a smart contract and a function and only for that will it allow railing and a lot of times people are more worried about trying to get as many people as possible to use the smartphone rate function and not the other way around so like you yeah it depends on your use case if you have a function that only you should use and uh that you only want to sponsor for yourself so this key might be a secret career that you have to completely say but same as with your ipv and so on that's the same time yes um
it's all in our documentation um uh yeah it's all documented and the rate limits are roughly like standard five transactions per minute and then Pro is third Implement although it's not that it's not documented I think actually end of this month we will have a big UI release with dashboard stats uh better documentation and so on and so so that's coming but but and then you can always talk to us if you need more than that we're happy to give you custom Readiness as well all right um but that's the UI part like that's the whole point yeah [Music] now uh like further uh
four uh the mega transactions so you also have something as part of those gas system and yeah actually you're right right oh no there it's coming it's coming so this was the wallet login and now we now we mentioned the decimeter transaction and that's on the UI again some typescript code and if you remember by day or by night and now we're just basically using ethos.js we have our nft contract here we are encoding the mint transaction with you know by day or by night and
um yeah so then on line 84 we have the magic we call it another smart wallet or it says no the safe really but it's it's an abstraction like it's an also save that is basically connected to gelato relay and we call the sponsor transaction on it and we say please call this nft address there's a typo there but I was not pedantic enough to remove it so you have to live with it and you can make a PR um all right and then you know you just uh yeah that's it you can literally on the smart wallet call any contract this nft address you could call any other contract out there as long as someone's happy to pay for it
which in this case someone was so yeah yeah you could do batching um that's the nice thing about using a smart contract wallet you can bash as many transactions as a block as a member with you uh yeah so I guess we don't have this support in the SDK yet but we could have a sponsor or a course maybe your transactions wouldn't be the right word I guess but sponsor calls and then in the rain you can call an nft and then whatever else so so that's totally possible foreign [Music]
that's it now you can sponsor gases transaction for anything out there all right it can be in this case for boss as well like you know the creation box or maybe you know publicize a lot for them to realize yeah so if you don't want to deal with multi-chain top-ups then I could see this being useful although I would say if you're running a liquidation but or something you probably are specialized enough that you care about latency and so on and like we're super fast but like I'm not sure if it's maybe competitive fast so on so yeah but I think some people
have used this for them but but yeah okay and that's the last part of the UI here and that's just tracking that the battery function Dynamics in FTA I generational UI happened here we're just listening to our nft contract you remember this event metadata updated that's the free function that updates it then we will look at now at the end of this workshop and then some update codes um wow yeah but I don't wanna I don't wanna you know it's fine though I think you might as I don't want to introduction it just could do some more line breaks maybe no it's it's nice code and it does something amazing which is
it sets the image and so on on the on the UI um and uh yeah so now we on the UI at the end so um so our AI generator image appears on me that's what this does and yeah what are gelato web free functions so that's the question now like we've seen how to sponsor transactions how to generate a wallet for user with account abstraction with account extraction remember as just a smart contract wallet with a relay app that's it um so that's all been explained and now we can look into webview functions
and that's the magical part of this dynamic nft uh and and yeah so basically how you know how was this nft image generated and how did it suddenly appear in our nft so my three functions are decentralized Cloud functions that enable developers to connect their smart contracts to object data so here we're connecting our nft to off-chain data from open AI show the data is accurate good question earlier in this case it's a bit trusted runoff object computation execute transactions in this case a polygon send notification index and store data in this case we start data on IP address how do web pre functions work well you
simply have to write typescript code and to deploy this to ipfs and then the gelato network of nodes downloads it and runs it for you in intervals or event driven whatever you need and the cool thing is your code is typescript node.js code support which we call any web to API out there get any data compute whatever you need and do stuff with it on chain later on so in this case you got your data maybe I don't know some sports game result for betting side and so on then you publish this on a chain two virtual value protocol which does some basic checks and then calls your Target contract in this case we called an X we met an HTTP call to
either open AI API for Dolly to generate um an image of a gelato Bots with an ice cream in Dubai by night in this case or by day in another case and then we went and once we got this data we published it to our NFC contract and then suddenly it was there so typescript runtime that's the feature very cool simple to use RPC instructions like you could call multiple chains get multiple connections to multiple chains get data from the send transactions to them is all made super easy we have access to secret environment variables so you can actually also use API keys in there if you have a paid account with Twitter or something API you can store
these sequence in there it can be private public code you have clean function State Management which is really cool because you basically get access to persistent storage you get access to redis you get access to SQL databases all of the stuff you could use stored for you the cloud basically in the new set that I start it's flexible paper usage pricing although we are updating like the pricing but it's it's not self-serviceable Network yet but that's all coming soon and very scalable and one of the cool things is um and that's like a true connection here of this web free and web tool is you can actually spawn these runners from it's not a country so you can I don't know have something happen on chain that you don't even trigger like
maybe some user did something somewhere and now here's my contract if it's an event or change your state and then your web reflection better you can react with it maybe see what's happened maybe get some data and respond to it on shame so use case is a dynamic nfts for example as we see in this Workshop but you can also use one Edge power swap install apis um a lot of automate users we had where but the previous version was allowed to automate I sort of sequences is the next step for automate but it's much more than that but but in the through the lens of automate a lot of users like beefy and so on problems a bit with automate because automated restricted
them to on-chain data and one is part of all of this you know data providers in blockchain to give you their routes and now you can use them you can also use other like aggregators like le5 or bridging you could get you know you know Sports data API you can get uh you can talk to chat GPT and post on lens we recently launched this four dials implements and that's something that I want to do there for sure maybe have a lens account that's chat gbt and um multichai NSD limit on us for example so yeah I think we already looked at the smart track part that's not
you don't have to be anymore but now we can jump into the battery function so yeah if you remember actually quick recap the user called the mid function so the smartphone recorder called the mid function and then later on the WebMD function called the reveal nft function right so smartphone right wallet means the nstv battery function backend your servers backend realizes this goes to open AI says I want a nice image for this nftu gets it pushes it via the review nft function URI is just as typical you know ideas whatever um image encoding the web free function that makes it all
possible is the last thing people have in the look at today and for that I'm actually gonna go to GitHub and I'm going to zoom in a little bit maybe just fine as I could also actually open it in and yes code if you prefer that um everything fine with that um okay cool nice so yeah that's the battery function as you can see I mean first of all shout out to clavier and Sylvan they quickly built this party to buy from revolt and they did amazing job
here it works beautifully many many entities in it already so thanks guys if you're listening uh to this on YouTube so so yeah um this is basically a typical index type file it's inside yeah you don't need to know more than that it's attaching file and it's using a package gelato Network web free functions SDK which exports multifunction and with a function context that's all you need for your electric function to work pretty much you can supply it with arguments and so on if you need parameters but yeah ethers typical staff open AI right like people are talking about eyes so again we're using a web 2 service and we're leveraging electric service for our battery contracts which is great right
and if key storage that's just makes nft stuff easier um to be honest I haven't thought much with it yet so some of you might know this and then axios we use to call the API here we have our API for the nft and I don't think we actually need to see any of this other than the reveal nft is what we want to call and then again this code is very unoptimized I know the guys he already sent themselves they want to optimize it later on so so there's a bunch of unoptimized stuff in here but it's been happy as well but but yeah this is I think we can ignore this this is just happy stuff to understand whether the image was already revealed
or not normally this would be written I think in a different way normally we would do it in an event driven way like we would listen to The Mint events and then react to them but here I think they called it up something fitted in there had a different way of doing it which is why this is here [Music] um but yeah so here generating nft properties I think we can forget about that one uh except for maybe in the description and so this stuff here is for openc filtering uh but yeah so here we have this um this night or like yeah basically the user prompt and product so this is what you you guys imported you're only getting two options to keep it simple so that we
don't have to do so much sanitization but at night we're at Sunset and then here's the prompt we give to the AI so here we say a cute robot a robot eating an ice cream with Dubai background and that's your user I thought at night or at sunset templates in the mirror in a cyberpunk r3d video game and pastel 7 colors so that's what we give that's the description uh actually that's the description for openc but I think we also use a letter on for the AI generation and now now to the actual stuff line 35 is where it's at that's a typical word free function you just literally did you use this class battery function online
and you can later later on in order to deploy a Weaponry function you can just uh basically deployments and then you can create a task at the moment it's still sort of coupled with automate but you would basically create a task and then this task would I don't know call this electron function um every so often every minute every two minutes or so but you can use existing gelato layers to create those tasks and so on you don't have to write any that can also for that um but of course we also want these things to be completely eventually solve that it's not just uh yeah so like this one run could also be hey if we if I see something then then call my battery function right for example but for now I think it's very simple it's like time
based intervals so once a minute once every 10 minutes or so and then the welfare function context is the main parameter input to to the this interface and it just has your user arcs this is something that you could have in your task like if you want to pass some some parameter into the function it has storage in case you're using that it has Secrets um now in this case I believe this was deployed with a API key from openair and it has aged allowed to provide abstraction which is the supercharged RPC provider that you know it makes uh you know connecting two chains and getting better sometimes super easy
so here you can see um we have the nft address in this case this is the nft contract so and um then we instantiate this nft address here with the API that you're not the provider and now we're using our storage and this is what I meant earlier with it's it's not that event driven like it doesn't listen to the minivans it's a little bit more elegant of course but for the workshop we have a bit of a sort of an optimized version where actually we just run this every minute and every time we run we sort of get like the nft ID that was last process right so um nft IDs are counters incremental and this function runs and every time you if
we process a new one we saw a store where we left off so that next time when it runs it can see okay is there something new or not and how do we know if there was something you were not we just asked the nft contract has there been newer IDs minted right and if the current ID on the on the nft is equal to what we stored in our on our gelato decentralized hosted battery function and then we just exit we say no there's nothing nothing new was minted right now this is you know again would be cooler to do this event based But Here We Do It checked every minute it's a bit inefficient but still works so you know
so if there is something new again unoptimized we're not even doing like bashing we're not even taking a range of new things like literally this goes one everyone is just one nft that's why by the way it's like a lot of guys uh and girls men at the same time [Music] then you have to wait maybe 10 minutes or so if you're in the last one if there's 10 people ending you're the 10th you might have to wait 10 minutes because literally this function only once once a minute and it can only process one minute Nifty at a time so it's Heavenly throw it a little bit heavily unoptimized most likely we will do an optimized version of this where yeah after after the hackathon here um but yeah here we're saying okay look
we asked this one contract was there a new nft method we checked what our last thing nftid was that we saw was in storage if if there was minted we say okay let's take the last one we have in storage and just increment it right like if we for the last Nifty we saw was number four then we say okay now let's get number five and we again ask our smart contract uh what is the token URI for number five and here that's the hacking part where it's like okay if the token URI is not the the default one uh then we do the magic and just quickly there's another statement down here like okay if it's uh the default if it's not like
if it's not the default one then it was already mentioned and we just store that this nft actually was already invented I think yeah right maybe let's go let's go in first so if if the token UI is not the not reviewed your eyes yeah not video I just means that this is the July 24 minutes right so if it's the default image then we want to do something we want to generate a new image right so here basically saying if the nft doesn't have is the image then let's go here we are basically starting on the smart contract whether the nft is nine or our day so is nine is that Boolean
here and then we generate the nft properties just for openc and now um and here you can see we are reusing the same description for the open AI prompt here we get our open AI API key so again you have access to SQL storage so here you can literally store a sensitive API key and yeah and then get it here and now here we are instantiating the open open API class with the API key um and then we're creating the image and this is the AI part so here literally we're just calling open AI create image
with the description write this this gelato bot either by by day by Night Thing by day by night is the user prompt and here we get the response back from the HTTP API with the image URL if there's an error we do Arrow handling and then we basically get the the image block we downloaded it from from open Ai and we um do solvent ft storage API let's see yeah I think we're using this nft package I mentioned earlier is a helper for ipfs that automatically puts I think I think data for you and so on so I think that's
what's going on here so just again getting another secret value uh getting this nft storage thing which is some project does this nft or storage I think it's some project working with ipfs and then we are generating um um yeah we basically generating this image file um we're storing we're storing it on ipfs underneath here this is basically storing it on IPL s and um and then yeah then at the end we say okay now we have to let the web free flash know that this token ID was processed which says okay gelato network executors
no go and do something and what should they do whether they should go and reveal the nft rising um and here you have the token identity and here you have the metadata URL which is just the link to the idfs hash so that opens you can look at this energy then you see the URL and then they just value the image of my business so after this is returned from the metric function July the Bots will do their magic and call like first of all they run this for you right you don't have to run this as the first magic the second magic is now there's some executors out there might be our mode might be staking facilities node whoever is shows the network could be your node eventually
and um and yeah execute this and the other final else statement is just this weird thing where basically we're checking hey look has this nft already got its AI or mods if it's got its AI thing then then we just say it already meant it so yeah that's it that's what's doing this nft image generation in the background pulsing it into the nftv so that your UI suddenly shows you your 2000 block thing and and uh so does the openc page as you can see here are those how many people use this 108 108 minutes already
today and you see a bunch of bunch of them there and yeah that's that's the workshop I think let's see of course we can ask questions yeah [Applause] [Music] um Can execute as false so also we kind of like how how the end user will be modified as a development yeah a very good question of course we are like actually there's a missing piece here so you can do that is a CLI that you can use to deploy your battery function and create a task but there's like a really
cool UI to build and that's what I showed you earlier if I go to the main page again yesterday again this is now verifying and using multiplier computation to uh to get my private key and then our SDK will tell you watching smartphone what medicine towards private key Network that's a UI to your webview function
so um here you can see task logs you can see you know when like if there are new token so you see here every minute it runs so if someone has minted yet equipment now and you will see a lot appear here so if someone is ask me to get to the stove and the code I think that's yeah that's your function code you can see it here and you can see your executions here um executions of humanity function so here for example this was today earlier so ever since it lasts let's see um
yeah it's going through a lot of network and it's probably ending in nfpr this is not decoded here I won't go to channel you know data data updates here you see this is the last execution 108. so it was this this 108th um not sure who's the own idea about someone might own the 108 one yeah and we want to add more notifications alerts all of that stuff um so that you have as much introspection as possible 105 rights let's see uh that's yours right yeah nice and look if you go through the logs here
um