Loading...
Loading...
Connect Solana wallets and sign or send transactions in React Native Expo apps using Mobile Wallet Adapter and Wallet UI. Use when adding a connect wallet button, showing a connected address, disconnecting, signing messages, sign-in with Solana, transferring SOL, or sending any transaction from a Solana mobile app.
npx skill4agent add solana-mobile/solana-mobile-dev-skill solana-mobile-wallet@wallet-ui/react-native-kit@wallet-ui/react-native-web3jssolana-mobile@solana/kit@wallet-ui/react-native-kit@solana/web3.jspackage.json | Do this |
|---|---|
| Kit. This file, plus references/kit.md |
| references/web3js.md |
| The user explicitly asked for web3.js | references/web3js.md, and say why kit would be better |
useMobileWalletMobileWalletProvidercreateSolana*SolanaClusterlabelimport {
type AppIdentity,
createSolanaDevnet,
MobileWalletProvider,
type SolanaCluster,
} from '@wallet-ui/react-native-kit'
const identity: AppIdentity = { name: 'My App' }
const cluster: SolanaCluster = createSolanaDevnet({ url: 'https://api.devnet.solana.com' })
<MobileWalletProvider cluster={cluster} identity={identity}>
{children}
</MobileWalletProvider>createSolanaDevnetcreateSolanaTestnetcreateSolanaLocalnetcreateSolanaMainneturlclusteridentitycachecreateClientchildrenchainendpointAppIdentitynameuriQueryClientProvider@tanstack/react-queryimport { useMobileWallet } from '@wallet-ui/react-native-kit'
const { account, connect, disconnect, client } = useMobileWallet()| Value | Type | Notes |
|---|---|---|
| | |
| | All authorized accounts |
| | Opens the wallet picker |
| | |
| | Kit client — use |
| | The active cluster. Put it in query keys |
| | Simplest send path |
| | Note the second argument |
| | Sign without broadcasting |
| | |
| | Sign-in with Solana; can also connect |
| Config and authorization store |
sendTransactionsignMessagesignTransactionsconnectedconst connected = !!accountsignAndSendTransactionminContextSlotgetLatestBlockhashsendTransactions(instructions)clientconnectionconnectionchainaccount.addressAddressaccount.labelimport { Pressable, Text } from 'react-native'
import { useMobileWallet } from '@wallet-ui/react-native-kit'
export function ConnectButton() {
const { account, connect, disconnect } = useMobileWallet()
async function onPress() {
try {
if (account) await disconnect()
else await connect()
} catch (error) {
// The user dismissing the wallet picker lands here. Do not treat it as a crash.
console.error(error)
}
}
return (
<Pressable onPress={onPress}>
<Text>{account ? 'Disconnect' : 'Connect Wallet'}</Text>
</Pressable>
)
}connect()clientimport type { Address } from '@solana/kit'
import { useQuery } from '@tanstack/react-query'
import { useMobileWallet } from '@wallet-ui/react-native-kit'
export function useGetBalance({ address }: { address: Address }) {
const { chain, client } = useMobileWallet()
return useQuery({
queryFn: () => client.rpc.getBalance(address).send(),
queryKey: ['get-balance', chain, address],
})
}client.rpc.someMethod(...).send().send()bigintparseFloatexport function lamportsToSol(lamports: bigint) {
return Number(lamports) / 1e9
}import { getAddMemoInstruction } from '@solana-program/memo'
import type { Instruction } from '@solana/kit'
const { sendTransactions } = useMobileWallet()
const instructions: Instruction[] = [getAddMemoInstruction({ memo: 'gm' })]
const signature = await sendTransactions(instructions)sendTransactionsminContextSlotpipe@solana/web3.jsexpo-kit-minimalnpx solana-mobile@latest create /tmp/reference-app --template expo-kit-minimal --skip-installsolana-mobileintegration-privyseeker-genesis-tokenseeker-domains.skr