Data Bridge: Pass arbitrary messages between chains
Overview
Frequently, you need to send information from one chain to another. To do this, you can create a Data Bridge, a Midpoint that can receive messages from one chain and send them on to a contract on another chain.
Setup
To build a Data Bridge you need to construct three parts
The sending contract, which lives on one chain and sends the message.
The Midpoint itself, which observes the event and transfers it over to the other contract
The receiving contract
Creating the Midpoint
It’s almost always easiest to create the Midpoint first, because you need its ID to create the contracts, but as the the source and the task need the addresses of the contracts, you won’t be able to set up them up until after the contracts are created.
The sending contract
The job of the sending contract, whatever else it does, is to invoke a function on a special contract, called a Startpoint, provided on every chain as a portal to Midpoints.
The source for the sending contract should look something like this:
The actual value for startpointAddress
depends on the chain you are deploying on. For the list of values, see here: Startpoints
Note that you must invoke the Startpoint with a specially packed array of bytes. For more information about how to pack them, see here: Startpoint Called
The receiving contract
The receiving contract just have to have a public function that takes the appropriate arguments, something like this:
As with the the startpointAddress in the sending contract, the callbackAddress in the receiving contract depends on the chain that the receiving contract is deployed on. See here for values: Midpoint EOAs
Midpoint
$ npm install -g midpoint-cli
$ midpoint init blank my-data-feed
1 . Startpoint Called
$ midpoint add-source startpointCalledSource startpoint-called-source
We define the Startpoint Called source so that contract can make a midpoint request.
2. Transact To EVM Function
$ midpoint add-task transactToEvmFunctionTestnet post-subject-on-blockchain
We define the Transact to EVM Function Task to send the summary back to the contract.
3. Define Path
We define our path file.
4. Publish Midpoint
$ midpoint publish
Last updated