New Ethereum talks, every Monday. The week's conference uploads by event, in your inbox.

Loading player…

Skynet Labs 🛠 Building Decentralized APIs on Skynet's Decentralized Storage

ETHGlobalSun, Oct 9, 2022, 12:00 AM

Join Daniel Helm of Skynet Labs for a workshop titled, "Building Decentralized APIs on Skynet's Decentralized Storage." This workshop is part of ETHNewYork 2022, a three-day in person hackathon that will feature hackers, mentors, enthusiasts, sponsors and speakers who are all gathering in New York June 24-26, 2022 to talk about the future of money, finance, the web, ownership, the way software works and the way power is distributed. We're excited about a new frontier. ---------------------------------------------------- Follow us: https://twitter.com/ETHGlobal​ Check us out: https://ethglobal.co​m Email us at: hello@ethglobal.com

Transcript

[Applause] [Music] so for centralization and storage we're looking mostly at application data this might be about the user this might be about a collection of users and with this centralized storage we can oftentimes think about this as like application front ends too um we don't want to necessarily host our whole website on aws or versailles or whatever else and this is a little bit what skynet is known for is our decentralized storage but we can also look at centralization and compute resources which is where this talk's going to go eventually and we can think about things like apis that work over that application data and for our kind of model here we can think about this as our application back ends of course this is the off chain back end typically our compute a lot of times the smart contracts is going to be on chain but there's also other apis that get utilized all the time that we can focus on decentralizing and skynet is our magic bullet for solving these things so i want to talk to you a little bit about what skynet does and what we're building towards and so i'm going to talk to you hopefully only about 10 minutes about skynet and then show you what it looks like to use skynet but first as a primer for what it looks like to you know how skynet's built i want to have a little diagram here skynet is built on the scia blockchain it is an application specific blockchain focusing on decentralized storage and it has hosts on its network and it also has renters and on skynet we have individual users in their web browser and on skynet what we can do is have a user take a piece of data this can be an image it can be a video it can be their user profile data and they want to send it to a skynet portal like skynetfree.net that data will then get broken into lots of little chunks and stored across a lot of hosts on the cya network once that's done once that data is persisted that user will get back a sky link if you're familiar with ipfs this is similar to a cid it is immutable it's like a fingerprint for that file it is a way that the user can later verify that the data that they're getting matches the data that they're requesting and with the skylink they can pass that to a friend it doesn't have to be isolated to that user so now we have user b they have the skylink they say hey fileportal.org totally different skynet portal not run by skynet labs i want this file what happens is fileportal.org has a connection with a bunch of hosts it will you know select some that are the fastest it'll grab enough pieces to reconstitute the original data and pass it back to the requester okay so this is kind of what immutable data on skynet looks like we have a mutable data layer too um but talking about decentralization and decentralized apis there's something interesting here right on the right hand side when we're still in the blockchain world all this end to end is verified through typical blockchain stuff but when we start using browsers it gets a little bit weird and if you noticed i was being a little cagey with my language the skylink is an identifier that means that the data is verifiable but that doesn't necessarily mean the client is verifying it which brings about a question right are we just putting our faith in the portal at that point it might be open source or whatever else but do we have a centralization point happening there let's kind of look at an example we've got a user they've got this file and they use chrome because they love chrome and using chrome they request this skylink from badportal.org badportal.

