Getting Started with Interop Messages
This guide explains how to broadcast and verify an arbitrary message on any ZKsync chain by building a crosschain DeFi app.
What you'll learn:
- How interop messaging works
- How to broadcast an interop message
- How to verify the message on a ZKsync chain.
Tools:
- - zksync-ethers
- - hardhat
- - zksync-contracts
- - wagmi
- - viem
- - zkstack
In this tutorial, we will cover how interop messages work, how to send them, and how to verify them on any ZKsync chain that uses ZKsync Gateway.
- First, you will either set up a local ZKsync ecosystem with multiple chains for testing.
- Next, you will write and deploy smart contracts to send and verify messages onchain.
- Finally, you will integrate the template frontend to complete the app.
What We Are Building
We will be building a crosschain DeFi app that uses interop messaging via ZKsync Connect. The app will allow users to stake ETH on one chain, and then mint a token reward on another chain.
For this app we will create two contracts: a staking contract and a token contract.
The staking contract allows anyone to deposit and withdraw ETH. On the first deposit, the user's address is encoded and sent as an interop message.
The token contract allows users to mint some tokens if they can verify that they have previously deposited ETH to an approved staking contract on any other chain. The mint function will verify the message sent in the staking contract. The token contract will also track the number of mints for each staking chain.
Understanding Interop Messages
Interop messaging marks the first phase of universal interoperability for the Elastic Network. There are three phases planned for rolling out full interoperability:
- Messaging
- Asset transfers and bundles
- Crosschain transactions
Interop messaging with ZKsync Connect enables sending and verifying messages across ZKsync chains via ZKsync Gateway. An interop message consists of arbitrary data and has two simple properties:
- Anyone can send a message.
- Anyone can verify that a given message was successfully sent on some chain.
The message itself has no destination chain or address. It’s simply a payload created by a user or contract that gets broadcast. There is no expiration for when messages can be verified. They remain verifiable indefinitely.
These messages are the foundation to unlock more complex crosschain activities in the future, ike bridging assets and calling contracts across different chains.
Interop messages currently DO NOT have:
- 🚫 support for selecting destination chains
- 🚫 nullifiers or replay protection
- 🚫 a cancellation mechanism
- 🚫 support for sending assets or calling contracts
These limitations will be addressed in stages 2 and 3 of full universal interoperability.
To learn more in-depth about the lifecycle of interop messages, check out the ZKsync Connect messaging page.
Ecosystem Setup
Before writing any code, you must setup a local ecosystem with a few interoperable ZKsync chains.
To setup a local multichain ecosystem, follow the instructions in the multichain ecosystem tutorial. Then continue to the next section.