> ## Documentation Index
> Fetch the complete documentation index at: https://docs.spark.money/llms.txt
> Use this file to discover all available pages before exploring further.

# EventEmitter

> Listen for wallet events like transfers and deposits.

`SparkWallet` extends `EventEmitter`, so it inherits the following methods for handling events.

## Available Events

| Event                   | Callback Signature                                                               | Description                                                                                             |
| ----------------------- | -------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- |
| `"transfer:claimed"`    | `(transferId: string, updatedBalance: bigint) => void`                           | Emitted when an **incoming** transfer is claimed. Does NOT fire for outgoing Lightning payments.        |
| `"deposit:confirmed"`   | `(depositId: string, updatedBalance: bigint) => void`                            | Emitted when a claimed L1 deposit is marked available (after the required confirmations, 3 by default). |
| `"stream:connected"`    | `() => void`                                                                     | Emitted when the event stream connects                                                                  |
| `"stream:disconnected"` | `(reason: string) => void`                                                       | Emitted when the stream disconnects after max retries                                                   |
| `"stream:reconnecting"` | `(attempt: number, maxAttempts: number, delayMs: number, error: string) => void` | Emitted when attempting to reconnect                                                                    |

<Info>
  The `updatedBalance` parameter is a `bigint` representing the wallet's new total balance in satoshis after the event.
</Info>

<Warning>
  Events are only emitted for **incoming** funds (transfers received, deposits confirmed). For outgoing operations (Lightning sends, withdrawals), poll the status using `getLightningSendRequest()` or `getCoopExitRequest()`.
</Warning>

<br />

***

<br />

## on(event: string, listener: Function)

Adds a listener for the specified event.

```typescript theme={null}
on(event: keyof SparkWalletEvents, listener: Function): this
```

## Parameters

<ResponseField name="event" type="string" required>
  The event name to listen for
</ResponseField>

<ResponseField name="listener" type="Function" required>
  The callback function to execute when the event is emitted
</ResponseField>

## Returns

<ResponseField name="this" type="this" required>
  The SparkWallet instance for chaining
</ResponseField>

## Example

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

<br />

***

<br />

## once(event: string, listener: Function)

Adds a one-time listener for the specified event.

```typescript theme={null}
once(event: keyof SparkWalletEvents, listener: Function): this
```

## Parameters

<ResponseField name="event" type="string" required>
  The event name to listen for
</ResponseField>

<ResponseField name="listener" type="Function" required>
  The callback function to execute when the event is emitted
</ResponseField>

## Returns

<ResponseField name="this" type="this" required>
  The SparkWallet instance for chaining
</ResponseField>

## Example

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

<br />

***

<br />

## off(event: string, listener: Function)

Removes the specified listener from the specified event.

```typescript theme={null}
off(event: keyof SparkWalletEvents, listener: Function): this
```

## Parameters

<ResponseField name="event" type="string" required>
  The event name
</ResponseField>

<ResponseField name="listener" type="Function" required>
  The callback function to remove
</ResponseField>

## Returns

<ResponseField name="this" type="this" required>
  The SparkWallet instance for chaining
</ResponseField>

## Example

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

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