org not surprisingly returns out bad data but because chrome is dumb it doesn't know anything about web3 and the protocols and the protections we've built it's going to just pass back this bad file to the user and the user goes on their way um but we could do a thought experiment right like what if chrome browser did understand web3 primitives and the protections that those can grant a user and and you know incorporated them in the browser and what that might look like is that our request goes out to badportal.org we get back a bunk response and the browser's like hold on i know that this is not the right data because i can verify this with the skylink so let me go reach out to another portal hopefully they won't lie to me or censor the data or whatever else the file comes back it gets verified now not just verifiable and the user without thinking about portals or anything else gets the data that they need in a fully decentralized fashion okay so skynet's not building a browser don't worry i know that's always the quite a task for some engineers um but we've built something called the kernel and so what the kernel is is it's either run as a browser extension or in an iframe and it is able to load code hosted on skynet and it will pull that code verify the code and then run that code as a decentralized client-side api and lots of websites can share that code so what does this look like in practice well we have a website our kernel and our portal and let's say we have greatscap.hns that's one of the naming services we support it's handshake and so the application in its code we'll say hey colonel use the module for doing uploads to do method upload okay and it'll send that request to the kernel the kernel knows how to handle this and so it's going to load that you know blob of data run it as a web worker pass on that request to the web worker and say hey i need you to do upload and this was requested from you know greatscap.hns and then this blob of code we'll know how to handle that it'll talk to the portal it does all the verified's fun and eventually gets back to the browser in a protected safe way fully verified end to end fully open source and fully permissionless okay what if we wanted to get a little bit fancier well the kernel also has an identity layer where you have you know a seed and public private keys for doing updates and signing messages things like that and so we might say to the colonel hey i will need you to use this module located at this skylink to do the action registry update but the module needs the user's key but we don't trust the module with the user's key the kernel is the only one that gets to have the user's key and we definitely can't trust the client side application because anyone can deploy that very trivially onto skynet so what happens is the module says all right i need a key colonel can i have one the kernel will create a derivative key a brand new key just for that module and then we can do our signing and our interacting with the portal and so i hope this gives you a little bit of a sense of what it looks like for our vision of creating a decentralized api where we can still do authentication we can still do access control from you know modules calling other modules they know the identity of the caller or what the host website is and let's see a little bit of what this looks like in code because you're hackers you're here to code so what you basically have to do this is the module code for a very trivial module but you'll clone a repo and you have a file where you start writing out your code and aside from this boilerplate basically we have to add handlers so the requests have a method um and this method is called sayhello and then we define a function that handles the requested methods so this function is called handle sayhello we'll log some data and then we respond to the query with arbitrary data and here it's an object with messages of the key and why hello as the value from the client side in a react app or wherever else this code is real clean and simple and so you import this call module you want to have the skylink of the module which we here should have as a constant and we say await call module so call out to the to do module we want to do say hello and pass along some arbitrary data or action or whatever else we'll await the response grab the message and be able to use it and so you know getting started building these apis is actually not that complex we have a pretty tight build pipeline where you're able to quickly deploy these things to skynet just using your cli and iterate against it but apis are made to be consumed right for the most part we want more people consuming the apis than producing the apis and so how can we do that i've already talked about saya skynet skynet kernel i know it's a lot going on so let's look at what these layers of abstraction are on saya we have this fast and secure data storage and a decentralized blockchain that is still private though so we need to make this accessible to the web which is what skynet does and then to make these rich applications for web 2 developer experience on web3 we need to enable identity and shared code execution which is what these skynet modules can do these kernel modules excuse me can do and then lastly what we're seeing is that people building these kernel modules then just write normal json libraries that wrap the annoying call module or whatever else right so we're going to see a few of these in the demo but the idea here is that we can do another layer of abstraction so it just feels like interacting with javascript code for the end user the end developer the user doesn't really have to know too much that even a decentralized backend is supporting it and we can empower really powerful decentralized experiences where users can share their data across different apps in a safe private way okay so let's build a social dap on skynet so modules tend to isolate and separate out specific types of behavior and so we for building a social application are going to need something for identity we're going to need a social graph we're going to need a feed of posts from those users and we're probably going to want everyone's user profiles so we can have pretty things like avatars and bios usernames so there is a set of developers in our community that have published skynet dax library that is a one of those wrapper libraries so you don't have to deal with call module or anything else these expose methods for interacting with these abstractions on skynet and if you want to follow along or follow along later or want to take a picture this is the github repo of the code that i'll be working with in the demo and let's build okay so let's take a look at that repo sorry about the plosives um are folks able to see great i think that seems pretty good okay so i'm in this hackathon ideas workshop and this is the code i'm working against here and i want to show you that as a react app i've already built out all the ui elements so this is just mock dummy data this is not coming from skynet at the moment but this is what i want to build so i want to start off here i want to build an idea hackathon idea decentralized web app where we can have people join a social graph of hackathon participants and mentors they can create new ideas and then see a feed of existing ideas from other folks in the hackathon so that new idea page will be over here and i can put in some details and if you take a look at the repo later you'll notice kind of everywhere these wires everywhere that i have these kind of mock statements but all of the logic for dealing with the kernel and these decentralized apis is going to be in this hooks folder so basically all of this is ui stuff but we're going to really focus on authentication and then using these social modules so let's take a look at this right now i am basically to do authentication i have to use the functions in the lib kernel library which is produced by skynet labs and first off we need to load the kernel so this is our bootloader and once we do that we'll set state in our ui to say the load the bootloader is loaded so let's kind of just start stepping through this actually what does it look like when we don't have a bootloader loaded let's start from the very beginning here all right so the bootloader is not loaded bootletter lids pretty fast so we'll get rid of these skeleton elements and our bootloader is loaded once our bootloader is loaded our user is not logged in so we have to provide a button here to log into the kernel again i'm just kind of showing the ui and login flow here but then once they authorize with the kernel produce their seed then the kernel will load and we'll start kind of preparing to load in other data and once the kernel is loaded off of skynet the code that does all this protection then we'll be fully ready to use this data and again this is just mock dummy data for now but what does it look like if we drop that off and actually call the necessary functions for interacting with skynet kernel so we await an init that's our bootloader and then we basically await a promise from login complete so whenever the user is finally logged in then we can start doing some stuff in our application so these are just kind of fairly boilerplate honestly if you want to build a react app following my example here so let's go ahead and save i'll do a hard refresh over here and now in actuality i will be calling out to skynet to load that bootloader load in a kernel and get going with it okay so now if i've done my authentication correct now the user is authenticated and i can start interacting with these this library that exposes all this social behavior so as i mentioned before we have identity which gets us the user's id in this public decentralized social network it's a ed25519 pubkey and um we can use that to then look up their profile look up their social deck and look up their feed deck so they're this is their friends list and this is their list of posts and you know i'm not going to use any post here we're going to have some selective elements where we modify which posts we actually want to show or display and so instead of returning the photographers or distracting instead of returning this kind of mock data for our profile let's start using um the use dax hook to actually expose real behavior that will then export to our ui okay so right now i'm returning early with mock data let's comment that out and now if i reload by app what should happen is i should load my bootloader we'll temporarily see the kernel loading and once that's loaded now that decentralized api is going out grabbing my profile data that i was you know on my own assigned on skynet all the data's persisted to skynet the user profile image is persisted to skynet and it's loading that identity into our application and what this looks like from the code site is that we have the identity dac we say hey grab the user id and let me know when you get it back and then let's pass that to our profile abstraction and we want to get the profile for that user id then once we have the result let's update the state of our application and keep going so there's a lot of react-y stuff going on here if you're unfamiliar with react the actual kind of kernel stuff is not too deep or dense here okay so also we waited until we were authorized authenticated on the user side and we waited for our kernel to load well great how about these avatars right here if we go and look at our element for that on our hackers component we kind of have a function where we say we want to get the user avatar for some some predefined folks that we know these are our participants and mentors so we have a list somewhere i've defined a list it's going to be in the bottom of usdx i defined a list of the user ids that i want to define as like participants and mentors and so now i want to grab their avatars instead of grabbing um this mock data and under get user avatar i can stop returning my mock data and instead say let's create an instance of our profile dac remember this library that wraps up a module interaction and called get profile with the user id and then that's a skylink which is um you know we need to then define the portal that we're accessing them from and that's what this method does but at the end of the day when we save that what will happen is we can refresh our page and as these things load again our application reaches out to the kernel saying hey i need this profile for this user id but i want you to use this module and the code in this module and then it will reach out to the next place which will reach out to the skynet and so now we see these being pulled in in real time off of decentralized storage this is fully decentralized uh end to end which is pretty impressive especially if you have experience building on some other decentralized storage projects all right how am i doing on time decent um so this is kind of cool like i'm a brand new user i don't follow any of these people but i have a list of you know basically i can bootstrap my social you know social graph that will follow me from application to application on skynet by basically writing my own method that says here's a list of people go follow all of them and tag them as being associated with a specific event and so that's what this follow user list method does i say let's use the social dac for all of the users in our user id list that was hard coded into the program let's go ahead and follow that user id and if i pass in some details i can then add some metadata too so that later on i can know why i followed them or whatever else and you know there's nothing built into any of the protocol pieces that require me to use this tagging or use whatever else like this is all community developed and open source and everything else so i think that's an interesting aspect here that we can design how we want social graphs to work and even extend how they work and use that extension in our application but still have that data be interoperable with other folks building in the same paradigm okay so if i save that now as those load i already know these user ids but i can click follow all and i'll just in the back end that module will start following these users i want to mention maybe right here before i forget this is kind of the cutting edge of what skynet is working on we've focused a long time on decentralized storage and we've started seeing all the potentials for decentralized apis being fully hosted on decentralized storage so there are spots where we are still doing optimizations uh things that are called sequentially that you know with a couple hours work will be called in parallel um and so you'll notice things that like following these folks is going to take a little while um but we're excited to have developers start building on things now so that they can have a voice in the direction that things move and what we focus our our efforts on so all right i'm gonna just try to like fly through a few more before doing my closing appeal to everyone let's look at our ideas feed and instead of returning our mock data let's return actual data so here what i have is a set of users and for each one of these things i'm going to eventually grab their user profile but we've kind of looked at the profile deck so i'm just going to skip over it but what we have is a oh i broke something fun okay what we have is a reducer here um basically what that means is a piece of state that we can kind of keep updating with the previous piece of state's state and so what we're going to do here is call this updater every time we see a new user and grab their current social feed and we're not going to grab their whole so we are going to grab their whole social feed actually but we can just really quickly filter it so what we're going to do actually specifically is call sorry it is down here on our feed deck we're going to call load posts for user we're going to pass it our user id and we'll get back a big list of posts and we can quickly call a filter on it to say we only want posts that have a content field that we've extended that is called event we could say activity hackathon whatever else but here we can just say if it has an event field let's use it and then we'll pass that onto dispatch ideas list which is a complicated way of updating the state but you can see that grabbing the data off of skynet is actually pretty easy for the end user now but the module developer has abstracted this decentralized social network behavior and it would be cool if things loaded all right so the last behavior that we haven't seen maybe we can watch a few of these ideas load and pop over into creating a new idea but while it's grabbing some of those we've created a create post method here that we can call from our user site as well and we can just pass it a title for our project idea some text identify the event price track whatever else and now we're making a post on that user's social feed that has this extended metadata that can any application can utilize for whatever they want but this is really cool because you in the ecosystem have other folks that are building aggregator type infrastructure and so now your application specific data that is tagged with certain stuff can still be included by maybe scrapers or aggregators or other user interfaces and that's the beauty of this fully decentralized structure is that this application data is totally interoperable everywhere else and again you'll see that we're using the feed dac to create a post pass it this information that we've formatted in the correct way and then it will be added to the feed so let's take a look for a brief second to kind of see we're loading in some of the feed items from members of our list up here above but let's go ahead and add a new idea we want to have a super big prize winner and we'll be at east new york trying to do the public goods track and we'll be building with you know solidity flutter and hard hat i don't know if this makes sense together and we're looking for a team now when i press that button i can call again this create post and what happens is that data is persistent to skynet and then i'm immediately pulling that data off of skynet into the social feed using fully decentralized storage using decentralized code stored on decentralized storage and using a decentralized stored on skynet piece of code to do all that verification all that message routing and everything else so from end to end it's always forkable it's always verifiable and yeah and for the user they don't have to have crypto or a wallet or anything else to interact with it so i hope you see some of the potential and are a little bit excited about some of the direction that we're going again if you want to look at this later on you can see where i just comment out mock data on the hackathon ideas workshop and we also have beta documentation because this is still new and is at kernel beta kernel-beta.skynetlabs.

