# @eth-optimism/watcher

> Watcher for cross domain messages

Latest version **0.0.1-alpha.9** (published 2021-02-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install @eth-optimism/watcher
pnpm add @eth-optimism/watcher
yarn add @eth-optimism/watcher
bun add @eth-optimism/watcher
```

## Health

**Score 35/100 (D)** — status: abandoned.

Positive: has types; no vulnerabilities; high maintenance score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 0.0.1-alpha.9 |
| Published | 2021-02-08 |
| First published | 2020-10-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 7.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6494 |
| Author | Optimism |
| Maintainers | karlfloersch, ben-chain, will_optimism, k-ho, tynes, kelvinfichter |
| Keywords | optimistic, rollup, group, ethereum, smart, contract |

## Links

- npm: https://www.npmjs.com/package/@eth-optimism/watcher
- Repository: https://github.com/ethereum-optimism/optimism-monorepo
- Homepage: https://github.com/ethereum-optimism/optimism-monorepo#readme
- Issues: https://github.com/ethereum-optimism/optimism-monorepo/issues
- npm.io page: https://npm.io/package/@eth-optimism/watcher

## Dependencies (1)

- [ethers](https://npm.io/package/ethers.md) 5.0.0

## Alternatives

- [raw-loader](https://npm.io/package/raw-loader.md) — 4.3M weekly downloads
- [plop](https://npm.io/package/plop.md) — 1.4M weekly downloads
- [webpack-deadcode-plugin](https://npm.io/package/webpack-deadcode-plugin.md) — 80.3K weekly downloads
- [@storybook/preact-vite](https://npm.io/package/@storybook/preact-vite.md) — 54.2K weekly downloads
- [vite-plugin-transform](https://npm.io/package/vite-plugin-transform.md) — 2.4K weekly downloads

## Recent versions

- 0.0.1-alpha.9 (latest) — 2021-02-08
- 0.0.1-alpha.8 — 2020-12-03
- 0.0.1-alpha.7 — 2020-12-03
- 0.0.1-alpha.6 — 2020-11-30
- 0.0.1-alpha.5 — 2020-11-30
- 0.0.1-alpha.4 — 2020-10-19
- 0.0.1-alpha.3 — 2020-10-09
- 0.0.1-alpha.2 — 2020-10-09
- 0.0.1-alpha.1 — 2020-10-09
- 0.0.1-alpha.0 — 2020-10-09

## README

# @eth-optimism/watcher

#### Watcher
Our `Watcher` allows you to retrieve all transaction hashes related to cross domain messages such as deposits and withdrawals. In order to use, first send a transaction which sends a cross domain message, for example a deposit from L1 into L2. After sending the deposit transaction and storing the transaction hash, use `getMessageHashesFromL1Tx(l1TxHash)` to get an array of the message hashes of all of the L1->L2 messages that were sent inside of that L1 tx (This will usually just be a single element array, but it can return multiple if one L1 transaction triggers multiple deposits). `getMessageHashesFromL2Tx(l2TxHash)` does the same for L2->L1 messages. `getL2TransactionReceipt(messageHash)` takes in an L1->L2 message hash and then after 2-5 minutes, returns the receipt of the L2 tx that the message ends up getting relayed in. `getL1TransactionReceipt(messageHash)` does the same for L2->L1 messages, except the delay is 7 days.

```typescript
import { Watcher } from '@eth-optimism/watcher'
import { JsonRpcProvider } from 'ethers/providers'

const watcher = new Watcher({
  l1: {
    provider: new JsonRpcProvider('INFURA_L1_URL'),
    messengerAddress: '0x...'
  },
  l2: {
    provider: new JsonRpcProvider('OPTIMISM_L2_URL'),
    messengerAddress: '0x...'
  }
})
const l1TxHash = (await depositContract.deposit(100)).hash
const [messageHash] = await watcher.getMessageHashesFromL1Tx(l1TxHash)
console.log('L1->L2 message hash:', messageHash)
const l2TxReceipt = await watcher.getL2TransactionReceipt(messageHash)
```

---
_Source: https://npm.io/package/@eth-optimism/watcher · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
