Universal frames

ETHCC 7 · 11 Jul 2024 · 21:10

Henri Binsztok, co-founder of OK Contract, argues that frames like Farcaster's should become universal, so smart contract interactions can be embedded in any website, mobile app or social platform. He says only a tiny share of crypto holders use contracts, and that a Uniswap swap needs hundreds of files of front-end code. He demonstrates describing an interaction once, then embedding it with a six-line React widget or a customisable component, with a Discord integration in progress.

Speakers

Topics

From ETHCC 7, hosted by Ethereum France.

Transcript

Give me a reason, give you a visa, give me a reader. Yeah. Okay. Hi everybody, I'm Henri, uh co-founder of OK Contract, and today we're gonna talk about universal frames at the interaction between developer tools, developer experience, and UX as well. There are about five hundred million people worldwide who hold cryptocurrencies.

But if we look at the stats at the gene dashboard, etc., only a tiny fraction of them actually use contracts. If we look at Lido, for instance, there are 300k users. That's 0.05% of the cryptocurrency holders. If we look at Ave, which is the the most used, let's say non-staking DeFi protocol, it's about the same. If we combine the statistics on all chain for V3, the latest version, it's still 300k users. Uh according to different estimates.

Why? Because we have limited distribution channels.org website or DapRa or several dashboards basically, they tell you that we have 12,000 distributed decentralized apps. But there are way more distribution channels. There are 4 million mobile apps and almost 2 billion websites. So the question is how do we extend the reach? And if we look at what frames uh achieved, basically for Farcaster, they added interaction and showed what it is to attract third-party developers, putting interaction with smart contracts inside their application.

But it's still one app. And it contributed to their growth, but as we see with the numbers, the growth is still limited to the potential of two billion websites and four million mobile apps. So the question is how can we generalize this? How can we have universal frames that go way beyond? And there is a second problem. The second problem is that most frames are limited to very simple transactions, like a free NFT mint that has no parameter. It's something very easy to build.

And the gas also is often subsidized by your paymaster so you can have fully empty wallets interacting with it. But the real life we want more transactions that involve actual users, actual wallets. And also here in that case, the transaction is built by the frame server, which introduces a centralization in the whole architecture. So as we were telling, frames don't solve transactions. What they solve is display. Because basically, the actual transaction that you send in the frame is just the roll call data, the raw bytes of it. We are not solving the way we implement these transactions.

They are frameworks as well, frames frameworks. But they still don't help. Like they add just a few layers by converting the parameter using the ABI so that we are building the code data. So that's a single step, but it's way insufficient to reach what would be a global way to interact with smart contracts. What we want is enabling contract interaction across all applications to reach users everywhere. So we go from siloed dApps like we have today, which is more or less web one.

Web one, banner, click, go there, and you'll go to a dAP. But we want uh what Web2 has achieved, like uh Stripe, for instance. You you don't go to Stripe website to do a payment. You you stay where you are. And this is what we want to interact with smart contracts, integrated experiences. But to do this, the problem is it requires way more front-end. So, how do we scale front-end development so that we can integrate the smart contracts everywhere? And I won't go into details in this short talk, but there is a lot of friction, and the the key takeaway is front-end development on the world is way harder than it seems.

If we look at one example, Uniswap B3, which is the most common interaction, by the way. The most common interaction on chain is to swap ETH to USDC using Uniswap. So let's take this as an example. If you look at the React code base, there are hundreds of hooks, hundreds of files, and thousands of lines of code to manage it properly. Because of the architecture of the contract, you need another contract, a quota to get a quote, and then take this code, do computation with it to integrate sleep age, and then resubmit another transaction with all these build arguments, and this becomes more complex. You need more than one ABI, you need a lot of things, manage big numbers, etc.

etc. We need a shortcut. And the shortcut is to what uh we found out an automated tool to create this contract interactions and an SDK to embed these interactions into multiple front ends. And as well as one thing that I won't dig in today, which is a network, a decentralized network to handle this interaction without centralization parts. So this is the simplest way. We start by defining what an interaction on chain is. We have one single SDK to integrate it, and then it runs everywhere because the runtime as well matters.

