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

# Events

> EIP-1193 events the SDK provider emits.

The SDK provider extends an event emitter. Subscribe with `provider.on(event, handler)` and unsubscribe with `provider.removeListener` (or its alias `provider.off`).

## connect

```ts theme={null}
provider.on('connect', ({ chainId }: { chainId: string }) => {
  // chainId is hex (e.g. "0x74c" for Soneium Mainnet)
})
```

Fired when the provider transitions to a connected state. With wagmi, `useAccount()` exposes the same signal through `status`.

## disconnect

```ts theme={null}
provider.on('disconnect', (error: ProviderRpcError) => {
  // Provider lost connection (network drop, popup closed, user disconnected)
})
```

## accountsChanged

```ts theme={null}
provider.on('accountsChanged', (accounts: string[]) => {
  if (accounts.length === 0) {
    // Disconnected
  } else {
    // Connected as accounts[0]
  }
})
```

Fired when the connected account changes, including when the user disconnects (empty array) or switches accounts in the popup.

## chainChanged

```ts theme={null}
provider.on('chainChanged', (chainId: string) => {
  // chainId is hex
})
```

Fired after a successful `wallet_switchEthereumChain` or after the user changes the active chain in the popup.

## Cleanup

Always remove listeners when your component or scope unmounts:

```ts theme={null}
const onAccountsChanged = (accounts: string[]) => { /* ... */ }
provider.on('accountsChanged', onAccountsChanged)

// Later: both forms work; removeListener is the primary SDK method
provider.removeListener('accountsChanged', onAccountsChanged)
// provider.off('accountsChanged', onAccountsChanged)  // alias for removeListener
```

If you use wagmi, the connector handles event subscription internally. Just consume `useAccount()`, `useChainId()`, and friends.
