@fordefi/web3-provider

中文文档
0.3.3发布于 2026/07/29TypeScriptESM + CJS构建来源已验证近 30 天下载 2万

Web3 兼容 EIP-1193 的提供者和签名者

中文使用文档
文档目录11 节
  1. 概览
  2. 安装
  3. 使用量
  4. 创建提供者
  5. 连接
  6. 提交 JSON RPC 请求
  7. API 参考
  8. 配置
  9. 活动
  10. 实例
  11. 关于福德菲

Fordefi Logo

Fordefi Web3 提供者

NPM Version

概览

此提供者类工具 EIP-1193 (英语) 由电源驱动 福尔迪·API。 。 。 .

它提供了一个 请求( ) 函数以执行 JSON RPC 方法并释放相关的 事件。 。 。 .

安装

使用线条 :

yarn add @fordefi/web3-provider

使用 npm :

npm add --save @fordefi/web3-provider

使用量

创建提供者

每个实例管理一个特定链条上的单一地址(断层).

跟着 API 参考 以下为可用配置 选项.

import {
  FordefiWeb3Provider,
  FordefiProviderConfig,
} from "@fordefi/web3-provider";

const config: FordefiProviderConfig = {
  chainId: 11155111,
  address: "0x1234567890123456789012345678901234567890",
  apiUserToken: process.env.FORDEFI_API_USER_TOKEN,
  apiPayloadSignKey: process.env.FORDEFI_API_PAYLOAD_SIGNING_KEY,
};

const provider = new FordefiWeb3Provider(config);

连接

光谱要求提供者是 已连接 提交 请求.

当新实例出现时, 此提供者会自动连接到 Fordefi 已建造并发射a connect 事件一旦与 Fordefi 通信 平台已经建立.

订阅此活动:

// callback to act upon a `connect` event
const onConnect = ({ chainId }: ProviderConnectInfo) => {
  console.log(`Connected to chain ${chainId}`);
};

// option 1: subscribe using a callback
provider.on("connect", onConnect);

// option 2: wait for a promise to be resolved
const result = await provider.waitForEmittedEvent("connect");
onConnect(result);
// or
provider.waitForEmittedEvent("connect").then(onConnect);

详情见 活动。 。 。 .

提交 JSON RPC 请求

这个 request({ method, params }) 方法将 JSON RPC 请求发送给 供养. 它回报了一个承诺 解决了请求的结果.

所有与创造和(或)签署交易有关的方法一旦解决 交易已成功签名 API 签名器。 。 。 .

样本代码显示如何发送交易 :

const txHash = await provider.request({
  method: "eth_sendTransaction",
  params: [
    {
      from: "0x1234567890123456789012345678901234567890",
      to: "0x1234567890123456789012345678901234567890",
      value: 1_500_000_000_000n,
    },
  ],
});

console.log(`Transaction hash: ${txHash}`);

API 参考

API 参考文献全文见: 福德维网络3 提供者文件站点。 。 。 .

配置

详情见 失败者配置 接口.

interface FordefiProviderConfig {
  /**
   * Chain ID as a number or a named chain.
   *
   * For example, assuming Ethereum Sepolia chain:
   * - Numeric value: 11155111.
   * - Named chain: 'evm_ethereum_sepolia'.
   */
  chainId: number | string;

  /**
   * EVM address.
   *
   * For example: '0x1234567890123456789012345678901234567890'.
   */
  address: Address;

  /**
   * Fordefi API user token (base64 encoded) issued via the Fordefi Web Console.
   * See: https://app.fordefi.com/user-management
   *
   * For example: 'eyJWthEAdEr.eyJwTPaYLoad.SiGNAtUrEBase64=='
   */
  apiUserToken: string;

  /**
   * Private key in PEM format used to sign the body of requests sent to the Fordefi API.
   * This is the content the private `.pem` file.
   * See: https://docs.fordefi.com/reference/pair-an-api-client-with-the-api-signer
   *
   * Example of a private ECDSA `.pem` file:
   * -----BEGIN EC PRIVATE KEY-----
   * PrivateKeyBase64==
   * -----END EC PRIVATE KEY-----
   */
  apiPayloadSignKey: string;

