Send a message from L2 Scroll zkEVM testnet to L1 Goerli.
There's two contracts; L2Contract.sol and L1Contract.sol
The L2 contract has a method sendGreetingMessageToL1 that sends a message form L2 to L1 contract to set a greeting message on L1 contract.
It sends the encoded calldata to execute setGreeting on L1 which can only be called if the message was sent by the L2 contract.
L2Contract.solL1Contract.soldeployL2.jsdeployL1.jsgetRelayFee.jssendL2ToL1Message.jsgetGreetingOnL1.js
git clone https://github.com/miguelmota/scroll-messenger-l2-to-l1-example.git
cd scroll-messenger-l2-to-l1-example
npm installCreate .env
PRIVATE_KEY=123...Make sure private key has funds on both Scroll zkEVM testnet and Goerli.
npx hardhat compileCommand
npx hardhat run --network scroll scripts/deployL2.jsOutput
L2Contract deployed to: 0x32EdD9E855F92C6Db51B86D5d004C6E7d11018a1Command
L2_CONTRACT=0x32EdD9E855F92C6Db51B86D5d004C6E7d11018a1 \
npx hardhat run --network goerli scripts/deployL1.jsOutput
L1Contract deployed to: 0xc99668601516205D2305383c96134814b1f2CC11Command
npx hardhat run --network scroll scripts/getRelayFee.jsOutput
l1BaseFee: 0.000000015391181204
gasLimit: 500000
fee: 0.007695590602Command (replace env vars with your values)
GREETING="hello world" \
L2_CONTRACT=0x32EdD9E855F92C6Db51B86D5d004C6E7d11018a1 \
L1_CONTRACT=0xc99668601516205D2305383c96134814b1f2CC11 \
npx hardhat run --network scroll scripts/sendL2ToL1Message.jsOutput
sent tx hash 0x6ad8593e5aaf05496de0585f4e5dba9940c6268a1006df8160af6d5b1aa94210
https://blockscout.scroll.io/tx/0x6ad8593e5aaf05496de0585f4e5dba9940c6268a1006df8160af6d5b1aa94210Command (Note: it can take a few minutes to hours after sending from L2 to see updated state on L1)
L1_CONTRACT=0xc99668601516205D2305383c96134814b1f2CC11 \
npx hardhat run --network goerli scripts/getGreetingOnL1.jsOutput
greeting: hello worldSee https://github.com/miguelmota/scroll-messenger-l1-to-l2-example