Simple Relayer
Last updated
Was this helpful?
Last updated
Was this helpful?
The Relayer Engine is a package meant to provide the structure and a starting point for a custom relayer.
With the Relayer Engine, a developer can write specific logic for filtering to receive only the messages they care about.
Once a wormhole message is received, the developer may apply additional logic to parse custom payloads or submit the VAA to one or many destination chains.
To use the Relayer engine, a developer may specify how to relay wormhole messages for their app using an idiomatic express/koa middleware inspired api then let the library handle all the details!
Checkout the example here, or for a more advanced relayer app, see the
The source for this example is available
First, install the relayer-engine
package with your favorite package manager
note: These processes must be running in order for the relayer app below to work
Next, we must start a Spy to listen for available VAAs published on the guardian network as well as a persistence layer, in this case we're using Redis.
In order for our Relayer app to receive messages, a local Spy must be running that watches the guardian network. Our relayer app will receive updates from this Spy.
A Redis instance must also be available to persist job data for fetching VAAs from the Spy.
In the following example, we'll:
Set up a StandardRelayerApp, passing configuration options for our Relayer
Add a filter to capture only those messages our app cares about with a callback to do something with the VAA once we've gotten it
Start the Relayer app
The first meaningful line instantiates the StandardRelayerApp
, which is a subclass of the RelayerApp
with common defaults.
The only field we pass in the StandardRelayerAppOpts
is the name to help with identifying log messages and reserve a namespace in Redis.
The next meaningful line in the example adds a filter middleware component. This middleware will cause the Relayer app to request a subscription from the Spy for any VAAs that match the criteria and invoke the callback with the VAA.
If you'd like your program to subscribe to multiple chains and addresses, the same method can be called several times or the multiple
helper can be used.
The last line in the simple example runs await app.listen()
, which will start the relayer engine. Once started, the relayer engine will issue subscription requests to the spy and begin any other workflows (e.g. tracking missed VAAs).
This will run until the process is killed or it encounters an unrecoverable error. If you'd like to shut down the relayer gracefully, call app.stop()
.
More details about the Spy are available in the
Note: While we're using Redis here, the persistence layer can be swapped out for some other db by implementing the appropriate .
For a more advanced example that details other middleware and more complex configuration and actions including a built in UI, see the