@gnosis.pm/safe-react-gateway-sdk

中文文档
3.5.2发布于 2022/12/02MITTypeScriptCommonJS近 30 天下载 3.8万

npm

此软件包已被标记为弃用

Migrated to @safe-global/safe-gateway-typescript-sdk

原始使用文档
文档目录6 节
  1. Usage policy
  2. Using the SDK
  3. Adding an endpoint
  4. Eslint & prettier
  5. Tests
  6. Gateway API docs

Safe Gateway TypeScript SDK

npm

A TypeScript SDK for the Safe Client Gateway

📖 API reference

Usage policy

NB: Safe Client Gateway isn't meant for public use. Please do not use this SDK if you're building, e.g., a Safe App.

Using the SDK

Install:

yarn add @gnosis.pm/safe-react-gateway-sdk

Import:

import { getChainsConfig, type ChainListResponse } from '@gnosis.pm/safe-react-gateway-sdk'

Use:

const chains = await getChainsConfig()

The SDK needs no initialization unless you want to override the base URL. You can set an alternative base URL like so:

import { setBaseUrl } from '@gnosis.pm/safe-react-gateway-sdk'

// Switch the SDK to dev mode
setBaseUrl('https://safe-client.staging.5afe.dev')

The full SDK reference can be found here.

Adding an endpoint

Endpoint types are defined in src/types/gateway.ts.

Each endpoint consists of:

  • a function defined in src/index.ts (e.g. getBalances)
  • a path definition (e.g. '/chains/{chainId}/safes/{address}/balances/{currency}/')
  • operation definition (e.g. safes_balances_list)
  • response definition

To add a new endpoint, follow the pattern set by the existing endpoints.

Eslint & prettier

This command will run before every commit:

yarn eslint:fix

Tests

To run the unit and e2e tests locally:

yarn test

N.B.: the e2e tests make actual API calls on staging.

Gateway API docs

The TypeScript types in this SDK are based on Rust types from the Gateway API.

版本与发布记录

@gnosis.pm/safe-react-gateway-sdk 共发布 62 个版本,首次发布于 2021/07/27;过去 12 个月发布了 0 个版本。

版本发布日期距今
3.5.2latest2022/12/023 年前
3.5.12022/11/293 年前
3.5.02022/11/243 年前
3.4.62022/11/233 年前
3.4.52022/11/024 年前
3.4.42022/11/024 年前

关于 @gnosis.pm/safe-react-gateway-sdk 的常见问题

如何安装 @gnosis.pm/safe-react-gateway-sdk?

在项目目录运行 npm install @gnosis.pm/safe-react-gateway-sdk,或使用 pnpm add / yarn add / bun add。

@gnosis.pm/safe-react-gateway-sdk 支持 TypeScript 吗?

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

@gnosis.pm/safe-react-gateway-sdk 支持 ESM 还是 CommonJS?

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

@gnosis.pm/safe-react-gateway-sdk 可以商用吗?

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

@gnosis.pm/safe-react-gateway-sdk 的下载量有多少?

根据 npm 官方下载统计,@gnosis.pm/safe-react-gateway-sdk 在 2026/10/17 – 2026/11/15 这 30 天内被下载 37,780 次,日均约 1,259 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@gnosis.pm/safe-react-gateway-sdk 还在维护吗?

最新版本 3.5.2 发布于 2022/12/02(3 年前);至今共发布 62 个版本,其中过去 12 个月发布了 0 个;首次发布于 2021/07/27。作者已将其标记为弃用,新项目建议寻找替代方案。