@eth-optimism/watcher

中文文档
0.0.1-alpha.9发布于 2021/02/08MITTypeScriptCommonJS近 30 天下载 2498

Watcher for cross domain messages

原始使用文档

@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.

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)

版本与发布记录

@eth-optimism/watcher 共发布 10 个版本,首次发布于 2020/10/09;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.0.1-alpha.9latest2021/02/085 年前
0.0.1-alpha.82020/12/035 年前
0.0.1-alpha.72020/12/035 年前
0.0.1-alpha.62020/11/305 年前
0.0.1-alpha.52020/11/305 年前
0.0.1-alpha.42020/10/206 年前

关于 @eth-optimism/watcher 的常见问题

@eth-optimism/watcher 是什么?

Watcher for cross domain messages

如何安装 @eth-optimism/watcher?

在项目目录运行 npm install @eth-optimism/watcher,或使用 pnpm add / yarn add / bun add。

@eth-optimism/watcher 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@eth-optimism/watcher 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@eth-optimism/watcher 可以商用吗?

@eth-optimism/watcher 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@eth-optimism/watcher 的下载量有多少?

根据 npm 官方下载统计,@eth-optimism/watcher 在 2026/10/14 – 2026/11/12 这 30 天内被下载 2,498 次,日均约 83 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@eth-optimism/watcher 还在维护吗?

最新版本 0.0.1-alpha.9 发布于 2021/02/08(5 年前);至今共发布 10 个版本,其中过去 12 个月发布了 0 个;首次发布于 2020/10/09。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。