0.5.8 • Published 6 months ago

mobit-wallet v0.5.8

Weekly downloads
-
License
MIT
Repository
-
Last release
6 months ago

Mobit Wallet

Mobit Wallet 是一个轻量级的 TypeScript 库,用于在各种加密货币钱包中进行比特币交易操作。

特性

  • 支持多种流行的加密货币钱包
  • 提供签署 PSBT 和发送比特币的功能
  • 简单易用的 API
  • 完全用 TypeScript 编写,提供类型安全
  • 专为浏览器环境设计

支持的钱包

  • JoyID
  • UniSat
  • OKX Wallet

安装

使用 npm 安装:

npm install mobit-wallet

使用方法

import { JoyIDWallet, UniSatWallet, OKXWallet } from 'mobit-wallet';
import { DataSource } from '@rgbpp-sdk/btc';

// 创建钱包实例
const joyidWallet = new JoyIDWallet(DataSource.Mempool); // 为 JoyID 指定数据源
const unisatWallet = new UniSatWallet();
const okxWallet = new OKXWallet();

// 签署 PSBT
async function signTransaction(wallet, psbtHex) {
  try {
    const signedPsbtHex = await wallet.signPsbt(psbtHex);
    console.log("Signed PSBT:", signedPsbtHex);
  } catch (error) {
    console.error("Error signing PSBT:", error);
  }
}

// 发送比特币
async function sendBitcoin(wallet, address, amount, feeRate) {
  try {
    const txid = await wallet.sendBitcoin({ address, amount, feeRate });
    console.log("Transaction ID:", txid);
  } catch (error) {
    console.error("Error sending Bitcoin:", error);
  }
}

// 使用示例
signTransaction(joyidWallet, "your_psbt_hex_here");
sendBitcoin(unisatWallet, "recipient_address", 0.001, 1);

注意事项

  • 确保在使用前已安装相应的钱包浏览器扩展。
  • JoyID 钱包需要指定一个 DataSource
  • 在生产环境中使用前,请务必进行充分的测试。
  • 不同钱包可能有不同的特性和限制,请参考各自的文档。
0.5.8

6 months ago

0.5.7

6 months ago

0.5.4

6 months ago

0.4.5

6 months ago

0.5.3

6 months ago

0.5.6

6 months ago

0.5.5

6 months ago

0.5.0

6 months ago

0.5.2

6 months ago

0.5.1

6 months ago

0.4.4

10 months ago

0.4.3

10 months ago

0.4.2

10 months ago

0.4.1

10 months ago

0.4.0

10 months ago

0.3.1

10 months ago

0.3.0

10 months ago

0.2.0

10 months ago

0.1.0

10 months ago