> 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/solana.md).

# Solana

TrustConnect provides React hooks for Solana wallet interactions.

## Installation

```bash
pnpm add @trustwallet/connect-solana-react
```

## Setup

Configure Solana using `createSolana`:

```tsx
import { createSolana, mainnet as solanaMainnet } from '@trustwallet/connect-solana-react'

const solana = createSolana({
    chain: solanaMainnet,
})
```

Then add it to the `namespaces` array in your `TrustConnectProvider` configuration. See [Quickstart](/developer/trustconnect/quickstart.md) for the full setup.

## Sign messages

### useSignMessage

Sign an arbitrary message with the connected Solana wallet:

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

function SolanaSignMessage() {
    const { isConnected } = useConnection({ namespaceId: 'solana' })
    const { mutate, data, isPending, isSuccess, error } = useSignMessage()

    const handleSign = () => {
        if (!isConnected) return
        mutate({ message: 'Hello Solana!' })
    }

    // Signature is returned as Uint8Array
    const signatureBase58 = data ? bs58.encode(data.signature) : null

    return (
        <div>
            <button onClick={handleSign} disabled={isPending || !isConnected}>
                {isPending ? 'Signing...' : 'Sign Message'}
            </button>
            {isSuccess && signatureBase58 && (
                <div>
                    <p>Message signed successfully!</p>
                    <code>{signatureBase58}</code>
                </div>
            )}
            {error && <p>Error: {error.message}</p>}
        </div>
    )
}
```

## Send transactions

### useSignSendTransaction

Sign and broadcast a Solana transaction:

```tsx
import { useSignSendTransaction } from '@trustwallet/connect-solana-react'
import { Transaction, SystemProgram, PublicKey } from '@solana/web3.js'

function SolanaSendTransaction() {
    const { mutateAsync, isPending } = useSignSendTransaction()

    const handleSend = async () => {
        try {
            const tx = new Transaction().add(
                SystemProgram.transfer({
                    fromPubkey: new PublicKey('...'),
                    toPubkey: new PublicKey('...'),
                    lamports: 1000000, // 0.001 SOL
                })
            )

            const serialized = tx.serialize({ requireAllSignatures: false })
            const result = await mutateAsync({
                transaction: serialized,
                options: {
                    skipPreflight: false,
                    preflightCommitment: 'confirmed',
                },
            })

            console.log('Transaction signature:', result.signature)
        } catch (error) {
            console.error('Transaction failed:', error)
        }
    }

    return (
        <button onClick={handleSend} disabled={isPending}>
            {isPending ? 'Sending...' : 'Send SOL'}
        </button>
    )
}
```

#### Transaction options

| Option                | Type                                        | Description                                              |
| --------------------- | ------------------------------------------- | -------------------------------------------------------- |
| `skipPreflight`       | `boolean`                                   | Disable transaction verification at the RPC              |
| `preflightCommitment` | `'processed' \| 'confirmed' \| 'finalized'` | Commitment level for preflight                           |
| `commitment`          | `'processed' \| 'confirmed' \| 'finalized'` | If provided, confirm the transaction after sending       |
| `maxRetries`          | `number`                                    | Maximum number of times to retry sending the transaction |
| `minContextSlot`      | `number`                                    | Minimum slot to include the transaction                  |


---

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