> ## 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.

# Automate with the User API

> Drive wallet setup, signing, and transactions from a script or backend using the User API.

The User API is the JSON-RPC 2.0 API behind the User UI. Anything a person can do in the UI —
manage sessions, networks, identity providers, wallets, and transactions — you can do
programmatically with the same API. Use it to script wallet setup, build a custom wallet UI
embedded in your app, or automate operations from a backend.

This guide walks through a typical automation flow. For the full method list, authentication
rules, and the OpenRPC specification, see the
[User API reference](https://docs.canton.network/integrations/wallet-gateway/reference/user-api.md).

> [!NOTE]
>
> The User API drives **your own** wallets and setup. It is different from the
> [dApp API](https://docs.canton.network/integrations/wallet-gateway/reference/dapp-api.md), which dApps call through the dApp
> SDK to connect to a user's wallet.

## Before you start

You need:

* A running Wallet Gateway you can reach (for example `http://localhost:3030`). See the
  [Quickstart](https://docs.canton.network/integrations/wallet-gateway/quickstart.md).
* At least one configured network and identity provider. See
  [Networks & identity providers](https://docs.canton.network/integrations/wallet-gateway/operate/networks-and-identity.md).
* A way to obtain a JWT from that identity provider for the user you are automating.

All calls are JSON-RPC 2.0 `POST` requests to the User API base path
(`/api/v0/user` by default, configurable via `server.userPath`):

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl -X POST http://localhost:3030/api/v0/user \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer <jwt-token>' \
  -d '{ "jsonrpc": "2.0", "id": 1, "method": "<method>", "params": { } }'
```

Most methods require the `Authorization` header. Three methods are available without it so a
client can bootstrap a connection: `addSession()`, `listNetworks()`, and `listIdps()`.

> [!NOTE]
>
> Parameter shapes vary per method. Use the
> [OpenRPC specification](https://github.com/canton-network/wallet/blob/main/api-specs/openrpc-user-api.json)
> as the source of truth for exact request and response fields.

## Create a session

Start the connection with `addSession()` (no authentication required), then complete your
identity provider's auth flow to obtain a JWT. Pass that JWT in the `Authorization` header on
every later call.

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl -X POST http://localhost:3030/api/v0/user \
  -H 'Content-Type: application/json' \
  -d '{ "jsonrpc": "2.0", "id": 1, "method": "addSession", "params": { } }'
```

The Wallet Gateway issues a session tied to the authenticated user. List active sessions with
`listSessions()` and end the current one with `removeSession()`.

## Discover networks and identity providers

List what the Wallet Gateway offers before creating wallets. Both calls work without authentication.

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
# List configured networks
curl -X POST http://localhost:3030/api/v0/user \
  -H 'Content-Type: application/json' \
  -d '{ "jsonrpc": "2.0", "id": 2, "method": "listNetworks", "params": { } }'

# List identity providers
curl -X POST http://localhost:3030/api/v0/user \
  -H 'Content-Type: application/json' \
  -d '{ "jsonrpc": "2.0", "id": 3, "method": "listIdps", "params": { } }'
```

Admins can also manage these at runtime with `addNetwork()`, `removeNetwork()`, `addIdp()`, and
`removeIdp()`. Admin privileges are granted to the user configured as `server.admin`; see
[Configure the Wallet Gateway](https://docs.canton.network/integrations/wallet-gateway/operate/configure.md#server).

## Create and manage wallets

Create a wallet by choosing a network and a signing provider, then manage the set with the
wallet methods.

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
# Create a wallet (party) on a network
curl -X POST http://localhost:3030/api/v0/user \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer <jwt-token>' \
  -d '{ "jsonrpc": "2.0", "id": 4, "method": "createWallet", "params": { } }'
```

| Method | Description |
| - | - |
| `createWallet()` | Create a new wallet (party) on a network. |
| `listWallets()` | List all wallets for the current user. |
| `setPrimaryWallet()` | Set the primary wallet dApps default to. |
| `removeWallet()` | Remove a wallet from the Wallet Gateway. |
| `syncWallets()` | Sync wallets with the ledger. |
| `isWalletSyncNeeded()` | Check whether a wallet sync is needed. |

## Sign and execute a transaction

Once a wallet exists, sign and submit transactions with `sign()` and `execute()`, then read
status with the transaction methods.

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
# Sign a prepared transaction
curl -X POST http://localhost:3030/api/v0/user \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer <jwt-token>' \
  -d '{ "jsonrpc": "2.0", "id": 5, "method": "sign", "params": { } }'

# Execute a signed transaction
curl -X POST http://localhost:3030/api/v0/user \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer <jwt-token>' \
  -d '{ "jsonrpc": "2.0", "id": 6, "method": "execute", "params": { } }'
```

Read transactions with `getTransaction()` and `listTransactions()`. Signing is delegated to the
wallet's [signing provider](https://docs.canton.network/integrations/wallet-gateway/operate/signing-providers.md), so the key
never leaves that provider.

## Follow transactions in real time

The dApp API exposes Server-Sent Events for real-time updates (`txChanged`, `accountsChanged`,
`connected`, `statusChanged`). If you are building a custom UI, subscribe to them instead of
polling. See [Real-time events](https://docs.canton.network/integrations/wallet-gateway/reference/dapp-api.md#real-time-events-sse).

## End the session

When you are done, end the session:

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl -X POST http://localhost:3030/api/v0/user \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer <jwt-token>' \
  -d '{ "jsonrpc": "2.0", "id": 7, "method": "removeSession", "params": { } }'
```

## Next steps

* [User API reference](https://docs.canton.network/integrations/wallet-gateway/reference/user-api.md): Every method, authentication rules, rate limits, and the OpenRPC spec.
* [Party management](https://docs.canton.network/integrations/wallet-gateway/use/party-management.md): The same operations in the User UI.
* [Approve & sign transactions](https://docs.canton.network/integrations/wallet-gateway/use/approve-and-sign.md): How approval and signing work end to end.
* [Signing providers](https://docs.canton.network/integrations/wallet-gateway/operate/signing-providers.md): Where each wallet's keys live and who signs.
