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.solL2Contract.soldeployL1.jsdeployL2.jsgetRelayFee.jssendL1ToL2Message.jsgetGreetingOnL2.js
git clone https://github.com/miguelmota/scroll-messenger-l1-to-l2-example.git
cd scroll-messenger-l1-to-l2-example
npm installCreate .env
PRIVATE_KEY=123...Make sure private key has funds on both Goerli and Scroll zkEVM testnet.
npx hardhat compileCommand
npx hardhat run --network goerli scripts/deployL1.jsOutput
L1Contract deployed to: 0x41Ed7bd26747d2BE681795443C9e76c7fa3f9880Command
L1_CONTRACT=0x41Ed7bd26747d2BE681795443C9e76c7fa3f9880 \
npx hardhat run --network scroll scripts/deployL2.jsOutput
L2Contract deployed to: 0x6310B81901A64DDF04Ca83fc9904Df9833721d4FCommand
npx hardhat run --network goerli scripts/getRelayFee.jsOutput
l2BaseFee: 0.00000000002
gasLimit: 500000
fee: 0.00001Command (replace env vars with your values)
GREETING="hello world" \
L1_CONTRACT=0x41Ed7bd26747d2BE681795443C9e76c7fa3f9880 \
L2_CONTRACT=0x6310B81901A64DDF04Ca83fc9904Df9833721d4F \
npx hardhat run --network goerli scripts/sendL1ToL2Message.jsOutput
sent tx hash 0xf684e3bd4f176f86be5ee4664765a1d6af74096eedbbf001ead36bf8302c0bb0
https://goerli.etherscan.io/tx/0xf684e3bd4f176f86be5ee4664765a1d6af74096eedbbf001ead36bf8302c0bb0Command (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.jsOutput
greeting: hello worldSee https://github.com/miguelmota/scroll-messenger-l2-to-l1-example