客户端守护进程模式和 HTTP API

除了 CLI 和 JSON 模式外,Walrus 客户端还提供 _daemon 模式。在此模式下,它运行一个简单的 Web 服务器,分别在 aggregatorpublisher 角色中提供存储和读取 blob 的 HTTP 接口。我们还提供 公共聚合器和发布者服务 以尝试 Walrus HTTP API,而无需运行本地客户端。

本地启动守护进程

您可以使用以下命令运行守护进程,在同一地址 (127.0.0.1) 和端口 (31415) 上同时提供聚合器和发布者:

walrus daemon -b "127.0.0.1:31415"

或者,您可以在不同的地址/端口上分别运行聚合器和发布者进程:

walrus aggregator -b "127.0.0.1:31415" # 运行聚合器以读取 blob
walrus publisher -b "127.0.0.1:31416" # 运行发布者以存储 blob

聚合器提供所有读取 API,发布者提供所有存储 API,守护进程提供两者。

Warning

While the aggregator does not perform Sui on-chain actions, and therefore consumes no gas, the publisher does perform actions on-chain and will consume gas. It is therefore important to ensure only authorized parties may access it, or other measures to manage gas costs.

使用公共聚合器或发布者

对于某些用例(例如,公共网站),或者只是尝试 HTTP API,需要一个公开可访问的聚合器和/或发布者。几家公司运行此类聚合器和发布者,请参阅下面的公共 聚合器发布者 列表。

公共发布者默认将请求限制为 10 MiB。如果您想上传更大的文件,您需要 运行自己的发布者 或使用 CLI

另外,请注意,发布者在服务端消耗 (Testnet) SUI 和 WAL,主网部署可能无法在不要求某些身份验证和补偿所用资金的情况下提供不受控制的公共发布访问。

公共聚合器

以下是已知公共聚合器的列表;它们会定期检查,但每个聚合器可能仍会暂时不可用:

  • https://aggregator.walrus-testnet.walrus.space
  • https://wal-aggregator-testnet.staketab.org
  • https://walrus-testnet-aggregator.bartestnet.com
  • https://walrus-testnet.blockscope.net
  • https://walrus-testnet-aggregator.nodes.guru
  • https://walrus-cache-testnet.overclock.run
  • https://sui-walrus-testnet.bwarelabs.com/aggregator
  • https://walrus-testnet-aggregator.stakin-nodes.com
  • https://testnet-aggregator-walrus.kiliglab.io
  • https://walrus-cache-testnet.latitude-sui.com
  • https://walrus-testnet-aggregator.nodeinfra.com
  • https://walrus-tn.juicystake.io:9443
  • https://walrus-agg-testnet.chainode.tech:9002
  • https://walrus-testnet-aggregator.starduststaking.com:11444
  • http://walrus-testnet-aggregator.everstake.one:9000
  • http://walrus.testnet.pops.one:9000
  • http://scarlet-brussels-376c2.walrus.bdnodes.net:9000
  • http://aggregator.testnet.sui.rpcpool.com:9000
  • http://walrus.krates.ai:9000
  • http://walrus-testnet.stakingdefenseleague.com:9000
  • http://walrus.sui.thepassivetrust.com:9000

公共发布者

  • https://publisher.walrus-testnet.walrus.space
  • https://wal-publisher-testnet.staketab.org
  • https://walrus-testnet-publisher.bartestnet.com
  • https://walrus-testnet-publisher.nodes.guru
  • https://sui-walrus-testnet.bwarelabs.com/publisher
  • https://walrus-testnet-publisher.stakin-nodes.com
  • https://testnet-publisher-walrus.kiliglab.io
  • https://walrus-testnet-publisher.nodeinfra.com
  • https://walrus-testnet.blockscope.net:11444
  • https://walrus-publish-testnet.chainode.tech:9003
  • https://walrus-testnet-publisher.starduststaking.com:11445
  • http://walrus-publisher-testnet.overclock.run:9001
  • http://walrus-testnet-publisher.everstake.one:9001
  • http://walrus.testnet.pops.one:9001
  • http://ivory-dakar-e5812.walrus.bdnodes.net:9001
  • http://publisher.testnet.sui.rpcpool.com:9001
  • http://walrus.krates.ai:9001
  • http://walrus-publisher-testnet.latitude-sui.com:9001
  • http://walrus-tn.juicystake.io:9090
  • http://walrus-testnet.stakingdefenseleague.com:9001
  • http://walrus.sui.thepassivetrust.com:9001

