Polywrap resolver
Before we start, it is best to checkout Polywrap's documentation to get some insight into Polywrap.
Polywrap resolver is still in Beta!
Begin by cloning this Polywrap resolver template.
You'll also need the following installed before building your wrapper:
  • yarn
  • docker
  • docker-compose
Once you have cloned the repository, do yarn install to install dependencies.
The main files you will have to change are src/query/index.ts and src/query/schema.graphql

Defining a schema

./src/query/schema.graphql

Here, the only thing you should modify is UserConfig .
Similar to smart contract resolvers, you can also pass arguments to Polywrap resolvers. If you would like to do so, you have to define the argument types here.
If you do not need any arguments, you can just leave it empty like so.

Writing your resolver

./src/query/index.ts

You will define the logic of your resolver in this file. Like writing asse
Here we deserialize the argument that we are passing if any. In this example counterAddress .
Another parameter that is passed in the argument is ethConnection which is needed for the Ethereum Plugin that is covered below.

Gelato Supported Plugins

Ethereum Plugin

The Ethereum plugin is the EtheresJs plugin which can be used inside your Polywrap resolver.
Check out the schema here to get an idea of the functions that are available.
We can use callContractView to call view functions like so.
1
const lastExecuted = Ethereum_Query.callContractView({
2
address: COUNTER,
3
method: "function lastExecuted() view returns (uint256)",
4
args: null,
5
connection: ethConnection,
6
});
Copied!

Subgraph Plugin

Allows you to query subgraphs in your Polywrap resolver.
Check out the schema here.
Here is an example:
1
const res = GraphNode_Query.querySubgraph({
2
subgraphAuthor: "gelatodigital",
3
subgraphName: "poke-me-polygon",
4
query: `{
5
version(id:"3"){
6
tasks{id}
7
}
8
}
9
`,
10
});
Copied!

HTTP Plugin

Allows you to do HTTP requests in your Polywrap resolver.
Check out the schema here.
Here is an example:
1
const res = HTTP_Query.get({
2
url: url,
3
request: null,
4
});
Copied!

Logger Plugin

Allows you to log messages in your resolver which can be useful for debugging.
Here is an example:
1
Logger_Query.log({
2
level: Logger_Logger_LogLevel.INFO,
3
message: `config.counterAddress : ${config.counterAddress}`,
4
});
Copied!

DateTime Plugin

Allows you to get the current epoch UNIX timestamp in milliseconds.
Here is an example:
1
const time = DateTime_Query.currentTime({})
Copied!
Last modified 23d ago