OP Stack interop is in active development. Some features may be experimental.
Messages are relayed automatically in the interop devnet.
Overview
Learn to relay transactions directly by sending the correct transaction.What you’ll build
- A program to relay messages using the JavaScript library
- A shell script to relay messages using
cast
Setup
These steps are necessary to run the tutorial, regardless of whether you are usingcast or the JavaScript API.
Run Supersim
This exercise needs to be done on Supersim.
You cannot use the devnets because you cannot disable autorelay on them.
You cannot use the devnets because you cannot disable autorelay on them.
- Follow the installation guide.
- Run Supersim without
--interop.relay.
Create the state for relaying messages
The results of this step are similar to what the message passing tutorial would produce if you did not have autorelay on.Execute this script:This script installs
These smart contracts let us send a message from chain A that needs to be relayed to chain B.Then, the script creates
That script is explained below.Finally, this script writes out some parameter setting lines that should be executed on the main shell before you continue.
With a fresh Supersim running, these should be:
Greeter.sol on chain B and GreetingSender.sol on chain A.These smart contracts let us send a message from chain A that needs to be relayed to chain B.Then, the script creates
./manual-relay/sendAndRelay.sh to manually relay a message from chain A to chain B.That script is explained below.Finally, this script writes out some parameter setting lines that should be executed on the main shell before you continue.
With a fresh Supersim running, these should be:
Manual relay using the API
Setup
Manual relay using cast
You can see an example of how to manually relay using cast in manual-relay/sendAndRelay.sh.It is somewhat complicated, so the setup creates one that is tailored to your environment. Run the script:
-
Configuration parameters
This is the configuration. The greeter addresses are identical because the nonce for the user address has an identical nonce on both chains.
-
Send a message that needs to be relayed
Send a message from chain A to chain B. The
$$is the process ID, so if you rerun the script you’ll see that the information changes. -
Find the log entry to relay
Whenever
L2ToL2CrossDomainMessengersends a message to a different blockchain, it emits aSendMessageevent. Extract only the latestSendMessageevent from the logs. -
Manipulate the log entry to obtain information
Consolidate the log topics into a single hex string.Read additional fields from the log entry.Consolidate the entire log entry.
- Create the access list for the executing message
admin_getAccessListByMsgHash RPC call is not a pure function, it is dependent on system state and therefore less flexible in these situations.
-
Show that the manual relay is necessary
Show the current greeting. The message has not been relayed yet, so it’s still the old greeting.
-
Actually relay the message
Call
relayMessageto relay the message. -
Show the relay results
Again, show the current greeting. Now it’s the new one.
Next steps
- Review the [OP Stack interop explainer](/> op-stack/interop/explainer) for answers to common questions about interoperability.
- Read the message passing explainer to understand what happens “under the hood”.
- Write a revolutionary app that uses multiple blockchains within the OP Stack ecosystem.