Send a message from L1 Goerli to L2 Scroll 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.
L1Contract.sol
L2Contract.sol
deployL1.js
deployL2.js
getRelayFee.js
sendL1ToL2Message.js
getGreetingOnL2.js
git clone https://github.com/miguelmota/scroll-messenger-l1-to-l2-example.git
cd scroll-messenger-l1-to-l2-example
npm install
Create .env
PRIVATE_KEY=123...
Make sure private key has funds on both Goerli and Scroll zkEVM testnet.
npx hardhat compile
Command
npx hardhat run --network goerli scripts/deployL1.js
Output
L1Contract deployed to: 0x41Ed7bd26747d2BE681795443C9e76c7fa3f9880
Command
L1_CONTRACT=0x41Ed7bd26747d2BE681795443C9e76c7fa3f9880 \
npx hardhat run --network scroll scripts/deployL2.js
Output
L2Contract deployed to: 0x6310B81901A64DDF04Ca83fc9904Df9833721d4F
Command
npx hardhat run --network goerli scripts/getRelayFee.js
Output
l2BaseFee: 0.00000000002
gasLimit: 500000
fee: 0.00001
Command (replace env vars with your values)
GREETING="hello world" \
L1_CONTRACT=0x41Ed7bd26747d2BE681795443C9e76c7fa3f9880 \
L2_CONTRACT=0x6310B81901A64DDF04Ca83fc9904Df9833721d4F \
npx hardhat run --network goerli scripts/sendL1ToL2Message.js
Output
sent tx hash 0xf684e3bd4f176f86be5ee4664765a1d6af74096eedbbf001ead36bf8302c0bb0
https://goerli.etherscan.io/tx/0xf684e3bd4f176f86be5ee4664765a1d6af74096eedbbf001ead36bf8302c0bb0
Command (Note: must wait 8-14 minutes after sending from L1 to see updated state on L2)
L2_CONTRACT=0x6310B81901A64DDF04Ca83fc9904Df9833721d4F \
npx hardhat run --network scroll scripts/getGreetingOnL2.js
Output
greeting: hello world
See https://github.com/miguelmota/scroll-messenger-l2-to-l1-example