@dashevo/dapi-grpc

中文文档
5.0.3发布于 2026/11/04MITCommonJS近 30 天下载 4710

DAPI GRPC definition file and generated clients

原始使用文档
文档目录9 节
  1. Table of Contents
  2. Install
  3. Usage
  4. Core Client
  5. Platform Client
  6. Maintainer
  7. Contributing
  8. License
  9. Building generated clients

DAPI GRPC

Build Status NPM version Release Date license

Decentralized API GRPC definition files and generated clients

Table of Contents

Install

Ensure you have the latest NodeJS installed.

From repository

Clone the repo:

git clone https://github.com/dashevo/dapi-grpc

Install npm packages:

npm install

From NPM

npm install @dashevo/dapi-grpc

Usage

Node users are able to access exported elements by requiring them under v0 property.

Core Client

Provide a client to perform core request.

const {
  v0: {
    CorePromiseClient,
  },
} = require('@dashevo/dapi-grpc');

const client = new CorePromiseClient(url);

Provided method allow to then perform the request, by passing a specific request parameter (see below example). All methods share the same API :

  • First parameter expect a specific request instance of a Request class (such as GetBlockRequest, GetTransactionRequest).
  • Second parameter is optional for metadata object.
  • Third parameter is optional for options.

Here is a usage example for requesting a Block by its hash and handling its response :

const {
  v0: {
    CorePromiseClient,
    GetBlockRequest,
    GetBlockResponse,
  },
} = require('@dashevo/dapi-grpc');

const client = new CorePromiseClient(url);

async function getBlockByHash(hash, options = {}) {
  const getBlockRequest = new GetBlockRequest();
  getBlockRequest.setHash(hash);

  const response = await client.getBlock(
    getBlockRequest,
    {},
    options,
  );
  const blockBinaryArray = response.getBlock();

  return Buffer.from(blockBinaryArray);
}

Available methods :

  • getStatus
  • getBlock
  • broadcastTransaction
  • getTransaction
  • getEstimatedTransactionFee
  • subscribeToBlockHeadersWithChainLocks
  • subscribeToTransactionsWithProofs

For streams, such as subscribeToTransactionsWithProofs and subscribeToBlockHeadersWithChainLocks, a grpc-web stream will be returned. More info on their usage can be read over their repository.

Platform Client

Provide a client to perform platform request. Method's API and usage is similar to CorePromiseClient.

const {
  v0: {
    PlatformPromiseClient,
  },
} = require('@dashevo/dapi-grpc');

const client = new PlatformPromiseClient(url);

Available methods :

  • broadcastStateTransition
  • getIdentity
  • getDataContract
  • getDocuments
  • getIdentitiesByPublicKeyHashes
  • waitForStateTransitionResult
  • getConsensusParams
  • setProtocolVersion

Maintainer

@shumkov

Contributing

Feel free to dive in! Open an issue or submit PRs.

License

MIT © Dash Core Group, Inc.

Building generated clients

From the Platform monorepo, run yarn install, then provision the native client generators once:

python3 packages/dapi-grpc/scripts/setup-codegen.py --install
yarn workspace @dashevo/dapi-grpc build

Installation needs Python 3.12 or newer, CMake and a C++ compiler. It builds checksum-verified sources into your user cache without sudo or Docker. Linux runner images provide the same tools at /opt/client-codegen. Set DAPI_GRPC_TOOLCHAIN to use an explicitly provisioned installation; a missing or mismatched installation fails rather than silently selecting a different protoc.

codegen.json pins the recipe and native generator versions. The client compiler is deliberately separate from the Rust build's protoc 32.0: the existing client output uses protobuf 3.18.1, gRPC 1.46.3, gRPC Java 1.42.1 and the Yarn-locked ts-protoc-gen 0.15.0. Update the recipe, Platform lock and runner requirements together, with generated-output compatibility checks. Ordinary builds never install system packages or start containers.

Generation stages all languages before replacing clients/, so a failed plugin preserves the previous output. Java, Objective-C and Python are generated for repository consumers; the NPM archive continues to exclude them and ships the Node and web clients. Run the generation regressions after installing the tools:

yarn workspace @dashevo/dapi-grpc exec python3 -m unittest discover -s tests/codegen -v

版本与发布记录

@dashevo/dapi-grpc 共发布 486 个版本,首次发布于 2019/04/18;过去 12 个月发布了 72 个版本。

版本发布日期距今
5.0.3latest2026/11/047 天前
5.0.22026/11/029 天前
5.0.12026/10/2714 天前
5.0.02026/10/2715 天前
5.0.0-rc.82026/10/2319 天前
5.0.0-rc.72026/10/2220 天前

其他发布通道:dev → 0.12.0-dev.10,0.13-dev → 0.13.0-dev.4,0.14-dev → 0.14.0-dev.1,0.15-dev → 0.15.0-dev.4,0.16-dev → 0.16.0-dev.3,0.17-dev → 0.17.0-dev.1。

关于 @dashevo/dapi-grpc 的常见问题

@dashevo/dapi-grpc 是什么?

DAPI GRPC definition file and generated clients

如何安装 @dashevo/dapi-grpc?

在项目目录运行 npm install @dashevo/dapi-grpc,或使用 pnpm add / yarn add / bun add。

@dashevo/dapi-grpc 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/dashevo__dapi-grpc 是否存在。

@dashevo/dapi-grpc 支持 ESM 还是 CommonJS?

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

@dashevo/dapi-grpc 可以商用吗?

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

@dashevo/dapi-grpc 的下载量有多少?

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

@dashevo/dapi-grpc 还在维护吗?

最新版本 5.0.3 发布于 2026/11/04(7 天前);至今共发布 486 个版本,其中过去 12 个月发布了 72 个;首次发布于 2019/04/18。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。