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

# Solana provider

> Build the headless connect and transact pages a Solana global wallet provider needs.

Privy's hosted connect and transact pages serve EVM connections only. A provider that shares Solana wallets builds both pages itself with [`@privy-io/cross-app-provider`](https://docs.privy.io/wallets/global-wallets/launch-your-wallet/custom-experience), then points `custom_connect_url` and `custom_transact_url` at them. There is no hosted option.

> [!NOTE]
>
> `@privy-io/cross-app-provider` is a vanilla JavaScript library. Pair it with
> `@privy-io/react-auth` to resolve and sign with the user's embedded Solana wallet.

## What a Solana provider owns

| Responsibility | Detail |
| - | - |
| Consent surface | Both pages are the provider's own UI. Privy renders nothing. |
| Wallet resolution | Picks the user's embedded Solana wallet for the requested namespace. |
| Method handling | Routes each request by namespace, then by method. |
| Broadcast | Submits the transaction for `solana:signAndSendTransaction`. |
| Encoding | Matches the wire encodings the requester's adapter expects. |

## Create the client

```tsx theme={"system"}
// client.ts
import {createClient} from '@privy-io/cross-app-provider/connect';

export const client = createClient({
  appId: '<your-privy-app-id>'
});
```

## Build the connect page

Read the request, then resolve an address for the namespace it asks for.

```tsx theme={"system"}
import {getRequestNamespace} from '@privy-io/cross-app-provider/connect';

const connectionRequest = client.getConnectionRequestFromUrlParams();
const namespace = getRequestNamespace(connectionRequest); // 'eip155' | 'solana'
```

`getConnectionRequestFromUrlParams` throws on a `chain` parameter it does not recognize as a CAIP-2
chain ID. `getRequestNamespace` returns `'eip155'` when `chain` is absent, which only ever meant EVM.

The provider writes its own embedded-wallet predicates. react-auth's `isPrivyWallet` is `@internal`
and not importable, and the two wallet hooks return different shapes, so the checks cannot be shared:

```tsx theme={"system"}
import {useWallets as useEthereumWallets} from '@privy-io/react-auth';
import {useWallets as useSolanaWallets} from '@privy-io/react-auth/solana';

/** Embedded EVM wallet. `privy-v2` is the TEE-backed stack. */
const isEmbeddedEthereumWallet = (wallet: {walletClientType: string}) =>
  wallet.walletClientType === 'privy' || wallet.walletClientType === 'privy-v2';

/** Embedded Solana wallet. The Solana hook returns Wallet Standard wallets. */
const isEmbeddedSolanaWallet = (wallet: {standardWallet: {name: string; features: object}}) =>
  wallet.standardWallet.name === 'Privy' && 'privy:' in wallet.standardWallet.features;
```

The Solana predicate also excludes a cross-app wallet registered by `@privy-io/cross-app-connect`.
That wallet advertises neither the `Privy` name nor a `privy:` feature, by design.

Resolve the wallet for that namespace and nothing else:

```tsx theme={"system"}
const {wallets: ethereumWallets} = useEthereumWallets();
const {wallets: solanaWallets} = useSolanaWallets();

const resolvedAddress =
  namespace === 'solana'
    ? solanaWallets.find(isEmbeddedSolanaWallet)?.address
    : ethereumWallets.find(isEmbeddedEthereumWallet)?.address;

if (!resolvedAddress) {
  throw new Error(`No embedded ${namespace} wallet for this user`);
}

await client.acceptConnection({
  accessToken,
  address: resolvedAddress,
  userId: user.id,
  connectionRequest
});
```

Two rules matter here:

* Never fall back to a wallet on another chain. A Solana requester would silently receive an Ethereum address.
* Pick an **embedded** wallet, not the first entry a wallet hook returns. Both lists also carry injected wallets. A browser extension such as Phantom registers as an EVM provider and a Solana Wallet Standard wallet at once. Lending one asks the user's own extension to sign for the requester, with a wallet the provider does not custody.

Call `client.rejectConnection({accessToken, callbackUrl: connectionRequest.callbackUrl})` when the user declines.

## Build the transact page

`getVerifiedTransactionRequest` decrypts the request and verifies it before returning. It confirms the connection exists, has not expired, and belongs to the logged-in user.

