GithubHelp home page GithubHelp logo

miguelmota / scroll-messenger-l1-to-l2-example Goto Github PK

View Code? Open in Web Editor NEW
6.0 2.0 3.0 173 KB

Send a message from L1 Goerli to L2 Scroll zkEVM testnet

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

License: MIT License

Solidity 43.38% JavaScript 56.62%
bridge cross-chain ethereum example hardhat l1 l2 messenger multi-chain scroll scroll-zkevm solidity tutorial zk zkevm

scroll-messenger-l1-to-l2-example's Introduction

Scroll zkEVM Messenger L1->L2 Example

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

Example

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.

Files

Install

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

Set Signer

Create .env

PRIVATE_KEY=123...

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

Compile Contracts

npx hardhat compile

Deploy L1 Contract

Command

npx hardhat run --network goerli scripts/deployL1.js

Output

L1Contract deployed to: 0x41Ed7bd26747d2BE681795443C9e76c7fa3f9880

Deploy L2 Contract

Command

L1_CONTRACT=0x41Ed7bd26747d2BE681795443C9e76c7fa3f9880 \
npx hardhat run --network scroll scripts/deployL2.js

Output

L2Contract deployed to: 0x6310B81901A64DDF04Ca83fc9904Df9833721d4F

Get Relay Fee

Command

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

Output

l2BaseFee: 0.00000000002
gasLimit: 500000
fee: 0.00001

Send L1->L2 Message

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

Get Greeting on L2

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

Send L2->L1 Message

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

License

MIT @ Miguel Mota

scroll-messenger-l1-to-l2-example's People

Contributors

miguelmota avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.