> For the complete documentation index, see [llms.txt](https://developer.trustwallet.com/developer/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.trustwallet.com/developer/trustconnect/modal-and-connections.md).

# Modal & Connection Management

TrustConnect provides React hooks for controlling the wallet connection modal and reading connection state across all supported chains.

## Modal control

### useTrustModal

Use `useTrustModal` to open and control the connection modal:

```tsx
import { useTrustModal } from '@trustwallet/connect-react'

function ConnectButton() {
    const { open } = useTrustModal()

    return (
        <>
            {/* Open wallet selection */}
            <button onClick={() => open()}>Connect Wallet</button>

            {/* Prompt the user to connect to a specific namespace */}
            <button onClick={() => open({ type: 'namespace', namespaceId: 'eip155' })}>
                Connect EVM Wallet
            </button>
        </>
    )
}
```

The `open` function accepts an optional parameter to target a specific namespace:

| Parameter     | Type          | Description                                                                    |
| ------------- | ------------- | ------------------------------------------------------------------------------ |
| `type`        | `'namespace'` | Specifies that the modal should filter by namespace                            |
| `namespaceId` | `string`      | The CAIP-2 namespace to filter wallets by (`'eip155'`, `'solana'`, `'bip122'`) |

## Connection state

### useConnections

Use `useConnections` to read all active connections across every namespace:

```tsx
import { useConnections } from '@trustwallet/connect-react'

function AllConnections() {
    const { connections } = useConnections()

    return (
        <ul>
            {connections.map((conn) => (
                <li key={conn.address}>
                    {conn.wallet?.name} — {conn.address}
                </li>
            ))}
        </ul>
    )
}
```

### useConnection

Use `useConnection` to read the connection for a single namespace:

```tsx
import { useConnection } from '@trustwallet/connect-react'

function WalletInfo() {
    const { isConnected, address, wallet, chain, status } = useConnection({
        namespaceId: 'eip155',
    })

    if (!isConnected) return <p>Not connected</p>

    return (
        <div>
            <p>Wallet: {wallet?.name}</p>
            <p>Address: {address}</p>
            <p>Chain: {chain?.reference}</p>
            <p>Status: {status}</p>
        </div>
    )
}
```

**Returned properties:**

| Property      | Type                  | Description                                      |
| ------------- | --------------------- | ------------------------------------------------ |
| `isConnected` | `boolean`             | Whether a wallet is connected for this namespace |
| `address`     | `string \| undefined` | The connected wallet address                     |
| `wallet`      | `object \| undefined` | Wallet metadata (name, icon, etc.)               |
| `chain`       | `object \| undefined` | The active chain for this connection             |
| `status`      | `string`              | Connection status                                |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://developer.trustwallet.com/developer/trustconnect/modal-and-connections.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