It then binds the request two ways. It rejects a request whose namespace differs from the one the user approved at connect. On Solana, it also rejects a request that names an account other than the one that connection carries. A requester therefore cannot substitute a different wallet the user owns.

For known Solana methods it validates the `params` shape too. An unrecognized method passes through.

```tsx theme={"system"}
import {parseCaip2} from '@privy-io/cross-app-provider/connect';

const {connection, request} = await client.getVerifiedTransactionRequest({userId: user.id});
const namespace = request.chain ? parseCaip2(request.chain)?.namespace : 'eip155';
```

The namespace and the account come back verified, so read the account from `connection.address` rather than out of `params`. `request.chain` is the requester's claim within that namespace. Compare it against `connection.chain` if the cluster matters.

### Sign the request

Branch on `request.method`, then sign with the matching react-auth hook:

```tsx theme={"system"}
import {base58, base64} from '@scure/base';
import {
  parseSolanaSignTransactionParams,
  SOLANA_SIGN_AND_SEND_TRANSACTION_METHOD,
  toSolanaChainAlias
} from '@privy-io/cross-app-provider/connect';
import {
  useSignAndSendTransaction,
  useSignMessage,
  useSignTransaction,
  useWallets as useSolanaWallets
} from '@privy-io/react-auth/solana';

const {wallets: solanaWallets} = useSolanaWallets();
const {signAndSendTransaction} = useSignAndSendTransaction();
const {signTransaction} = useSignTransaction();
const {signMessage} = useSignMessage();

const wallet = solanaWallets.find((candidate) => candidate.address === connection.address);

if (!wallet) {
  throw new Error(`No Solana wallet found for ${connection.address}`);
}

if (!request.chain) {
  throw new Error('A Solana request must name a chain');
}

const chain = toSolanaChainAlias(request.chain);

if (request.method === SOLANA_SIGN_AND_SEND_TRANSACTION_METHOD) {
  const params = parseSolanaSignTransactionParams(request.params);
  const {signature} = await signAndSendTransaction({
    wallet,
    chain,
    transaction: base64.decode(params.transaction),
    options: {uiOptions: {showWalletUIs: false}, optimisticBroadcast: true}
  });

  await client.handleRequestResult({accessToken, result: base58.encode(signature), connection});
}
```

Read `params[0]` with `parseSolanaSignTransactionParams` for both transaction methods, or with `parseSolanaSignMessageParams` for `solana:signMessage`.

`toSolanaChainAlias` maps the genesis-hash chain ID to the alias form react-auth takes. It throws on an unrecognized chain rather than defaulting to a cluster. Signing against the wrong cluster is unrecoverable once broadcast.

Report failures with `client.handleError({accessToken, error, callbackUrl: connection.callbackUrl, chain: request.chain})`, and user rejections with `client.rejectRequest`.

### Suppress Privy's wallet UI

Pass `{uiOptions: {showWalletUIs: false}}` on every signing call. The provider's page is already the consent surface, so Privy's UIs would ask for a second approval.

Those UIs also end on a terminal success screen. They hold the signing promise pending until the user dismisses it, so the requester waits out its full timeout after a successful signature.

### Broadcast and confirmation

The provider submits the transaction, so broadcast policy is the provider's call. Set `optimisticBroadcast: true` to return the signature as soon as the cluster accepts the broadcast.

Polling for confirmation instead holds the popup open past the requester's timeout. A confirmation failure there also turns an already-broadcast transaction into a reported error. The requester holds the RPC connection, so confirmation belongs to it.

### Match the wire encodings

| Method | `params[0]` | Result to return |
| - | - | - |
| `solana:signAndSendTransaction` | `{account, transaction, options?}` | base58 signature |
| `solana:signTransaction` | `{account, transaction, options?}` | base64 signed transaction |
| `solana:signMessage` | `{account, message}` | base64 signature |

`signAndSendTransaction` returns the only base58 result.

## Reply transport

This package always answers over `postMessage`. It never reads the requester's `communication_mode`
parameter, and every call site leaves its internal mode at the `message` default.

Ask requesters for `message` so both sides agree. The
`@privy-io/cross-app-connect/solana` adapter already defaults to it. A requester calling
`createPrivyCrossAppClient` directly defaults to `redirect`, so it must set
`communicationMode: 'message'` explicitly.
