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 wraps, the interface is defined using a Wrap 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 wraps 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 type to interface.

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

format: 0.3.0
project:
name: UriResolver
type: interface
source:
schema: ./src/schema.graphql

Defining an interface

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

Implementing an interface

As described in Wrap 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 URI Resolver Extensions plugins implement the URI Resolver interface and inherit its methods.

#import { Module, MaybeUriOrManifest } into UriResolver from "ens/wraps.eth:uri-resolver-ext@1.1.0"
#import { Module } into Ethereum from "ens/wraps.eth:ethereum@2.0.0"

type Module implements UriResolver_Module {}