Send a message from L1 Goerli to L2 zkSync testnet.
There's two contracts; L1Contract.sol and L2Contract.sol
The L1 contract has a method sendGreetingMessageToL2 that sends a message to L2 contract to set a greeting message on L2 contract.
It sends the encoded calldata to execute setGreeting on L2 which can only be called if the message was sent by the L1 contract.
L2Contract.solL1Contract.soldeployL1.jsdeployL2.jssendL1ToL2Message.jswaitForInclusion.jsgetGreetingOnL2.js
git clone https://github.com/miguelmota/zksync-messenger-l1-to-l2-example.git
cd zksync-messenger-l1-to-l2-example
npm installCreate .env
PRIVATE_KEY=123...Make sure private key has funds on both zkSync testnet and Goerli.
npx hardhat compileCommand
npx hardhat run --network goerli scripts/deployL1.jsOutput
deployed to 0xbb027F3d45CEb4c9F8F1FaB6c7Bad5053A66c9b0Command
L1_CONTRACT=0xbb027F3d45CEb4c9F8F1FaB6c7Bad5053A66c9b0 \
npx hardhat deploy-zksync --network zksyncOutput
deployed to 0xdA90933EAC728c6e9AF0f5403514439a4Bb6ae90Command (replace env vars with your values)
GREETING="hello world" \
L1_CONTRACT=0xbb027F3d45CEb4c9F8F1FaB6c7Bad5053A66c9b0 \
L2_CONTRACT=0xdA90933EAC728c6e9AF0f5403514439a4Bb6ae90 \
npx hardhat run --network goerli scripts/sendL1ToL2Message.jsOutput
sent tx hash 0x70b1c11f608a2319fd07dc64f6a0de35ce4e1d483fe0c2a8f09be45c61fb035b
https://goerli.etherscan.io/tx/0x70b1c11f608a2319fd07dc64f6a0de35ce4e1d483fe0c2a8f09be45c61fb0Command
L1_TX_HASH=0x70b1c11f608a2319fd07dc64f6a0de35ce4e1d483fe0c2a8f09be45c61fb035b \
npx hardhat run --network zksync scripts/waitForInclusion.jsOutput
Waiting for L2 block inclusion (this may take up to 20 minutes)...
{
to: '0xdA90933EAC728c6e9AF0f5403514439a4Bb6ae90',
from: '0xbb027F3d45CEb4c9F8F1FaB6c7Bad5053A66c9b0',
contractAddress: null,
transactionIndex: 0,
...
l1BatchNumber: 626758,
l1BatchTxIndex: 123,
l2ToL1Logs: [ ... ],
byzantium: true
}Command
L2_CONTRACT=0xdA90933EAC728c6e9AF0f5403514439a4Bb6ae90 \
npx hardhat run --network zksync scripts/getGreetingOnL2.jsOutput
greeting: hello world