# @blend-capital/blend-sdk 中文文档

规范地址：https://npmcn.com/package/%40blend-capital/blend-sdk/

版本：4\.0\.0
npm 元数据更新时间：2026-10-26T22:03:19.034Z
中文译文更新时间：2026-11-08T06:40:40.528Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40blend-capital/blend-sdk
原文对照：https://npmcn.com/package/%40blend-capital/blend-sdk/?lang=original
项目主页：https://github.com/blend-capital/blend-sdk-js#readme
源码仓库：https://github.com/blend-capital/blend-sdk-js

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：1 MB，210 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- Node.js 要求：\>=22\.12\.0
- 运行依赖：2 个
- 首次发布：2023-10-24T19:05:24.759Z
- 最新版本发布：2026-10-26T22:03:18.737Z
- 近 30 天下载量：14318（2026-10-09 至 2026-11-07，npm 官方下载统计）
- 已发布版本数：54（近 12 个月 4 个）

## 中文简介

混合协议的 Javascript SDK

## 安装

```sh
npm install @blend-capital/blend-sdk
```

也可以使用：`pnpm add @blend-capital/blend-sdk`、`yarn add @blend-capital/blend-sdk`、`bun add @blend-capital/blend-sdk`

## README

# 混合sdk -js (英语)

用于Javascript协助与"Blend协议"互动的混合协议SDK.

## 开始

1.  使用 npm 安装 :

```bash
npm install @blend-capital/blend-sdk
```

## 使用量

每个混合议定书合同都输出一个合同类别,用于与合同互动。 一些合同,如"宝库",包括了额外的课程来帮助读取分类账状态.

注:在包件之间有一个通过XDR对象的未决问题。 详细情况见下期: [https://github.com/stellar/js-stellar-base/issues/617 (中文(简体) )](https://github.com/stellar/js-stellar-base/issues/617)

两者 [混合图案](https://github.com/blend-capital/blend-utils) 财务报告和审定财务报表 [搅拌](https://github.com/blend-capital/blend-ui) 数据库广泛使用此SDK作为参考.

### 向现金池提供资产

合同类创建一个操作作为基数64 XDR 字符串,可以和 `@stellar/stellar-sdk` [交易 构建器类](https://stellar.github.io/js-stellar-sdk/TransactionBuilder.html)在与索洛班合同互动时,援引者必须拥有 `SorobanData` 交易的一部分。 这个 `@stellar/stellar-sdk` 通过模拟针对RPC的交易,为做到这一点提供了一种简单的方式。 关于如何向Sterrar网络提交索罗班行动,请参见: [https://developers.stellar.org/docs/building/guides/transactions/invoke-contract-tx-sdk 互联网档案馆的存檔,存档日期2014-12-21](https://developers.stellar.org/docs/build/guides/transactions/invoke-contract-tx-sdk)

```ts
import { PoolContract, RequestType } from '@blend-capital/blend-sdk';
import { xdr } from '@stellar/stellar-sdk';

const asset: Address = // C... the Address of the asset to lend
const user: Address = // G... some Address
const to_lend: bigint = // ... the amount to lend as a bigint fixed point number with the tokens decimals 

const pool_contract = new PoolContract(poolId);
const supply_op = xdr.Operation.fromXdr(
    pool_contract.submit({
        from: user,
        spender: user,
        to: user,
        requests: [
            {
                amount: to_lend,
                request_type: RequestType.SupplyCollateral,
                address: asset,
            },
        ],
    }),
    'base64'
);

// build a transaction with the operation and submit it to the network
```

要提交针对池的其他动作, 您可以修改 `Requests` 阵列,以控制要对集合采取的行动 `from`, (中文(简体) ), `spender`,以及 `to`。 。 。 .

### 为 Pool 和一个用户读取分类账数据

包括了帮助类,以帮助从RPC中高效读取一个集合的分类账数据. 以下代码读取了池子的分类账数据,它是储备的,它的状态是备份.

```ts
import {
  Backstop,
  BackstopPool,
  BackstopPoolEst,
  BackstopPoolUser,
  BackstopPoolUserEst,
  Network,
  Pool,
  PoolEstimate,
  PoolOracle,
  PositionsEstimate,
} from '@blend-capital/blend-sdk';

const network: Network = {
  rpc: // rpc URL,
  passphrase: // Stellar network passphrase,
  // optional, allows you to connect to a local RPC instance
  opts: { allowHttp: true },
};

const backstop_id = // C... the address of the backstop contract
const pool_id = // C... the address of the pool contract
const user_id = // G... the address of a user that has taken a position in the pool

// Load the pool data from the ledger to check things like supported reserves, current interest rates
// and other pool specific information like emissions.
const pool = await Pool.load(network, pool_id);

// If price is needed, load the pool's oracle.
const pool_oracle = await pool.loadOracle();

// Additional estimates aggregate information using oracle prices. For example,
// the PoolEstimate class calculates things like total value supplied and borrowed.
const pool_est = PoolEstimate.build(pool.reserves, pool_oracle);

// The pool also allows you to directly load a user's position and emissions information.
const pool_user = await pool.loadUser(user_id);

// Additional estimates for their positions calculate things like borrow limit, net apr, ect.
const user_est = PositionsEstimate.build(pool, pool_oracle, pool_user.positions);

// Load the backstop data from the ledger to check things like the status of the backstop token and the
// configuration of the backstop
const backstop = await Backstop.load(network, backstop_id);

// Load a pool's backstop data to get information like backstop size, Q4W percentage, and more.
const backstop_pool = await BackstopPool.load(network, backstop_id, pool_id);

// Additional estimates calculate the total number of BLND/USDC tokens the backstop holds.
const backstop_pool_est = BackstopPoolEst.build(backstop.backstopToken, backstop_pool.poolBalance);

// Load a user's position in a pool's backstop
const backstop_pool_user = await BackstopPoolUser.load(network, backstop_id, pool_id, user_id);

// Additional estimates calcualte total number of BLND/USDC tokens the user holds the status
// of any queued withdrawals, and the unclaimed emissions.
const backstop_pool_user_est = BackstopPoolUserEst.build(backstop, backstop_pool, backstop_pool_user);
```

## 常见问题

### @blend-capital/blend-sdk 是什么？

混合协议的 Javascript SDK

### 如何安装 @blend-capital/blend-sdk？

在项目目录运行 npm install @blend-capital/blend-sdk，或使用 pnpm add / yarn add / bun add。

### @blend-capital/blend-sdk 支持 TypeScript 吗？

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

### @blend-capital/blend-sdk 支持 ESM 还是 CommonJS？

同时提供 ES Module 与 CommonJS 入口，import 和 require\(\) 都可以使用，打包工具会自动选择合适的版本。

### @blend-capital/blend-sdk 需要什么版本的 Node\.js？

package\.json 的 engines 字段要求 Node\.js \>=22\.12\.0。版本不符时 npm 默认只给出警告，开启 engine-strict 后会拒绝安装。

### @blend-capital/blend-sdk 可以商用吗？

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

### @blend-capital/blend-sdk 的下载量有多少？

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

### @blend-capital/blend-sdk 还在维护吗？

最新版本 4\.0\.0 发布于 2026/10/27（12 天前）；至今共发布 54 个版本，其中过去 12 个月发布了 4 个；首次发布于 2023/10/25。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

