Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

第 5 章 读取、下载与状态查询

学习目标

  • 使用 walrus read 把 Blob 写到 stdout 或文件。
  • 使用 walrus blob-status 按 Blob ID 或本地文件查询状态。
  • 理解一致性检查相关参数。

前置条件

  • 已上传第 4 章的 files/hello.txt
  • 已设置 BLOB_ID
echo "$BLOB_ID"

如果没有变量,先从上一章上传输出里复制。

查询状态

按 Blob ID 查询:

walrus blob-status --blob-id "$BLOB_ID" --context testnet

按本地文件查询:

walrus blob-status --file files/hello.txt --context testnet

--file 会根据本地文件内容重新计算 Blob ID,再查询链上和网络状态。它适合验证“这个具体文件是否已存储”。

读取到终端

文本 Blob 可以直接输出:

walrus read "$BLOB_ID" --context testnet

二进制文件不要直接输出到终端,使用 --out

下载到文件

mkdir -p downloads

walrus read "$BLOB_ID" \
  --out downloads/hello.downloaded.txt \
  --context testnet

验证内容:

diff files/hello.txt downloads/hello.downloaded.txt

diff 没有输出表示两个文件一致。

使用自定义 RPC

一般使用配置文件即可。需要临时指定 Sui RPC 时:

walrus read "$BLOB_ID" \
  --out downloads/hello.rpc.txt \
  --rpc-url https://fullnode.testnet.sui.io:443 \
  --context testnet

一致性检查

默认一致性检查已经适合大多数读取场景。需要更严格检查时:

walrus read "$BLOB_ID" \
  --out downloads/hello.strict.txt \
  --strict-consistency-check \
  --context testnet

只有在你完全信任写入者且理解风险时,才考虑跳过检查:

walrus read "$BLOB_ID" \
  --out downloads/hello.fast.txt \
  --skip-consistency-check \
  --context testnet

输出解读

blob-status 可用时会返回存储状态、可用期,以及 BlobCertified Sui event ID。这个事件表示该 Blob 的可用性已经被认证。

read --out 成功时,重点检查:

  • 目标文件是否存在。
  • 文件大小是否符合预期。
  • 对文本或确定性文件,diff 是否一致。
ls -lh files/hello.txt downloads/hello.downloaded.txt

常见坑

  • read 默认写 stdout,下载图片、压缩包、数据库快照时必须加 --out
  • Blob 过期后读取会失败;先用 blob-status 看 end epoch。
  • blob-status --file 查询的是文件内容对应的 Blob ID,文件改一个字节就是另一个 Blob。
  • --skip-consistency-check 不是性能开关的默认选择,它会降低读取验证强度。

下一步

下一章管理 Blob 生命周期:延长、删除、burn、共享和属性。