@blockshake/defly-connect

中文文档
1.2.1发布于 2025/01/09ISCTypeScriptES Module近 30 天下载 5.1万

JavaScript SDK for integrating Defly Wallet to web applications.

原始使用文档
文档目录7 节
  1. @blockshake/defly-connect
  2. Quick Start
  3. Options
  4. Methods
  5. Customizing Style
  6. Your app name on Defly Wallet
  7. Contributing

@blockshake/defly-connect

JavaScript SDK for integrating Defly Wallet to web applications. For more detailed information, please check our Defly Manual.

This is a fork of the Pera connect JavaScript SDK, for more details visit Pera connect on GitHub.

Quick Start

Let's start with installing @blockshake/defly-connect

npm install --save @blockshake/defly-connect
// Connect handler
deflyWallet
  .connect()
  .then((newAccounts) => {
    // Setup the disconnect event listener
    deflyWallet.connector?.on("disconnect", handleDisconnectWalletClick);

    setAccountAddress(newAccounts[0]);
  })
  .reject((error) => {
    // You MUST handle the reject because once the user closes the modal, deflyWallet.connect() promise will be rejected.
    // For the async/await syntax you MUST use try/catch
    if (error?.data?.type !== "CONNECT_MODAL_CLOSED") {
      // log the necessary errors
    }
  });

If you don't want the user's account information to be lost by the dApp when the user closes the browser with user’s wallet connected to the dApp, you need to handle the reconnect session status. You can do this in the following way.

// On the every page refresh
deflyWallet.reconnectSession().then((accounts) => {
  // Setup the disconnect event listener
  deflyWallet.connector?.on("disconnect", handleDisconnectWalletClick);

  if (accounts.length) {
    setAccountAddress(accounts[0]);
  }
});

After that you can sign transaction with this way

// Single Transaction
try {
  const signedTxn = await deflyWallet.signTransaction([singleTxnGroups]);
} catch (error) {
  console.log("Couldn't sign Opt-in txns", error);
}

Options

optiondefaultvalue
chainId4160416001, 416002, 416003 , 4160optional
shouldShowSignTxnToasttruebooleanoptional

chainId

Determines which Algorand network your dApp uses.

MainNet: 416001

TestNet: 416002

BetaNet: 416003

All Networks: 4160

shouldShowSignTxnToast

It's enabled by default but in some cases, you may not need the toast message (e.g. you already have signing guidance for users). To disable it, use the shouldShowSignTxnToast option:

Methods

DeflyWalletConnect.connect(): Promise<string[]>

Starts the initial connection flow and returns the array of account addresses.

DeflyWalletConnect.reconnectSession(): Promise<string[]>

Reconnects to the wallet if there is any active connection and returns the array of account addresses.

DeflyWalletConnect.disconnect(): Promise<void | undefined>

Disconnects from the wallet and resets the related storage items.

DeflyWalletConnect.platform: DeflyWalletPlatformType

Returns the platform of the active session. Possible responses: mobile | null

DeflyWalletConnect.isConnected: boolean

Checks if there's any active session regardless of platform. Possible responses: true | false

DeflyWalletConnect.signTransaction(txGroups: SignerTransaction[][], signerAddress?: string): Promise<Uint8Array[]>

Starts the sign process and returns the signed transaction in Uint8Array

Customizing Style

You can override the z-index using the .defly-wallet-connect-modal class so that the modal does not conflict with another component on your application.

.defly-wallet-connect-modal {
  // The default value of z-index is 10. You can lower and raise it as much as you want.
  z-index: 11;
}

Your app name on Defly Wallet

By default, the connect wallet drawer on Defly Wallet gets the app name from document.title.

In some cases, you may want to customize it. You can achieve this by adding a meta tag to your HTML between the head tag.

<meta name="name" content="My dApp" />

Contributing

All contributions are welcomed! To get more information about the details, please read the contribution guide first.

版本与发布记录

@blockshake/defly-connect 共发布 14 个版本,首次发布于 2022/09/30;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.2.1latest2025/01/091.8 年前
1.2.02024/12/311.9 年前
1.1.62023/08/213 年前
1.1.52023/06/243 年前
1.1.42023/06/243 年前
1.1.32023/06/203 年前

关于 @blockshake/defly-connect 的常见问题

@blockshake/defly-connect 是什么?

JavaScript SDK for integrating Defly Wallet to web applications.

如何安装 @blockshake/defly-connect?

在项目目录运行 npm install @blockshake/defly-connect,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:algosdk(^3.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@blockshake/defly-connect 支持 TypeScript 吗?

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

@blockshake/defly-connect 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@blockshake/defly-connect 可以商用吗?

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

@blockshake/defly-connect 的下载量有多少?

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

@blockshake/defly-connect 还在维护吗?

最新版本 1.2.1 发布于 2025/01/09(1.8 年前);至今共发布 14 个版本,其中过去 12 个月发布了 0 个;首次发布于 2022/09/30。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。