HTTP API 使用

对于以下示例,我们假设您将 AGGREGATORPUBLISHER 环境变量设置为您所需的聚合器和发布者。例如:

AGGREGATOR=https://aggregator.walrus-testnet.walrus.space
PUBLISHER=https://publisher.walrus-testnet.walrus.space

API specification

Walrus aggregators and publishers expose their API specifications at the path /v1/api. You can view this in the browser, e.g., at https://aggregator.walrus-testnet.walrus.space/v1/api

存储

您可以通过简单的 HTTP PUT 请求与守护进程交互。例如,使用 cURL,您可以使用发布者或守护进程存储 blob,如下所示:

curl -X PUT "$PUBLISHER/v1/store" -d "some string" # 将字符串 `some string` 存储 1 个存储周期
curl -X PUT "$PUBLISHER/v1/store?epochs=5" --upload-file "some/file" # 将文件 `some/file` 存储 5 个存储周期

存储 HTTP API 端点以 JSON 格式返回有关存储的 blob 的信息。当首次存储 blob 时,newlyCreated 字段包含有关新 blob 的信息:

$ curl -X PUT "$PUBLISHER/v1/store" -d "some other string"
{
  "newlyCreated": {
    "blobObject": {
      "id": "0xd765d11848cbac5b1f6eec2fbeb343d4558cbe8a484a00587f9ef5385d64d235",
      "storedEpoch": 0,
      "blobId": "Cmh2LQEGJwBYfmIC8duzK8FUE2UipCCrshAYjiUheZM",
      "size": 17,
      "erasureCodeType": "RedStuff",
      "certifiedEpoch": 0,
      "storage": {
        "id": "0x28cc75b33e31b3e672646eacf1a7c7a2e5d638644651beddf7ed4c7e21e9cb8e",
        "startEpoch": 0,
        "endEpoch": 1,
        "storageSize": 4747680
      }
    },
    "encodedSize": 4747680,
    "cost": 231850
  }
}

返回的信息是 Sui blob 对象 的内容。

当聚合器找到具有相同 blob ID 和足够有效期的已认证 blob 时,它会返回一个 alreadyCertified JSON 结构:

$ curl -X PUT "$PUBLISHER/v1/store" -d "some other string"
{
  "alreadyCertified": {
    "blobId": "Cmh2LQEGJwBYfmIC8duzK8FUE2UipCCrshAYjiUheZM",
    "event": {
      "txDigest": "CLE41JTPR2CgZRC1gyKK6P3xpQRHCetQMsmtEgqGjwst",
      "eventSeq": "0"
    },
    "endEpoch": 1
  }
}

字段 event 返回 Sui 事件 ID,可用于查找在 Sui explorer 上创建 Sui Blob 对象的交易或使用 Sui SDK。

读取

可以使用 HTTP GET 从聚合器或守护进程读取 blob。例如,以下 cURL 命令读取一个 blob 并将其写入输出文件:

curl "$AGGREGATOR/v1/<some blob ID>" -o <some file name>

或者,您可以使用 cURL 命令在终端中打印 blob 的内容:

curl "$AGGREGATOR/v1/<some blob ID>"

Content sniffing

Modern browsers will attempt to sniff the content type for such resources, and will generally do a good job of inferring content types for media. However, the aggregator on purpose prevents such sniffing from inferring dangerous executable types such as JavaScript or style sheet types.