Skip to main content

Define and implement interfaces

A special type of Polywrap project can be used to define an abstract interface without providing a concrete implementation. Like other wrappers, the interface is defined using a Wrapper Schema. Once an interface is written and deployed, other projects can import and implement it.

For example, the URI Resolver interface is used to standardize the interface of URI resolvers. It is implemented by multiple plugin wrappers to help the Polywrap client query different types of URIs.

Declaring an interface project#

Interface projects are declared using a Polywrap Manifest. To indicate that a project is an abstract interface, set the project language to interface.

Interface projects do not have a module. Only a schema path is declared.

format: 0.1.0
name: UriResolver
deploy: ./polywrap.deploy.yaml
language: interface
schema: ./src/schema.graphql

Defining an interface#

Defining an interface is as simple as writing the Wrapper Schema. Once the schema is complete, you are ready to deploy the interface wrapper.

Implementing an interface#

As described in Wrapper Schema, an interface can be imported and then implemented with the implements keyword. When a module implements an interface module, it inherits all of its method declarations.

The ENS Resolver plugin implements the URI Resolver interface and inherits its methods.

#import { Module, MaybeUriOrManifest } into UriResolver from "ens/uri-resolver.core.polywrap.eth"
#import { Module } into Ethereum from "ens/ethereum.polywrap.eth"
type Module implements UriResolver_Module {}