Send a message from L1 Goerli to L2 ConsenSys zkEVM testnet.
There's two contracts; L2Contract.sol
and L1Contract.sol
The L1 contract has a method sendMessageToL2
that sends a message from L1 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.sol
L1Contract.sol
deployL2.js
deployL1.js
getRelayFee.js
sendL1ToL2Message.js
getGreetingOnL2.js
git clone https://github.com/miguelmota/consensys-zkevm-messenger-l1-to-l2-example.git
cd consensys-zkevm-messenger-l1-to-l2-example
npm install
Create .env
PRIVATE_KEY=123...
Make sure private key has funds on both Goerli and ConsenSys zkEVM testnet.
npx hardhat compile
Command
npx hardhat run --network goerli scripts/deployL1.js
Output
L1Contract deployed to: 0x909c35f179c7cD151781f151A4d2a75528A8d2Fa
Command
L1_CONTRACT=0x909c35f179c7cD151781f151A4d2a75528A8d2Fa \
npx hardhat run --network consensyszk scripts/deployL2.js
Output
L2Contract deployed to: 0x0ef7281E3f746df91A350859271A8220F4B16519
Command
npx hardhat run --network goerli scripts/getRelayFee.js
Output
fee: 0.01
Command (replace env vars with your values)
GREETING="hello world" \
L2_CONTRACT=0x0ef7281E3f746df91A350859271A8220F4B16519 \
L1_CONTRACT=0x909c35f179c7cD151781f151A4d2a75528A8d2Fa \
npx hardhat run --network goerli scripts/sendL1ToL2Message.js
Output
sent tx hash 0x17d307327fea6e42837fb4e2ff0c3f6d2f6d8e95f659ac0cabd5a973c8d9a4f1
https://goerli.etherscan.io/tx/0x17d307327fea6e42837fb4e2ff0c3f6d2f6d8e95f659ac0cabd5a973c8d9a4f1
Command
L2_CONTRACT=0x0ef7281E3f746df91A350859271A8220F4B16519 \
npx hardhat run --network consensyszk scripts/getGreetingOnL2.js
Output
greeting: hello world
See https://github.com/miguelmota/consensys-zkevm-messenger-l1-to-l2-example