Mirrors
Syndicate’s mirrors allow you to send data from blockchains or HTTP resources to target blockchains. This becomes useful when creating cross-chain applications that could benefit from data that lives outside of a single blockchain.
Dependencies
Our data mirror service is a simple HTTP server that listens to events on desired blockchains or polls HTTP resources and allows you to broadcast transactions to target blockchains using Syndicate’s API.
Before getting started, ensure you have created an account with Syndicate. Additionally make sure you have bun installed on your system.
Next, clone the mirror repository and add your Syndicate project ID and API key to your environment
Install dependencies
Run the server
Upon starting the server two listeners will be initialized, a ChainListener
and an HttpListener
.
These two listeners implement the logic necessary for retreiving data from their sources
ChainListener
: queries events emitted on a blockchainHttpListener
: polls HTTP resources
ChainListener
On start, chain listeners will immediately query all events emitted from the fromBlock
to the most recent block and will continue listening to all
future events. An example is shown below for listening to all purchases of a CryptoPunk and minting an NFT for the purchaser on Base.
The following parameters can be passed to define a ChainListener
:
rpcUrl
: the RPC URL of the target chain you are mirroring data fromfromBlock
: the block from which you want to start mirroringevent
: the ABI of the event emitted fromcontractAddress
contractAddress
: the source contract address that emits anevent
onData
: callback that receives all data emitted in the eventpollingInterval
: (optional) value in seconds to poll forevent
HttpListener
An HttpListener
allows you to query multiple HTTP resources and broadcast data to a target blockchain.
The following parameters can be passed to define an HttpListener
getters
: array ofHttpGetters
used to query HTTP resources and normalize data utilizing theironJson
callbackonData
: callback that receives data from the HTTP resourcespollingInterval
: (optional) value in seconds to poll the HTTP resources
Hosting
Our data mirror service is open source and should be self-hosted. It does not use external dependencies such as a database or memory-cache and it can be deployed to any cloud provider such as Render, fly.io, Heroku. When hosting you will want to ensure the instance is always on so the service is able to continually poll resources. A Dockerfile can be found in the repository here if you are running your service in a container.