Class BaseWalletAbstract
Implements
- Wallet
Hierarchy
- BaseWallet (View Summary)
Index
Constructors
Properties
Accessors
Methods
Constructors
constructor
Parameters
- provider: IProvider
Returns BaseWallet
Properties
Protected_address
Protected_connected
Protected_events
Protected_provider
Protected_publicKey
Accessors
address
- get address(): string
Wallet address (bech32 format)
Returns string
provider
Provider instance for blockchain queries
Returns IProvider
publicKey
- get publicKey(): string
Public key (hex format)
Returns string
Methods
broadcastTransaction
Broadcast a single signed transaction to the network Default implementation uses the provider's sendRawTransaction method Can be overridden by child classes for custom behavior (e.g., extension broadcasting)
Parameters
- tx: Transaction
Returns Promise<TransactionHash>
broadcastTransactions
Broadcast multiple signed transactions to the network in a single batch Default implementation uses the provider's sendRawTransactions method Can be overridden by child classes for custom behavior (e.g., extension broadcasting)
Parameters
- txs: Transaction[]
Returns Promise<TransactionHash[]>
Abstractconnect
Connect to the wallet
Returns Promise<void>
Abstractdisconnect
Disconnect from the wallet
Parameters
OptionalclearPrivateKey: boolean
Returns Promise<void>
Protectedemit
Parameters
- event: WalletEvent
Optionaldata: unknown
Returns void
getBalance
Get wallet balance
Returns Promise<bigint>
Balance in smallest units (KLV has 6 decimals)
getNonce
Get current nonce for the wallet Used for transaction ordering
Returns Promise<number>
Current nonce value
isConnected
Check if wallet is connected
Returns boolean
true if connected, false otherwise
off
Unregister an event handler
Parameters
- event: WalletEvent
Event name
- handler: WalletEventHandler
Event handler function to remove
Returns void
- event: WalletEvent
on
Register an event handler
Parameters
- event: WalletEvent
Event name ('connect', 'disconnect', 'accountChanged')
- handler: WalletEventHandler
Event handler function
Returns void
- event: WalletEvent
removeAllListeners
Remove all event listeners for a specific event or all events
Parameters
Optionalevent: WalletEventOptional event name. If not provided, removes all listeners for all events
Returns void
sendTransaction
Send a transaction with any contract type Builds, signs, and broadcasts the transaction Can be overridden by child classes (e.g., BrowserWallet uses extension)
Parameters
- contract: ContractRequestData
Returns Promise<TransactionSubmitResult>
AbstractsignMessage
Sign a message with the wallet's private key
Parameters
- message: string | Uint8Array<ArrayBufferLike>
Returns Promise<Signature>
AbstractsignTransaction
Sign a transaction with the wallet's private key
Parameters
- unsignedTx: Transaction
Returns Promise<Transaction>
transfer
Transfer tokens to another address Convenience method that uses sendTransaction internally
Parameters
- params: TransferRequest
Returns Promise<TransactionSubmitResult>
verifyMessage
- verifyMessage(
message: string | Uint8Array<ArrayBufferLike>,
signature: string | Signature,
): Promise<boolean>Verify a message signature
Parameters
- message: string | Uint8Array<ArrayBufferLike>
The message that was signed (string or bytes)
- signature: string | Signature
The signature to verify (Signature object, hex string, or base64 string)
Returns Promise<boolean>
true if signature is valid, false otherwise
Example
const message = "Hello, Klever!"
const signature = await wallet.signMessage(message)
// Verify with Signature object
const isValid = await wallet.verifyMessage(message, signature)
// Or verify with hex string
const isValidHex = await wallet.verifyMessage(message, signature.toHex())
// Or verify with base64 string
const isValidBase64 = await wallet.verifyMessage(message, signature.toBase64())
console.log('Signature valid:', isValid) - message: string | Uint8Array<ArrayBufferLike>
Abstract base wallet implementation providing common functionality
BaseWallet implements the core wallet interface and provides shared functionality for all wallet types. It handles:
Design Pattern: This class follows the Template Method pattern, where concrete implementations (NodeWallet, BrowserWallet) provide specific implementations for:
Common Functionality: All wallets inherit these capabilities:
Do Not Instantiate Directly: This is an abstract class. Use concrete implementations:
Example