  /**
   * Fallback JSON-RPC HTTP node url.
   * Methods not implemented by this provider will pass through and be handled by this node.
   *
   * For example: 'https://rpc.sepolia.org'.
   */
  rpcUrl?: string;

  /**
   * Fordefi API base url (used for development), defaults to production API url.
   *
   * For example: 'https://api.fordefi.com'.
   */
  apiBaseUrl?: string;

  /**
   * Total duration in ms of polling for transaction lifecycle status changed after a transaction was submitted. By default, it would stop after 24 hours.
   */
  timeoutDurationMs?: number;

  /**
   * Duration in ms between checks for transaction lifecycle status updates after a transaction was submitted. The minimum value is 500, and by default it's 5000.
   */
  pollingIntervalMs?: number;
}

活动

使用 on(eventName, callback) 方法 :

// emitted once during the connection process with the `address` you provided.
provider.on("accountsChanged", (accounts: Address[]) => {
  /* handle event here */
});

// emitted once during connection process with the `chainId` you provided
provider.on("chainChanged", (chainId: string) => {
  /* handle event here */
});

// provider becomes connected
provider.on("connect", (connectInfo: ProviderConnectInfo) => {
  /* handle event here */
});

// provider becomes connected
provider.on("disconnect", (error: ProviderRpcError) => {
  /* handle event here */
});

使用 removeListener(eventName, callback) 方法, ,并提供事件名称和先前用于 订阅此事件 。 例如:

provider.removeListener("connect", onConnect);

混合 waitForEmittedEvent(eventName) 帮助方法返回 a 你应许,那件事情将随一件事情而判决 载荷。 例如:

provider
  .waitForEmittedEvent("connect")
  .then((connectInfo: ProviderConnectInfo) => {
    console.log(`Connected to chain ${connectInfo.chainId}`);
  });

实例

检查使用示例 e2e 测试。 。 。 .

关于福德菲

拒绝 是一个区块链安全公司,提供 机构级MPC(多党计算)非拘禁钱包 专为分权金融而建.

Fordefi侧重于加强交易的安全和效率 通过创新使用MPC技术进行关键管理和 交易签名,并提供一个安全和方便用户的界面 通过各种客户:

  1. Fordefi 浏览器扩展 用于与 dApps 交互.
  2. Fordefi 网络控制台 安全履行 行政业务,例如制定交易政策规则和 用户管理,这需要获得管理人员法定人数的批准.
  3. 福尔迪·API 用于开发者 与福德菲基础设施互动.

更多关于福德菲的文章 站点 财务报告和审定财务报表 文档。 。 。 .

版本与发布记录

@fordefi/web3-provider 共发布 29 个版本,首次发布于 2024/04/16;过去 12 个月发布了 3 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.3.3latest2026/07/293 个月前
0.3.22026/04/206 个月前
0.3.12026/04/067 个月前
0.3.02025/06/171.4 年前
0.3.0-dev.7957b77abeta2025/06/111.4 年前
0.2.82025/05/201.5 年前

关于 @fordefi/web3-provider 的常见问题

@fordefi/web3-provider 是什么?

Web3 兼容 EIP-1193 的提供者和签名者

如何安装 @fordefi/web3-provider?

在项目目录运行 npm install @fordefi/web3-provider,或使用 pnpm add / yarn add / bun add。

@fordefi/web3-provider 支持 TypeScript 吗?

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

@fordefi/web3-provider 支持 ESM 还是 CommonJS?

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

@fordefi/web3-provider 需要什么版本的 Node.js?

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

@fordefi/web3-provider 可以商用吗?

@fordefi/web3-provider 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@fordefi/web3-provider 的下载量有多少?

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

@fordefi/web3-provider 还在维护吗?

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