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

> ## Agent Instructions
> If you are building a Canton Network application, start from https://docs.canton.network/appdev/quickstart.md. To run only a local network for your own Daml code, without building the QuickStart demo, see https://docs.canton.network/sdks-tools/development-tools/localnet.md.

# dApp API

> The Wallet Gateway's CIP-0103 dApp API, and where it is documented.

The dApp API is the [CIP-0103](https://github.com/canton-foundation/cips/blob/main/cip-0103/cip-0103.md)
JSON-RPC 2.0 API that dApps call to connect to a wallet, list accounts, and prepare and
execute transactions. The Wallet Gateway exposes it, but you almost never call it directly.

* **Base path**: `/api/v0/dapp` (configurable via `server.dappPath`)
* **Protocol**: JSON-RPC 2.0, per CIP-0103
* **Authentication**: JWT bearer token (obtained through a session)

> [!NOTE]
>
> Build dApps with the [dApp SDK](https://docs.canton.network/sdks-tools/sdks/dapp-sdk/overview.md), which implements the
> dApp API and adds a high-level interface, session handling, wallet discovery, and multi-transport
> support. Use the raw API only for lower-level infrastructure. The SDK documentation is the
> reference for methods, events, and error handling.

## Full specification

The complete OpenRPC specification is available at
[openrpc-dapp-api.json](https://github.com/canton-network/wallet/blob/main/api-specs/openrpc-dapp-api.json).

## Real-time events (SSE)

The dApp API supports Server-Sent Events for real-time notifications. Connect to the `/events`
path relative to the dApp API base URL (for example `/api/v0/dapp/events`), authenticating with
the JWT as the `token` query parameter (the `Authorization: Bearer` header is also supported):

```typescript theme={"theme":{"light":"github-light","dark":"github-dark"}}
const eventsUrl = new URL('events', dappApiUrl + '/')
eventsUrl.searchParams.set('token', jwtToken)
const eventSource = new EventSource(eventsUrl.toString())

eventSource.addEventListener('accountsChanged', (e) => {
    /* ... */
})
eventSource.addEventListener('statusChanged', (e) => {
    /* ... */
})
eventSource.addEventListener('connected', (e) => {
    /* ... */
})
eventSource.addEventListener('txChanged', (e) => {
    /* ... */
})
```

SSE connections deliver real-time updates about transaction status (`txChanged`), account
changes (`accountsChanged`), and session state (`connected`, `statusChanged`).

## See also

* [dApp SDK overview](https://docs.canton.network/sdks-tools/sdks/dapp-sdk/overview.md)
* [dApp SDK events reference](https://docs.canton.network/sdks-tools/sdks/dapp-sdk/reference/events.md)
* [User API](https://docs.canton.network/integrations/wallet-gateway/reference/user-api.md)
