npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@web3jskit/wallethelper

v0.4.6

Published

wallethelper

Readme

WalletHelper

WalletHelper 是一个多链钱包连接的底层工具库,为 DApp 开发提供统一的钱包接口和状态管理。它是 WalletKit 的核心依赖库。

WalletHelper is a multi-chain wallet connection utility library that provides unified wallet interfaces and state management for DApp development. It is the core dependency of WalletKit.

特性 Features

  • 多链支持 / Multi-chain support (EVM, PUT, SOL, Tron, BTC)
  • 统一的钱包接口 / Unified wallet interface
  • 钱包自动检测 / Automatic wallet detection
  • 状态管理 / State management
  • TypeScript 支持 / TypeScript support
  • 轻量级设计 / Lightweight design

安装 Installation

# npm
npm install @web3jskit/wallethelper

# yarn
yarn add @web3jskit/wallethelper

# pnpm
pnpm add @web3jskit/wallethelper

使用方法 Usage

1. 创建钱包连接器 Create Wallet Connector

import { createConnector, ChainType } from '@web3jskit/wallethelper';

// 创建特定链的钱包连接器
const connectors = await createConnector(ChainType.EVM);

2. 检测钱包环境 Detect Wallet Environment

import { detectWalletBrowser } from '@web3jskit/wallethelper';

const walletInfo = detectWalletBrowser();
if (walletInfo) {
	console.log('Detected wallet:', walletInfo.type);
	console.log('Provider:', walletInfo.provider);
}

3. 状态管理 State Management

import { walletHelperStore } from '@web3jskit/wallethelper';

// 获取状态
const state = walletHelperStore.getState();

// 订阅状态变化
const unsubscribe = walletHelperStore.subscribe(state => {
	console.log('Wallet state changed:', state);
});

// 更新状态
walletHelperStore.setState({
	connectStatus: ConnectStatus.Connected,
	walletAddress: '0x...'
});

4. 交易操作 Transaction Operations

// 获取当前连接器
const connector = walletHelperStore.getState().currentConnector;

// 签名消息
const signature = await connector.signMessage('Hello Web3');

// 发送交易
const txHash = await connector.sendTransaction({
  to: '0x...',
  value: '0x...'
});

// 合约调用
const result = await connector.writeContract({
  address: '0x...',
  abi: [...],
  functionName: 'transfer',
  args: [...]
});

API 参考 API Reference

Connector 接口 Connector Interface

interface Connector {
	// 基本属性 Basic properties
	readonly provider: any;
	readonly name: string;
	readonly icon: string;
	readonly deepLink?: string;
	readonly walletAddress: string;
	readonly chainType?: ChainType;
	readonly connectorType?: ConnectorType;

	// 核心方法 Core methods
	connect(): Promise<string>;
	disconnect(): Promise<void>;
	reconnection(): Promise<void>;

	// 交易方法 Transaction methods
	signMessage?(message: string): Promise<string>;
	signTransaction?(transaction: any): Promise<string>;
	sendTransaction?(transaction: any): Promise<string>;
	writeContract?(contract: any): Promise<string>;
	readContract?(contract: any): Promise<string>;

	// 其他方法 Other methods
	getProvider(): Promise<any>;
	getWalletAddress(): string;
	switchNetwork?(chainId: number): Promise<string>;
}

Store 状态定义 Store State Definition

interface WalletHelperState {
	// 连接状态 Connection status
	connectStatus: ConnectStatus;
	currentConnector: Connector | null;
	walletAddress: string;

	// 链相关 Chain related
	currentChainType: ChainType;
	currentNetworkId: number;
	currentNetwork: NetworkInfo | null;

	// Provider
	provider: any;

	// 方法 Methods
	getProvider(): Promise<any>;
	disconnect(): Promise<void>;
	signMessage(message: string): Promise<any>;
	sendTransaction(transaction: any): Promise<any>;
	// ... 更多方法 more methods
}

支持的钱包 Supported Wallets

  • MetaMask (EVM)
  • Phantom (SOL, BTC)
  • TronLink (TRON)
  • Gel Wallet (EVM, PUT, SOL)
  • OKX Wallet (EVM)
  • Trust Wallet (EVM)
  • TokenPocket (EVM)
  • Bitget Wallet (EVM)
  • Coinbase Wallet (EVM)

错误处理 Error Handling

WalletHelper 提供了标准的错误类型和处理机制:

WalletHelper provides standard error types and handling mechanisms:

// RPC 请求错误 RPC request error
class RpcRequestError extends BaseError {
	code: number;
	// ...
}

// 连接错误 Connection error
class ConnectionError extends BaseError {
	// ...
}

// 超时错误 Timeout error
class TimeoutError extends BaseError {
	// ...
}

贡献指南 Contributing

欢迎提交 Issues 和功能请求!贡献步骤:

We welcome issues and feature requests! Steps to contribute:

  1. Fork 本仓库 Fork this repository
  2. 创建功能分支 Create feature branch:
git checkout -b feature/my-feature
  1. 提交更改 Commit changes:
git commit -m "Add some feature"
  1. 推送分支 Push branch:
git push origin feature/my-feature
  1. 提交 Pull Request Submit Pull Request

许可证 License

MIT License

联系我们 Contact Us

如有问题或建议,请通过以下方式联系我们:

For questions or suggestions, please contact us: