Skip to main content
SparkWallet extends EventEmitter, so it inherits the following methods for handling events.

Available Events

EventCallback SignatureDescription
"transfer:claimed"(transferId: string, updatedBalance: bigint) => voidEmitted when an incoming transfer is claimed. Does NOT fire for outgoing Lightning payments.
"deposit:confirmed"(depositId: string, updatedBalance: bigint) => voidEmitted when a pending L1 deposit becomes spendable (after 3 confirmations). Only fires if you claimed before confirmation.
"stream:connected"() => voidEmitted when the event stream connects
"stream:disconnected"(reason: string) => voidEmitted when the stream disconnects after max retries
"stream:reconnecting"(attempt: number, maxAttempts: number, delayMs: number, error: string) => voidEmitted when attempting to reconnect
The updatedBalance parameter is a bigint representing the wallet’s new total balance in satoshis after the event.
Events are only emitted for incoming funds (transfers received, deposits confirmed). For outgoing operations (Lightning sends, withdrawals), poll the status using getLightningSendRequest() or getCoopExitRequest().



on(event: string, listener: Function)

Adds a listener for the specified event.
on(event: keyof SparkWalletEvents, listener: Function): this

Parameters

event
string
required
The event name to listen for
listener
Function
required
The callback function to execute when the event is emitted

Returns

this
this
required
The SparkWallet instance for chaining

Example

wallet.on("transfer:claimed", (transferId, updatedBalance) => {
  console.log(`Transfer ${transferId} claimed. New balance: ${updatedBalance}`);
});



once(event: string, listener: Function)

Adds a one-time listener for the specified event.
once(event: keyof SparkWalletEvents, listener: Function): this

Parameters

event
string
required
The event name to listen for
listener
Function
required
The callback function to execute when the event is emitted

Returns

this
this
required
The SparkWallet instance for chaining

Example

wallet.once("deposit:confirmed", (depositId, updatedBalance) => {
  console.log(`Deposit ${depositId} confirmed! New balance: ${updatedBalance}`);
});



off(event: string, listener: Function)

Removes the specified listener from the specified event.
off(event: keyof SparkWalletEvents, listener: Function): this

Parameters

event
string
required
The event name
listener
Function
required
The callback function to remove

Returns

this
this
required
The SparkWallet instance for chaining

Example

const listener = (transferId) => console.log(`Transfer: ${transferId}`);
wallet.on("transfer:claimed", listener);

// Later, remove the listener
wallet.off("transfer:claimed", listener);