io and i'm going to annoy someone by going about 30 seconds over here we're doing a call for builders so we've just released this beta we really want feedback from folks building decentralized applications especially those that have maybe experience in web 2 or elsewhere we're putting up 8 000 in prizes for anyone that it creates or consumes kernel modules in your application so you know there's gold and two silver prizes but you don't have to create a kernel module or a decentralized api to be eligible you could just bring in some of these social components identity user profile whatever and still be applicable for the price um i just said all that to learn more check out kernel-beta.skynetlabs.io if you want a free account for a hundred gigabytes of upload for decentralized storage check out skynetfree.net come say hello to me i'm going to be downstairs chilling at my booth for a long time and i super appreciate everyone's time and attention and check out our discord i don't think i have time for questions is that correct okay um not necessarily no um if you want to have kind of like that sort of privacy on skynet what you want to do is use encryption to do that layer of interaction i mean i guess in theory you could spin up like a private saya and a fully private skynet that's all open source and you can do that but by the default architecture the idea is that these portals share this kind of big data lake more or less no matter what portal you're running or accessing it through yeah so the economic relationship for getting data on the siya is between the user and the portal so skynet labs is using a freemium model where we let users have 100 gigabytes of storage for free and like pretty generous access speeds but if you want to ramp those up for five bucks a month or whatever else because we're focused on like making this really accessible for web 2 users that aren't in the crypto space yet um but it's a fully open source stack and we're really excited for folks to open up portals where you can pay in crypto or anything else and then the portal itself is paying inside a coin on the side network because that's what that protocol does so all right thank you so much for your time and attention come see me if you're interested in the prize and i'd love to help you out

Automatic transcript — names and jargon may be misspelled.