How do we need to manage from all these front end the RPC nodes, some private APIs, which in the case of frames is the frame server, because behind each frame you have a frame server, which is usually an AWS instance. So we solve it by building a first part, which is what we call a kind of hub, so a GitHub, if you want, for interactions, a way to create clone experiment with contract interactions. And as you'll see, it will be community centered. So instead of writing hundreds of lines of code, what we introduce is a concise specification for any interaction.

Okay, how do we do this? We do this by introducing a new programming language which is which won't be too much visible. There will can be guide tools that make it easy for some developers. Otherwise, you can dig into it. It's a real functional programming language, which has many features like abstract RPC calls, the addresses, the contracts are first class values in the language. It's strongly statically typed, and this helps a lot with making sure that the specification we have of the interaction is correct, and it can be very easily audited and to start with because of the size. And as you see, it's very, very concise.

And then it will be compiled to a functional reactive runtime which runs in a VM inside the browser or later the mobile. And uh the community part is there to make it permissionless. There is a test station, so we worked with ES, if theorem attestation service to design a way to attest for the interaction, the contracts, but this will be for another talk. Just look at one real example, the the the most common one. How do we swap ETH to USDC on Uniswap V3? And this here is the complete specification of the interaction.

You'll see, for instance, that we interact with another contract, which is the Uniswap Quoter V2, which is defined in the graph database, which is behind OK contract and which is decentralized. And all the computations that we will do, including the sleepage computation, is expressed here. The big numbers are native. There's no need to specify this computation manually. The tokens that we interact with are also defined, and we check that the whole graph is verified when we compile the interaction. There's nothing more.

And how do we integrate it? And that's the second part. Once you have defined your interaction, which lives in the network, a decentralized network and uh signed by uh wallets and stored on chain, then you just need to integrate it. And this is something that we think is for the first time a SDK really made for front-end developers. We talk to a lot of front-end developers, many come from a UI web 2 background, and they have a hard time managing the complexity of the libraries in the ecosystem, uh like Ethers, Web3, Veeam, etc., which involves a lot of complex concepts. Here, basically, you'll see that this is six lines of code.

We just use OK contract, a global class which manages the wallet connection, the RPC connections, okay instance, one per page, which basically holds the cache of the value, so we speed up the navigation, and OK widget, which is a React component, which basically takes one ID, the ID of the specification of the interaction, and renders something. That's the something. The something is a fully auto-generated UI, which is foolproof for front-end developers. It's just six lines of code, and end users can as well verify the interaction because of the link in the bottom left, which leads to a verification page on chain, proving that the specification is correct, the attestations, et cetera, et cetera.

If you want to play with this, this six line of code, but the whole project setup is uh github.com, okay contract, uniswap demo. Many people ask us then, oh yeah, but we also want to customize these interfaces. For that, we have another component called OK interaction, which basically expose the whole state of the wallet connection, the RPC, the transaction lifecycle, uh the built information text, build button text, etc. Everything is exposed uh as cells, which is based on our own library.

As you see here, there's no dependency but React and the OKContract SDK. There's no other library that you need. You just go this type uh in OKContract, the same global instance for wallet and RPCs, okay instance, one per page, and then the OK interaction with our custom app. And this can lead, for instance, to this kind of customized UI, which differs from the previous one because here we manage everything by hand, but this is meant for a front-end developer. So basically there's no complex computation whatsoever involved in this.

And you can do your own app level, any interaction you you want. And if we look at all the state uh parts that we use, they are here. So basically we define, for instance, that we want the wallet, we want the the name, so the ENS name, we want to see if it's verified, if there has been a signature by this user yet. Uh the stepper, which involves multi-step transactions, so like uh approve uh a swap, and then maybe a third transaction, even to to stake, uh, and many, many other things. They're defined in the docker, of course.

And you can perform actions extremely easily. You just say, oh, I want to connect to the wallet, or instead drop the connection. I want to send this current transaction. I want to know how many transactions there are in this uh interaction. I want to switch to the desired chain for this. This is extremely easy, and it will be just a few lines of code. Just to give you an idea, if we go back to this, the complete example, including all the React boilerplate, etc., is 120 lines of code. And no dependencies.

