Arbitrum: L1 to L2 messaging smart contract

🚧

Deprecation notice

As the Goerli testnet has been deprecated, this guide is for historical reference.

Sending a message from the Ethereum chain (L1) to the Arbitrum chain (L2) does not involve the state challenge period and is as fast as the block confirmation time on L1 and L2 combined.

In this tutorial, you will:

  • Deploy greeter contracts on Ethereum and on Arbitrum.
  • Send a message from the greeter contract deployed on Ethereum (L1) to the greeter contract deployed on Arbitrum (L2).

Prerequisites

Overview

To get from zero to your first L1 to L2 message, do the following:

  1. With Chainstack, create a public chain project.
  2. With Chainstack, join the Ethereum Goerli testnet.
  3. With Chainstack, join the Arbitrum Goerli testnet.
  4. Set up your MetaMask to work through the Chainstack Ethereum and Arbitrum nodes.
  5. Fund your account through a faucet on the Ethereum Goerli testnet and on the Arbitrum Goerli testnet.
  6. Run the tutorial script to deploy the contracts on L1 and L2 and send the message from L1 to L2.

Step-by-step

Create a public chain project

See Create a project.

Join the Ethereum and Arbitrum Goerli testnets

Deploy a node on the Ethereum Goerli testnet and a node on the Arbitrum Goerli testnet.

See Join a public network.

Get the access and credentials to your deployed nodes

See View node access and credentials.

Set up MetaMask

See Arbitrum tooling: MetaMask.

Fund your account

Your account will need Goerli ether on both the Ethereum Goerli testnet and the Arbitrum Goerli testnet as you will deploy a contract on each of the chains.

The default Arbitrum Goerli faucet may fund your account with 0.001 GoerliETH, which is not enough to deploy the greeter contract on L2.

If you do not have enough GoerliETH on L2, you may bridge some more from the Ethereum Goerli testnet using the Arbitrum bridge.

Clone and prepare the tutorials repository

You will use the Offchain Labs tutorials repository to deploy the contracts and send the message.

Clone the repository:

git clone https://github.com/OffchainLabs/arbitrum-tutorials.git

Change to arbitrum-tutorials/packages/greeter.

Install dependencies by running yarn.

Set up the .env file by renaming the sample one in arbitrum-tutorials/packages/greeter:

cp .env-sample .env

In the .env file, add your account key and the endpoints:

  • DEVNET_PRIVKEY — the private key of your account that has GoerliETH both on the Ethereum Goerli testnet and the Arbitrum Goerli testnet.
  • L2RPC — the Chainstack HTTPS endpoint of your Arbitrum node deployed on the Arbitrum Goerli testnet.
  • L1RPC — the Chainstack HTTPS endpoint of your Ethereum node deployed on the Ethereum Goerli testnet.

Example:

DEVNET_PRIVKEY=YOUR_DEVNET_PRIVATE_KEY
L2RPC=YOUR_CHAINSTACK_ENDPOINT
L1RPC=YOUR_CHAINSTACK_ENDPOINT

Deploy the contract and send the message from L1 to L2

You are now all set to run the tutorial script that will deploy the greeter contracts and send a message from L1 to L2.

In arbitrum-tutorials/packages/greeter, run:

yarn run greeter

The script will:

Conclusion

This tutorial guided you through the basics of creating and deploying a simple greeter contract that sends a message from the Ethereum chain to the Arbitrum chain. The tutorial also provided the examples and an explanation of the step-by-step state changes and the contracts involved in the L1 to L2 messaging.

About the author

Ake

🛠️ Developer Experience Director @ Chainstack
💸 Talk to me all things Web3 infrastructure and I'll save you the costs
Ake | Warpcast Ake | GitHub Ake | Twitter Ake | LinkedIN