Polywrap is a Web Assembly (WASM) standard for integrating web3 protocols into any kind of application. The way Web3 works today is that developers import custom SDKs from DeFi, NFT, or DAO protocols directly into their apps and ship these SDKs on deployment. This approach, inherited from web2 devops workflows, creates several drawbacks for a decentralized trust-less system: first, traditional SDKs are limited to a specific programming language, so that devs are locked to the SDK's choice. Second, the web2 model of importing dependencies at the library/source-code level has proven to be too insecure and bulky.

Polywrap at a glance

Polywrap improves the orchestration of web3 dependencies by making web3 protocols dynamically loadable WASM modules with a standardized and discoverable GraphQL interface. Modules, also called Polywrappers, are loaded into web3 apps via a chain of trust starting at an on-chain name resolution system like ENS or Tezos Domains where a module's name and content hash are registered. After lookup, the compiled Polywrapper is loaded from a trustless content delivery system like IPFS. On-chain name registry and content hash are trust anchors that improve app security while WASM serves as a common abstraction layer to separate development language from host language. Polywrappers can be written in any language that compiles to WASM (AssemblyScript and Typescript are supported, Rust and Go are in preparation). A host app interacts with a Polywrapper by executing GraphQL requests to either query or mutate the state of a web3 protocol. Its important to know that  as of now Polywrappers are entirely state-less: all state is stored on-chain and the Polywrapper just mediates read and write operations.

Why Tezos Polywrapper?

At Blockwatch, we are working to increase Tezos developer adoption by enabling applications to interact more easily with the Tezos blockchain. Right now, developer adoption in Tezos is challenged by the protocol’s complexities and its frequent protocol upgrades which results in a higher barrier to entry and additional maintenance. Many developers and businesses ask us for a plug-and-play solution and we believe Polywrap can become one of the choices. It will make Tezos more accessible to a larger developer audience.

Our Tezos wrapper for Polywrap is designed to enable straightforward integration of Tezos into web3 applications. It is built in TypeScript, one of the native development languages for Polywrap modules and plugins. We aim to keep all components of our wrapper up-to-date with new Tezos protocols and at the same time keep the high-level APIs stable so that application developers don’t have to worry about low-level changes to the Tezos protocol or its RPCs.

Project Overview

Polywrap supports WASM modules and native Typescript plugins to extend its functionality to multiple blockchains. Plugins are blockchain clients that provide core functionality to interact with a chain such as reading data and sending transactions via its native RPC interface. Plugins are implemented in JavaScript/TypeScript and loaded into a Web3 host application directly. Modules are wrappers for Web3 protocols that are deployed as WASM binaries which can be loaded on-demand by an application. Each module wraps a specific contract (or family of contracts) such as a DeFi DEX or an NFT marketplace. Modules are versioned and may be deployed on IPFS. Their IPFS hash is registered as metadata on a Tezos or ENS domain such as e.g. w3://ens/v2.uniswap.web3api.eth. Wrapper describe their interface with a GraphQL schema definition that provides types and parameters for contract calls to a Web3 protocol. All business logic to execute calls (e.g. buy a Tezos domain or swap on Quipswap) is implemented within the WASM module. Host apps can either query the protocol's state (which may result in reading on-chain storage or calling on-chain or off-chain views) or mutate a protocol's state by sending contract calls. From the side of a host app this looks like a regular (async) function call. Polywrap and its WASM modules handle all the protocol-specific logic including the construction of transactions and their signing process behind the scenes.

Initially, Polywrap was designed to work with Ethereum. Hence its current module loading system is very much centered around Ethereum domains and clients. However, Polywrap’s vision has always been to become a multi-chain platform where developers can discover, deploy, and interact with various Polywrappers for different web3 protocols across chains. We are currently extending Polywrap to support tools from the Tezos ecosystem such as Taquito and Tezos domains which will be the core building blocks of our integration going forward. Taquito will be used for interacting with the Tezos node RPC to craft transactions and read smart contract state while Tezos Domains are used to register and find Tezos Polywrap modules.

Project Status and Outlook

As a starting point we have implemented a Tezos client as a Typescript Polywrap plugin which supports connecting to the Tezos RPC to read account information, query contract data, call views, and send transactions. This plugin provides core functionality to execute query and mutation functions from Tezos Polywrap modules as well as to find Tezos modules via Tezos Domain names and load them from IPFS. Right now, our client uses a simple in-memory wallet and signer implementation which we're going to extend soon.

Additionally, we implemented a first prototype plugin for Tezos Domains which can be used to query domain data and buy new domains. For now, this is a proof-of-concept that helps us learn how to best integrate Tezos call conventions with Polywrap. Ideally, the Tezos Domains protocol will be implemented as Polywrap WASM module so it can be loaded on-demand.

Demo Application

We have prepared a small demo application that shows the functionality of our Tezos domains Polywrap integration. Currently, you can search for registered Tezos domain names across Tezos testnets and mainnet. The network to search on is detected from the TLD domain you add (.tez for mainnet and .gra or .han for one of the testnets).

  • Visit the Demo App here
  • Github repository for the demo app is here

To get an idea of the developer experience, we're showcasing how some common tasks will most likely look like (since this is a work in progress expect interfaces and naming conventions to change):

import { Web3ApiClient } from "@web3api/client-js"
import { tezosDomainsPlugin } from "@web3api/tezos-domains-plugin-js"

export const client = new Web3ApiClient({
  plugins: [{
    uri: "w3://ens/tezos-domains.web3api.eth",
    plugin: tezosDomainsPlugin({
      connections: {
  		granadanet: {
		  provider: "https://rpc.granada.tzstats.com",
	      supportedTLDs: ['gra']
        },
        hangzhounet: {
          provider: "https://rpc.hangzhou.tzstats.com",
          supportedTLDs: ['han']
        },
        mainnet: {
          provider: "https://rpc.tzstats.com",
          supportedTLDs: ['tez']
        }
      },
      defaultNetwork: "mainnet"
    })
  }]
})
Creating a Web3 Client with Tezos Domains Plugin Support
const uri = 'w3://ens/tezos-domains.web3api.eth'

export const resolveDomainRecords = async (connection, domain) => {
    return client.query({
        uri,
        query: `
            query {
                resolveDomainRecords(connection: $connection, domain: "${domain}" )
            }
        `,
        variables: {
            connection
        }
    })
}
A function to resolve a Tezos Domain via Polywrap+GraphQL

Outlook

In the next iteration of our research we will add support for the Beacon SDK and external Tezos wallets into the Tezos plugin. We will also create a first WASM Polywrapper module for Tezos Domains. Once we know how modules work we will start building additional Tezos Polywrappers for popular contracts such as Quipuswap, hic et nunc, and Harbinger Oracles. Along the way we’re going to release more documentation so that developers can build and publish their own Tezos Polywrappers and make more of the great protocols in the Tezos ecosystem universally available.

If you found this article interesting and would like to stay up to date on our progress, follow us on Twitter and join our Discord. When you have an idea or opinion on how a cross-chain developer & user experience between Tezos and other chains like Ethereum should look like please share your thoughts with us. We also have open positions for frontend and backend developers with a solid experience in working with different blockchain protocols, databases and distributed systems. Drop us a line at jobs@blockwatch.cc