We can do a short uh 30-second demo of what it looks like for 120 lines of code, fully included, including the import react, etc. So as you can see, I can sign here with my wallet, I have the ENS name, it reacts, I can't swap when the amount is zero, then the transaction is being sent, the explorer link is shown immediately, and it points to etherscan, and then in about uh 15 seconds yesterday, the block is mine, and when the block is mine, you get, for instance, the block number, which is the just the proof that we received and we are communicating uh with the app. So all this is 120 lines of code, nothing else, and with complete customization of the UI, but not a single complex detail of the interaction.

How do we move out of this? No, no, it's played again. Okay. So it can as well manage multiple steps, including of course the approvals, which are uh, and that's a bonus, automated as well. This demo, the compound one, uh, it's github.com, okay, contract compound demo. So what have we done here? Basically, it's one specification. As I just show here the one front end, which is a web app, but we can put this in multiple web apps, of course, but it's not limited to web. It could be a landing mobile page, and we are now working on integration, on direct integration with Discord and many other social media types.

And uh, this is something that uh we'll share pretty soon in the next few months. But we have a pretty awesome demo with Discord uh where we can put any kind of interaction with specify into Discord, and it works extremely well. We think that this can be really the future of contract interactions. Any front-end developers can embed this numerous smart contract interactions into their apps? What was it? And any smart contract developer will be able to distribute their contract to third-party apps and websites when you have partners. A partner writes a blog about what you your project, basically, they can integrate the transaction with your smart contracts into their blog extremely easily.

So, as I said, it's blogs, documentation site, websites, news, social media, there's really no limit to what we can do, and this is what we can call universal frames. Basically, universal transactional frames, it's interactions experiences that you embed everywhere. So we fully support EVM chains, and we are also working with Starknet, and Starknet support is coming real soon. Thank you. So if you want to follow the pointer, you can follow us on uh of course X. Thanks a lot for that.

And if you want to follow myself, I'm only dash uh underscore underscore. Okay. Uh we have a Telegram group to where we'll open the communication as well, and of course the GitHub, uh the demos, and one minor uh thing that might interest some of you is the cells. So the reactive functioning uh functional programming library uh that we have built is uh already being used outside of the the Web3 crypto space, and uh yeah, I'll also speak about this at uh pure JavaScript conferences. So thanks a lot and uh hope to see you partner and reach the ecosystem of these universal frames.

Yeah. Questions and one. So how do you manage versions of let's say I make an update of my integration? Oh yeah, very good question. So uh the specification R versioned. This is because it's uh stored on chain. And uh of course, uh you can update one interaction, and you don't need to change the implementation if you put your integration into the client to latest, which is the default, then as soon as you update the interaction, all integrations are updated at the same time. And also we have a key on switch.

If you think your contract is being hacked, you can stop all the front ends at once. And do you mean by React Native or planning to do Flutter or actually native iOS Android? Yeah, very good question. So for now it's uh it's pure uh React React native is coming, and we may uh as we grow, we we are of course considering uh native uh Swift and Kartlin implementations as well of the same SDK, but of course, which takes from the same interaction definition, so that's uh that would be uh nothing almost nothing to do to integrate into mobile experience. Thanks.

Yeah, what would you use under the hood for that? Yeah, so good question. Uh so first, uh how do we handle the the blockchain RPC connections? So we have our own functional reactive RPC library, so we rewrote this from the ground up. It's called uh github.com uh slash okay contract slash multi-chain, and also already works with Starknet as well. So we have uh a very let's say particular way of uh considering the state as a graph database. So everything we do basically we think that it's it's a graph data behind it.

So we can we we construct our own uh cache of the graph and we have bits which are handled uh by cache nodes uh which is part of our network, and as well we have a partial cache which we implement in each client and which is maintained in this uh multi-chain library. So that's for RPC. It's very efficient, like we do, for instance, multicalls, I think, uh better than uh than many others because of the functional reactive uh paradigm where we uh all the different bits that involve a RPC connection we know beforehand because we have the whole compute graph which is built before runtime. So for instance, we can do uh real multicole aggregation, and uh but you you can look at at multi-chain for that.

And for the wallet connection, we have also so we we partially use the Veeam, uh but we have uh we are rebuilding more and more of the connectors to port them to the same functional reactive programming paradigm. And this uh will be another library that we open source uh in the coming months. We'll see. It's it's not the highest priority right now, but it's coming. Thanks. Thank you.

Related talks