miguelmota / scroll-messenger-l2-to-l1-example

Send a message from L2 Scroll zkEVM testnet to L1 Goerli.

Home Page:https://github.com/miguelmota/scroll-messenger-l2-to-l1-example

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Scroll zkEVM Messenger L2->L1 Example

Send a message from L2 Scroll zkEVM testnet to L1 Goerli.

Example

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.

Files

Install

git clone https://github.com/miguelmota/scroll-messenger-l2-to-l1-example.git
cd scroll-messenger-l2-to-l1-example
npm install

Set Signer

Create .env

PRIVATE_KEY=123...

Make sure private key has funds on both Scroll zkEVM testnet and Goerli.

Compile Contracts

npx hardhat compile

Deploy L2 Contract

Command

npx hardhat run --network scroll scripts/deployL2.js

Output

L2Contract deployed to: 0x32EdD9E855F92C6Db51B86D5d004C6E7d11018a1

Deploy L1 Contract

Command

L2_CONTRACT=0x32EdD9E855F92C6Db51B86D5d004C6E7d11018a1 \
npx hardhat run --network goerli scripts/deployL1.js

Output

L1Contract deployed to: 0xc99668601516205D2305383c96134814b1f2CC11

Get Relay Fee

Command

npx hardhat run --network scroll scripts/getRelayFee.js

Output

l1BaseFee: 0.000000015391181204
gasLimit: 500000
fee: 0.007695590602

Send L2->L1 Message

Command (replace env vars with your values)

GREETING="hello world" \
L2_CONTRACT=0x32EdD9E855F92C6Db51B86D5d004C6E7d11018a1 \
L1_CONTRACT=0xc99668601516205D2305383c96134814b1f2CC11 \
npx hardhat run --network scroll scripts/sendL2ToL1Message.js

Output

sent tx hash 0x6ad8593e5aaf05496de0585f4e5dba9940c6268a1006df8160af6d5b1aa94210
https://blockscout.scroll.io/tx/0x6ad8593e5aaf05496de0585f4e5dba9940c6268a1006df8160af6d5b1aa94210

Get Greeting on L1

Command (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.js

Output

greeting: hello world

Send L1->L2 Message

See https://github.com/miguelmota/scroll-messenger-l1-to-l2-example

License

MIT @ Miguel Mota

About

Send a message from L2 Scroll zkEVM testnet to L1 Goerli.

https://github.com/miguelmota/scroll-messenger-l2-to-l1-example

License:MIT License


Languages

Language:JavaScript 58.0%Language:Solidity 42.0%