[BUIDL Asia 2023 Builder Stage] Programmable Oracle: build your own Oracle with no-code
BUIDL Asia 2023 · 3 Jul 2023 · 33:41
Wenfeng Wang, core developer at Phala Network, introduces fat contracts, off-chain programs that run inside secure enclaves and can reach the internet, other blockchains and heavy computation. The talk explains why Solidity contracts struggle with HTTP access, storage costs and verifiable off-chain logic, then demonstrates a no-code programmable oracle serving an EVM contract, using a Lens Protocol profile example with the result sent to Polygon. A builder grant program is mentioned at the end.
Speakers
Topics
From BUIDL Asia 2023, hosted by Kryptoplanet.
Transcript
all right all right um yeah good speech before before me and uh I think I totally agree that we need a good UI and a good Utah and but another thing is also important then you need to deploy your service in a totally entirely decentralized Network so unless they can ban your beautiful app at any time they want right and so uh so before I I get started I want to do a really uh a small survey uh how many you guys are Developers please raise your hand oh we have some guys yeah good and how many you guys have written so literally
Smart Control accessibility just the two guys okay uh how many you guys have written biken the program no matter what what program language you use yeah okay it's almost good and at least you guys have writing some smart contract and and the difference between a smart contract and the backend program is that when you write a smart contract especially in solidity you can't access the internet of course it it makes sense because it all operation must be deterministic and when you write smart
contract you you are you hard to do the heavy computation and you also you cannot you cannot Store the store a mess of data in your smart contract right it's very expensive so today I'm going to introduce a fight contrite and built by our team and and uh and I first will introduce what the fat control is and what problem it will serve and see I will give you guys a typical example of building with fat contract is uh we we're going to show you a our recall and we have built in non-code
articles and you can deploy your article in certain minutes okay [Music] Network we are a pirating from the popular ecosystem and okay here is my Twitter telegram also GitHub Handler if you guys have interesting and welcome discuss after the meeting okay so we know the challenge of building the building with smart contract right uh we write smart contract and about uh it's really hard to do it's very expensive right uh whenever users interact with their browser with metamask or other extension they must pay something especially on
Eastern uh and they must need to pay fifteen hundred dollars per transaction and it's very expensive in and and it also you you you cannot do the heavy computation you just uh in most cases or smart contracts just transfer Isis from one or can to another account and store a little of stuff in your smart contract and it's so every smart contract looks like very simple and very tiny we cannot do it very heavy and and another thing you can you you can start uh a mass of data for example you you can't
store an image or or you can't store and we do inside your smart contract it's impossible so I have ipfs and and another another thing is that you you nearly impossible to access the network it's it's impossible to access the network if you write solidity and sometimes you want to get some information from the web to uh web 2 service like Twitter finance and uh and so forth for example you want to get price data from the finance you want to get a Twitter user profile that you have from the Twitter IP through the Twitter plan it's very hard and some somehow you can use like the service provided by
chain link and to interact with your smart contract and you you add some requests to their smart contract and and this is request you some data it can it's kind of a article actually but it's hard because first chaining only supports a bunch of platform eum platform actually this is the kind of they can't support other platforms like substrate Etc yeah uh so it's already it's it's very hard to build smart contracts so far and so we all know the next Frontier is option because we cannot do many uh many complex stuff in ancient because ancient
or ancient logic or ancient operation must deterministic uh what deterministic is every operation must be uh can be run by any other validators and they must get the same result at any time so one why did her maybe run the the operation today and another validate her or another computer one day they fetch the the phase the blockchain data they run the transaction why did their transaction domesticated the same Opera same result if but if you for example if you think about if we have a HTTP request we get the get my Twitter followers followers today
um get my Twitter photos inside the smart contract today I have done uh followers but maybe tomorrow I have one thousand followers so it's it's changed so it cannot be uh embedded in smart contracts so that's that's the generic Smart Control or ordinary smart contract work so we put it on option and but uh here is a diagram that show the current um technical stack of current depth so as you can see first uh every dab they have a website right in the two in to make user interact with their smart
contract or their application and the yeah most of these are smart made through mid mask or other browse extension the enzyme they have the asset layer I set the layer that means we deploy our smart contract on ethereum or other blockchain like polygon Hawk doll Solana we could I set layer and somehow you need some indexing service like uh the graph or sub query or any other index service the the it is also decentralized the the graph like the drive and the subcarriage they both decentralized decentralized index service that can store your
ancient data into a database then your front end can both interact with your smart contract but somehow sometimes like I say your smart contract just very keep your Smart Control really tiny so you can it can uh more cheap but but somehow we need a we need some data set acculated by by many other components so we need the index service help us store them in database in advance so or front-end can access at any time they want and and we uh currently we when we build a the App application uh we for example
even the U.N unit swap they cannot build everything on Smart contract right they also have backend they also have some uh backend deployed on like deployed on AWS or other I don't know where they deploy but some kind of like this the web 2 cloud service right and they deployed on the by web2 biking and somehow they need to like fetch the asset price or store something on other places like store something on our way or Fair coin or they get the data from balance or Google and so but but as a requesting but the problem is the Garment or the like our other
Regulators they can ban you at any time once they don't like you right for example the binance and the coinbase the ACC Justice tourism and so one day they maybe one day they just spend the finance and coinbase in America so we can we can see it and uh uh and also so so the only way I think the only way to serve those kind of say eggs right the central decks is build their service are totally decentralized Network so no one can bend you and no one can kill you and so far the government Highland value is because you you have you you don't
pick enough but one day you bigly love they offend you and uh so what we mean actually if we build a web 3 app what we what we need actually is I think first we actually need a a bacon a place that is that can uh that is circle because uh many of the time we we deploy a or biking on a web 2 service we actually will insert our private key we have a authorized method and to sell something into our smart contract so we we get our private key into it so but we first we first must make sure we have a very secret totally Circle uh
environment that can keep our private key safety and even the host operation system cannot access it so so firstly is security security is always the first one and another thing I think is very important is important and it is it must decentralized and you you cannot uh World Service cannot be deployed just one on one server so what if the server is destroyed and whatever the the AWS service is done so when we have seen too many things happened on our Industries and the the applicants just cannot access because the service is done all right so so we
we better to deploy our product our truly centralized Network and of course we uh we need to within our program can be verifiable so because as a web 3 application everything you you don't should be verifiable but for now just all or smart contract can be worked for can be verified on train and but all stories behind the smart contract or biking service people cannot know how it works so here is some magic happens right so it's better to have that your your program can be verified at any time even your back in service
um so that's why we have the fight contract actually the fight contract is is replaced is replacement of the web 2 biking that we have we serve those problems by for example we or our program are running inside the secure Enclave which is the secret security is guaranteed by this uh by the CPU the hardware and even the house operations we cannot access it and the in your smart contract you derived your private key inside our fat contract and and it will it will never rebuild to the outside world you can keep it safe forever
and another thing is is truly decentralized we have almost I think more than 10 000 workers uh on Final Network so it's a truly decentralized Network you you don't need to uh care about the crash you don't need to uh afraid of the censorship right and it's anti and censorship and um and and of course we have provided many truck heads that can connect to the blockchain like the Fair coin or or the ethereum we have a entirely uh two arcade that can help you write write your smart contract and
external transaction to the blockchain or uh or read the data from browser yeah okay so uh so fat control actually is we we call it a smart contract because uh we actually write five contract like how we write a write smart contract uh today but it's more smart because like I said it have many many features and abilities and the traditional smart contractors cannot cannot have here is a I think you can just uh headed to our official website uh it just remove the bricks okay okay here is
the feature that uh can be highlighted on fire contract first is is incompatible that means we can access every every blockchain actually if your if the production has the RPC service we can accelerate it uh so both UAM substrate or other blockchain learned a lot based on this to technical stuff like like like uh maybe solar linear Etc and and the internet connectivity uh inside our fat contract so remember you write smart contract but you can access the uh internet you can send the HTTP request to outside work to other
blockchain and uh so it's just enabled seamless integration with any web 2 API right in the arbitrary complex logic you can do whatever you want to do inside fat contract do heavy computation do the it will very complicated algorithm but you cannot do it on smart smart control like solidity okay and the the next one is verifiable computation right and the we must make sure that as a web 3 application we women that must make sure that our program can be verifiable so someday you your customer or your user will challenge you and how your program
worked if you had it into a web 2 server you cannot explain to it so we need to make sure everything is transparent trustness so because our programs are running inside the secure enclave and the program log can be verified by anyone so this is this is how how the the amazing features the fat control have okay and and another thing that I want to see is writing a writing a off-chain smart contract with the fat contract actually is a option smart contract it's not a Unchained smart contract and so right is
write a opt-in smart contract is a it's not easy actually as a as a developer I know that is where it's not easy so we have provided uh the the top two modules then to mitigate the barrier for Developers for example we have the five bricks it's a individual predefined components of fat contrast so we actually have Implement many uh components that you are used in your smart contracts now you don't need to write it again right you just use the companies and we provide but if you are not a developer you you don't become a developer and you you are maybe a PM a
product product manager you also can use the blueprint the blueprint actually is a um it's a no code platform to inter to to place the file contract so if you want to play deploy some file contract our platform and you want to build a product you actually to write a single line code so or uh and today and as an example then I will show you is the Oracle and actually is build based on the blueprint and okay here are some use cases and uh very typical use cases and or Friedman
can build with fat contract the first one is the cross chain text aggregator and the first is a I have seen many times and or 500 can send HTTP requests to the outside world this is a mind difference between the fat contract and other smart contract traditional smart contract and uh so when you build a cross syntax aggregator that means you will first swap the Isis on first blockchain and then you swap the asset on the second blockchain and of course under middle you you need to bridge the asset from one blockchain to another blockchain so there are many steps you need to do but in the many and so many steps you need to do it one by one and it make it sound like a atomic Atomic
operation so um so when so the first use case is quality disks are greater you will use those uh features then a fat contract can provide you and the cell the second one is the self-funded article this is the example I will demonstrate to you guys and uh so first of course the avoid Oracle we must have the ability to uh access the internet yeah like get the data from the price service or Etc and of course it needs to be executed automatic automatically and of course you need to have some secret then be kept in inside the fight contract for
example the Oracle need to submit the data to you uh into your smart contract but you don't need you you cannot allow everyone can submit the data to your smart contract right so so you have a dedicated account to submit the response to your smart contract but you must keep this key safe so so here is the magic outside contract we because we run inside the securing lab you you can keep the key safe and and use this again to submit the data to your smart contract and and the third one is trading boot and I think as a trading both the for the trading board it's uh important is
it can do a it can do high performance compute computation because as a trading boat or you you have some you have your own trading uh strategy that some somehow it is very like high high computer heavy computation algorithm so it you you can't do it on a smart contract a smart contract right so but you you also cannot cannot do do is deploy your smart uh deploy your boat on a web 2 service even though you guys are do it right now but I I highly recommend you to move it to a decentralized network and especially you
your trading would also have a key because you're both need to send a transaction right and and the the dial control web 2 service is also is a typical use case um and for now uh for now we have we we have many surveys and we have many surveys in the running a bike hand and but the dial actually some some of I think many of the dogs are just running for one blockchain and with five times you can build a dollar across different Productions and another one is trustless ring system across I think the they have they don't have too much difference but under under
the hood and about but but but and it's really uh some the ranking system maybe it's it's a high quality ninja the high quality of the uh Community performers because somehow you need to get the result as soon as possible okay here is a a project it is a our a project come from or ecosystem and called the private X it's a DEX aggregator in the and it can print Isis from Moonbeam to a star between an imperation and in the future they were they were free they are bring their product to the UN blockchains and
they got the web free Foundation grants and they have some I got many funds I think and uh so we actually can build some product actually and and by the way I just forgot and we launched the Fire Control magnet uh just uh yesterday I get uh yesterday I guess and on June 5 25 so the day after yesterday okay uh the day before yesterday okay um so so here is a uh let's break it down the
five contract and what's the relationship between between each component uh first we have blueprint and you don't need to write a single line code and you can deploy your application and first we have fat control SDK whereas it's like it's like a fatalog or it's like a logo or in our and uh some J JavaScript SDK I mean and of course we have contract cluster this is important that is it represents that all smart contract actually running in the uh thing that we call the cluster a cluster is content is
contained by many workers so a bunch of workers will will become a cluster and the final network will have a bunch of clusters so that's a really that's the architecture of our workers of our Network and each worker inside each worker inside each machine we have the p110 the trust execution environment and so this is very a low level uh execution environment and so far we support the Intel te and the in the future will support more infrastructure infrastructure company
um okay so um I just said and we we will show you a typical example of the Oracle and we have built a lens article platform and to give you the local experience what the Oracle do is it it you can deploy your own lens article through our platform and it can uh for this you will deploy and the we will deployed for you a fat contract then to as a backend and a smart solidity contract deployed on polygon so um
see so this is the completed another this article contains and here is the here is the architecture of this article and I came for you guys to how it works um at first uh as the middle of the diagram the article the core of the Oracle is written by fat contract and it can interact with both the next particle the right side and the supporting Network the left side and first your polygon smart contract is the solid contract you deployed on a smart contract or you you deployed on polygon Network first your smart contract can have can re send a request to our fat contract that means oh I I will request
some lens protocol data for this game means and data and our fat article will uh get us this data get this request and pass this request and pulling the latest data from lens protocols through lens API and we put in the next protocol data every one second so it's very frequently and you and then when the after after the next API returned the data we will uh construct the response and send a transaction to uh feed those data to your smart contract so under this um unless workflow and the only thing
you need to change is is a smart the the data type in your smart contract because you can customize uh what What's your data type is okay here we have a we have a demo and uh yeah we can show you because we we don't do the live demo in case some Network issue and here as you can see we actually this is the UI and the U deploy a article and first you can choose your project name right it makes sense and then here actually you you are choose what kind of type you want to get from the lens
protocol the lens profile right we have a lens profile news profile have you users stay your user profile in the Z you just can't create and in case you don't have an account you will create an account and the connect is worth it then you just need to click deploy and we will do everything for you for now we are deploying the Oracle backend right in file contract and then we will deploy the example contract that the anchor contract is in polygon test net right this is showing test net so in the so
okay oh get back I need to jump to this because I think this is important so here in our UI we will show you an example code of how to interact with the Smart Control you just deployed the Oracle smart contract and in case you you can say it and so I will show you the the Live code here is an example of your application we just suppose you already deployed the
all of the stuff just now and now you have your own application your own smart contract then you can write read and write requests from the article and let's see how it works first we have a request method then that means you can a request to the send a request to to our fat contract the our fat contract our record you just deployed yeah inside our Network and you just construct the request and then you for example here we we like we'd like to the profile ID and we encode it and just call the push message and this function is come
come up with the fat rub anchor Smart Control it's written by it's provided by by all by all by us and you don't need to care about this you just need to push this message that means it will push a request and and the the Oracle backing will observe this request and pull out the data from the next protocol and after and after after the you after we or smart fat contract Oracle smart contract have got the data from this particle it will fail the data to your smart contract and you can handle your handle the data inside your smart contract this
is your customer smart contract your where your application logic have and as you can see we first we have the response tab defined by you defined by you and you decode it and you just do whatever you want here we just image the image and you want so it's very simple but you can do everything you want inside here and this is the Smart contract and then of this is your smart contract you can write in your own logic and here is the here is the implementation of our opt-in roll up the Oracle side and so as you can see here we have a function called answer request so you get
just know how it means right you just send a request from the solidity side and now we will answer the request uh inside the fat contract side what it does and first it will destruct the requested data and then it will for example answer request we if we dive deep into the um answer request inner we can see it will decode the request and it will get the data feature the feature the lens API feature lens API from the lens protocol right and then it will get the result it will get a result from the next protocol
and the next one is another one is when when or when the result is okay it will it will adjust um okay we have a result and we just send some transaction here maybe submit cheetah that means we will send a transaction to the polygon you just deploy your smart account to Solid the smart contract and we'll return the data for you okay so here is the the implementation and the yeah we just have a very simple review of this okay um so um so the video is uh this video is done
actually we are able to do all of this stuff wheezing actually I mean actually within one minutes actually yeah it's very it's very simple and uh okay okay yeah um as I've said we just launched the minute and we have a builder program and we as a program we have a program for us and uh every team can apply at most uh 15 fifteen thousand dollars for everything and everyone if you like to build something with file contract just a scan
the code and get the details yeah okay and here we have some QR code for for the uh I think very useful page for example the first one is the awesome fat contract GitHub repo it contains many uh examples for the contract and the the middle is file a network of your website and of course you have you can get all the findings here okay thank you any questions no okay thank you
