# bq-wallet

> 用于web钱包集合调用

Latest version **1.0.3** (published 2024-02-01) · ISC license · 0 weekly downloads

## Install

```sh
npm install bq-wallet
pnpm add bq-wallet
yarn add bq-wallet
bun add bq-wallet
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2024-02-01 |
| First published | 2024-01-31 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 4 |
| Unpacked size | 469.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | ywy_user |
| Maintainers | ywy_user |

## Links

- npm: https://www.npmjs.com/package/bq-wallet
- npm.io page: https://npm.io/package/bq-wallet

## Dependencies (4)

- [react](https://npm.io/package/react.md) >=18.0.0
- [react-dom](https://npm.io/package/react-dom.md) >=18.0.0
- [sats-connect](https://npm.io/package/sats-connect.md) ^1.1.2
- [@emotion/react](https://npm.io/package/@emotion/react.md) >=11.0.0

## Recent versions

- 1.0.3 (latest) — 2024-02-01
- 1.0.2 — 2024-01-31
- 1.0.1 — 2024-01-31
- 1.0.0 — 2024-01-31

## README

# web3 钱包聚合库

## 结构

1. 组件 WalletProvider 用于维持钱包数据上下文
2. hooks 用于钱包 api 调用

## WalletProvider 使用

```tsx
import { WalletProvider } from "bq-wallet";
export default function Index() {
  return <WalletProvider>{/* More JSX code here */}</WalletProvider>;
}
```

## hooks

1. useWallet 用于用于调用钱包 api 的。
2. useWalletSelector 用于获取钱包数据

## useWallet 提供的 api

1. connect 用于连接钱包
2. disconnect 用于断开钱包
3. getInfo 用于获取余额
4. sign 用于签名
5. signPsbt 用于签名 psbt
6. sendBitcoin 用于发送 btc
7. getNetwork 用于获取钱包当前网络
8. changeWallet 切换不同钱包或网络

```tsx
import UseWalletComp "./UseWalletComp";
import { WalletProvider } from "bq-wallet";
export default function Index() {
  return <WalletProvider>
    <UseWalletComp />
  </WalletProvider>;
}

// UseWalletComp
import { useWallet } from "bq-wallet";
export default function UseWalletComp() {
    const {connect, disconnect, getInfo, sign, ... } = useWallet()
}
```

## useWalletSelector 提供的数据

```ts
// 输出的ts类型
{
  name: WalletName | null; // 钱包名称
  network: Network; // 当前网络
  publicKey: string; // 公钥
  accounts: string[]; // 账户
  address: string; // 钱包地址
  btcAddress: string; // BTC钱包地址
  btcPublicKey: string; // BTC钱包公钥
  balance?: {
    confirmed?: number; // 确认的余额
    total?: number; // 总余额
    unconfirmed?: number; // 未确认的余额
  };
}
```

```tsx
import UseWalletComp "./UseWalletComp";
import { WalletProvider } from "bq-wallet";
export default function Index() {
  return <WalletProvider>
    <UseWalletComp />
  </WalletProvider>;
}

// UseWalletComp
import { useWalletSelector } from "bq-wallet";
export default function UseWalletComp() {
    const walletInfo = useWalletSelector()
}
```

## Api 部分

1. stringFormatTransition 用于 hex 与 base64 的转换
2. getBase64Str 获取 base64 字符串
3. getHexStr 获取 hex 字符串
4. detectEncoding 判断字符串类型
5. btcToSatoshis 用于 btc 转成 satoshis
6. satoshisToBtc 用于 btc 转成 satoshis

---
_Source: https://npm.io/package/bq-wallet · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
