@layerzerolabs/ui-wallet
TypeScript icon, indicating that this package has built-in type declarations

0.1.10 • Public • Published

LayerZero

@layerzerolabs/ui-wallet

NPM Version Downloads Snyk Vulnerabilities for npm package version NPM License

Installation

yarn add @layerzerolabs/ui-wallet

pnpm add @layerzerolabs/ui-wallet

npm install @layerzerolabs/ui-wallet

Usage

This package's primary exports are the abstract class AbstractWallet and helper function assertWallet.

AbstractWallet

The abstract class AbstractWallet implements the Wallet interface.

interface Wallet<Signer> {
  isAvailable: boolean;
  isConnected: boolean;
  isConnecting: boolean;
  isSwitchingChain: boolean;
  // eg MetaMask
  type: string;
  address?: string;
  publicKey?: string;
  chainKey?: string | ChainKey;
  readonly chainType: ChainType;
  // native chain id eg: evm chain id
  nativeChainId?: number | string;
  signer?: Signer;
  connect(): Promise<void>;
  disconnect(): Promise<void>;
  autoConnect(): Promise<void>;
  switchChain(endpointId: number): Promise<void>;
  switchChain(chainKey: string): Promise<void>;
  getChainKey(): Promise<ChainKey | string | undefined>;
  getNativeChainId(): Promise<number>;
  getAddress(): Promise<string>;
}

This interface is used throughout our LayerZero application ecosystem to abstract the wallet specific implementation details from application code. See @layerzerolabs/ui-wallet-evm, @layerzerolabs/ui-wallet-aptos, and @layerzerolabs/ui-wallet-solana for already implemented wallet abstractions or for examples on how to add your own.

assertWallet

This helper function is provided to help verify that a connected wallet has matching configuration at a given time. An example might be checking that the wallet still has the same chain and address just before executing a transaction.

const wallet = walletStore.evm;

await assertWallet(wallet, {chainKey: 'ethereum', address: input.srcAddress});
// or
await assertWallet(wallet, {chainId: input.srcChainId, address: input.srcAddress});

Readme

Keywords

none

Package Sidebar

Install

npm i @layerzerolabs/ui-wallet

Weekly Downloads

20

Version

0.1.10

License

BUSL-1.1

Unpacked Size

18.1 kB

Total Files

7

Last publish

Collaborators

  • layerzero-bot