@wallet-abstractor/shared
v0.1.2
Published
Shared types, errors, and utilities for wallet-abstractor
Readme
@wallet-abstractor/shared
Shared types, errors, and utilities for Wallet Abstractor
This package contains shared types, error handling, and utility functions used across all Wallet Abstractor packages.
Installation
npm install @wallet-abstractor/sharedWhat This Package Provides
- Types - Core TypeScript types (
Account,NetworkInfo,BalanceInfo, etc.) - Errors - Standardized error handling (
AbstractorError,ErrorCode) - Utils - Helper functions for address validation, balance formatting, etc.
Usage
This package is typically used as a dependency by other @wallet-abstractor packages. You usually don't need to install it directly.
// Types are re-exported from core
import { Account, BalanceInfo, NetworkInfo } from '@wallet-abstractor/core';
// Or use directly
import { AbstractorError, ErrorCode } from '@wallet-abstractor/shared';Types
Account
interface Account {
address: string;
publicKey?: string;
}BalanceInfo
interface BalanceInfo {
value: bigint;
formatted: string;
symbol: string;
decimals: number;
}NetworkInfo
interface NetworkInfo {
chainId: string | number;
name: string;
nativeCurrency: {
name: string;
symbol: string;
decimals: number;
};
rpcUrls: string[];
}Error Handling
import { AbstractorError, ErrorCode } from '@wallet-abstractor/shared';
try {
// Some wallet operation
} catch (error) {
if (error instanceof AbstractorError) {
console.log(error.code); // ErrorCode.USER_REJECTED, etc.
console.log(error.message);
}
}Error Codes
USER_REJECTED- User rejected the requestPROVIDER_NOT_FOUND- No wallet installedINSUFFICIENT_FUNDS- Not enough balanceNETWORK_ERROR- Network connection issueTRANSACTION_FAILED- Transaction failedTIMEOUT- Request timed out
Utilities
import {
isValidEthereumAddress,
isValidSolanaAddress,
formatBalance,
detectAddressType
} from '@wallet-abstractor/shared';
// Validate addresses
const isEth = isValidEthereumAddress('0x742d35Cc6634C0532925a3b8D4e6D3b6e8d3e8B6');
const isSol = isValidSolanaAddress('HN7cABqLq46Es1jh92dQQisAq662SmxELLLsHHe4YWrH');
// Format balance
const formatted = formatBalance(1000000000000000000n, 18); // "1"
// Detect address type
const type = detectAddressType('0x742d35Cc6634C0532925a3b8D4e6D3b6e8d3e8B6'); // "evm"Related Packages
- @wallet-abstractor/core - Core abstraction layer
- @wallet-abstractor/evm - EVM chain adapter
- @wallet-abstractor/solana - Solana adapter
License
MIT