|
1 | | -[](https://codecov.io/gh/ethereum-optimism/optimism) |
2 | 1 | # @eth-optimism/message-relayer |
3 | 2 |
|
4 | | -This package contains: |
5 | | - |
6 | | -1. A service for relaying messages from L2 to L1. |
7 | | -2. Utilities for finding these messages and relaying them. |
| 3 | +`message-relayer` is a service that automatically finalizes ("relays") messages sent from Optimism to Ethereum. |
| 4 | +This package is meant to be used during local development and should NOT be used on a production network. |
8 | 5 |
|
9 | 6 | ## Installation |
10 | 7 |
|
| 8 | +Clone, install, and build the Optimism monorepo: |
| 9 | + |
11 | 10 | ``` |
12 | | -yarn add @eth-optimism/message-relayer |
| 11 | +git clone https://github.com/ethereum-optimism/optimism.git |
| 12 | +yarn install |
| 13 | +yarn build |
13 | 14 | ``` |
14 | 15 |
|
15 | | -## Relay Utilities |
16 | | - |
17 | | -### getMessagesAndProofsForL2Transaction |
18 | | - |
19 | | -Finds all L2 => L1 messages sent in a given L2 transaction and generates proof for each. |
20 | | - |
21 | | -#### Usage |
| 16 | +## Running the relayer (Docker) |
22 | 17 |
|
23 | | -```typescript |
24 | | -import { getMessagesAndProofsForL2Transaction } from '@eth-optimism/message-relayer' |
| 18 | +The `message-relayer` can be included as part of the [local Optimism development environment](https://community.optimism.io/docs/developers/build/dev-node/). |
| 19 | +Although the `message-relayer` is not turned on by default, it can be enabled by [changing this line in docker-compose.yml](https://github.com/ethereum-optimism/optimism/blob/51a527b8e3fe69940fb8c0f5e4aa2e0ae8ee294c/ops/docker-compose.yml#L129) to: |
25 | 20 |
|
26 | | -const main = async () => { |
27 | | - const l1RpcProviderUrl = 'https://layer1.endpoint' |
28 | | - const l2RpcProviderUrl = 'https://layer2.endpoint' |
29 | | - const l1StateCommitmentChainAddress = 'address of StateCommitmentChain from deployments page' |
30 | | - const l2CrossDomainMessengerAddress = 'address of L2CrossDomainMessenger from deployments page' |
31 | | - const l2TransactionHash = 'hash of the transaction with messages to relay' |
32 | | - |
33 | | - const messagePairs = await getMessagesAndProofsForL2Transaction( |
34 | | - l1RpcProviderUrl, |
35 | | - l2RpcProviderUrl, |
36 | | - l1StateCommitmentChainAddress, |
37 | | - l2CrossDomainMessengerAddress, |
38 | | - l2TransactionHash |
39 | | - ) |
| 21 | +``` |
| 22 | +replicas: 1 |
| 23 | +``` |
40 | 24 |
|
41 | | - console.log(messagePairs) |
42 | | - // Will log something along the lines of: |
43 | | - // [ |
44 | | - // { |
45 | | - // message: { |
46 | | - // target: '0x...', |
47 | | - // sender: '0x...', |
48 | | - // message: '0x...', |
49 | | - // messageNonce: 1234... |
50 | | - // }, |
51 | | - // proof: { |
52 | | - // // complicated |
53 | | - // } |
54 | | - // } |
55 | | - // ] |
| 25 | +## Running the relayer (manual) |
56 | 26 |
|
57 | | - // You can then do something along the lines of: |
58 | | - // for (const { message, proof } of messagePairs) { |
59 | | - // await l1CrossDomainMessenger.relayMessage( |
60 | | - // message.target, |
61 | | - // message.sender, |
62 | | - // message.message, |
63 | | - // message.messageNonce, |
64 | | - // proof |
65 | | - // ) |
66 | | - // } |
67 | | -} |
| 27 | +The `message-relayer` can also be run manually. |
| 28 | +Copy `.env.example` into a new file named `.env`, then set the environment variables listed there. |
| 29 | +Once your environment variables have been set, run the relayer via: |
68 | 30 |
|
69 | | -main() |
| 31 | +``` |
| 32 | +yarn start |
70 | 33 | ``` |
0 commit comments