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

# Quickstart

> Usage examples for connecting to wallets, signing messages, and sending transactions with useMobileWallet.

This page demonstrates how to use each method from the `useMobileWallet` hook. Make sure you have completed the [Installation](https://docs.solanamobile.com/get-started/react-native/installation.md) and [Setup](https://docs.solanamobile.com/get-started/react-native/setup.md) steps first.

Stay on the tab for the Solana library you installed.

## Connect / Disconnect

Use `connect` to initiate a wallet connection and `disconnect` to end it. The `account` field holds the selected wallet account.

> [tab] @solana/kit
>
> ```tsx theme={null}
> import { useMobileWallet } from '@wallet-ui/react-native-kit'
>
> function ConnectButton() {
>   const { account, connect, disconnect } = useMobileWallet()
>
>   if (account) {
>     return <Button title="Disconnect" onPress={disconnect} />
>   }
>
>   return <Button title="Connect Wallet" onPress={connect} />
> }
> ```

> [tab] @solana/web3.js
>
> ```tsx theme={null}
> import { useMobileWallet } from '@wallet-ui/react-native-web3js'
>
> function ConnectButton() {
>   const { account, connect, disconnect } = useMobileWallet()
>
>   if (account) {
>     return <Button title="Disconnect" onPress={disconnect} />
>   }
>
>   return <Button title="Connect Wallet" onPress={connect} />
> }
> ```

## Sign Message

Use `signMessages` to request the wallet to sign an arbitrary byte payload. This is useful for off-chain signature verification.

> [tab] @solana/kit
>
> ```tsx theme={null}
> import { useMobileWallet } from '@wallet-ui/react-native-kit'
>
> function SignMessageButton() {
>   const { signMessages } = useMobileWallet()
>
>   const handleSignMessage = async () => {
>     const messageBytes = new TextEncoder().encode('Verify this message')
>     const signature = await signMessages(messageBytes)
>     console.log('Signature:', signature)
>   }
>
>   return <Button title="Sign Message" onPress={handleSignMessage} />
> }
> ```

> [tab] @solana/web3.js
>
> ```tsx theme={null}
> import { useMobileWallet } from '@wallet-ui/react-native-web3js'
>
> function SignMessageButton() {
>   const { signMessages } = useMobileWallet()
>
>   const handleSignMessage = async () => {
>     const messageBytes = new TextEncoder().encode('Verify this message')
>     const signature = await signMessages(messageBytes)
>     console.log('Signature:', signature)
>   }
>
>   return <Button title="Sign Message" onPress={handleSignMessage} />
> }
> ```

> [!NOTE]
>
> `signMessages` takes bytes, not a string. Use `TextEncoder` to encode text — a
> base64 helper such as `toUint8Array` will decode your text as base64 and sign
> the wrong payload.

## Sign In with Solana (SIWS)

Use `signIn` to connect to a wallet and verify ownership in a single step. This combines authorization and message signing into one user interaction. Read the account from the returned result — the hook's `account` is not updated until the next render.

> [tab] @solana/kit
>
> ```tsx theme={null}
> import { useMobileWallet } from '@wallet-ui/react-native-kit'
>
> function SignInButton() {
>   const { account, chain, identity, signIn } = useMobileWallet()
>
>   const handleSignIn = async () => {
>     const result = await signIn({
>       address: account?.address,
>       chainId: chain,
>       domain: 'your-app-domain.com',
>       statement: 'Sign in to Your App',
>       uri: identity.uri,
>     })
>     console.log('Signed in:', result.account.address)
>   }
>
>   return <Button title="Sign In" onPress={handleSignIn} />
> }
> ```

> [tab] @solana/web3.js
>
> ```tsx theme={null}
> import { useMobileWallet } from '@wallet-ui/react-native-web3js'
>
> function SignInButton() {
>   const { account, chain, identity, signIn } = useMobileWallet()
>
>   const handleSignIn = async () => {
>     const result = await signIn({
>       address: account?.address.toString(),
>       chainId: chain,
>       domain: 'your-app-domain.com',
>       statement: 'Sign in to Your App',
>       uri: identity.uri,
>     })
>     console.log('Signed in:', result.account.address.toString())
>   }
>
>   return <Button title="Sign In" onPress={handleSignIn} />
> }
> ```

> [!NOTE]
>
> `signIn` works whether or not the user is already connected. Omit `address` to
> let the wallet pick the account and sign in as part of the same prompt.

## Sign and Send Transaction

Request the wallet to sign a transaction and submit it to the Solana network. Both examples send a memo instruction — swap it for whichever instructions your app builds.

> [tab] @solana/kit
>
> `sendTransactions` takes instructions and handles fetching the blockhash, compiling the transaction, signing, and sending.
>
> ```tsx theme={null}
> import { getAddMemoInstruction } from '@solana-program/memo'
> import { Instruction } from '@solana/kit'
> import { useMobileWallet } from '@wallet-ui/react-native-kit'
>
> function SendTransactionButton() {
>   const { sendTransactions } = useMobileWallet()
>
>   const handleSendTransaction = async () => {
>     const instructions: Instruction[] = [
>       getAddMemoInstruction({ memo: 'gm from Mobile Wallet Adapter' }),
>     ]
>
>     const signature = await sendTransactions(instructions)
>     console.log('Transaction signature:', signature)
>   }
>
>   return <Button title="Send Transaction" onPress={handleSendTransaction} />
> }
> ```

> [tab] @solana/web3.js
>
> `signAndSendTransactions` takes a built transaction plus the `minContextSlot` the blockhash was fetched at, so compile the transaction yourself.
>
> ```tsx theme={null}
> import { createMemoInstruction } from '@solana/spl-memo'
> import { TransactionMessage, VersionedTransaction } from '@solana/web3.js'
> import { useMobileWallet } from '@wallet-ui/react-native-web3js'
>
> function SendTransactionButton() {
>   const { account, connection, signAndSendTransactions } = useMobileWallet()
>
>   const handleSendTransaction = async () => {
>     if (!account) return
>
>     const {
>       context: { slot: minContextSlot },
>       value: latestBlockhash,
>     } = await connection.getLatestBlockhashAndContext()
>
>     const message = new TransactionMessage({
>       payerKey: account.address,
>       recentBlockhash: latestBlockhash.blockhash,
>       instructions: [createMemoInstruction('gm from Mobile Wallet Adapter')],
>     }).compileToLegacyMessage()
>
>     const transaction = new VersionedTransaction(message)
>
>     const signature = await signAndSendTransactions(transaction, minContextSlot)
>
>     await connection.confirmTransaction(
>       { signature, ...latestBlockhash },
>       'confirmed',
>     )
>
>     console.log('Transaction signature:', signature)
>   }
>
>   return <Button title="Send Transaction" onPress={handleSendTransaction} />
> }
> ```

> [!WARNING]
>
> `signAndSendTransactions` requires `minContextSlot`. Fetch the blockhash with
> `getLatestBlockhashAndContext()` so you have the slot to pass along, rather
> than `getLatestBlockhash()`.

## Next steps

> [card] [Advanced: Invoke MWA Sessions Directly](https://docs.solanamobile.com/get-started/react-native/invoke-mwa-sessions-directly.md)
>
> Learn the low-level transact() API for direct MWA session control.

> [card] [Sample Apps](https://docs.solanamobile.com/sample-apps/sample_app_overview.md)
>
> Browse reference apps to jumpstart your development.

Code samples on this page are subject to the
[Apache 2.0 license](https://www.apache.org/licenses/LICENSE-2.0)
.
