Get from zero to a working wallet connection in your React app.
Install the core package, at least one network package, and WalletConnect:
pnpm add @trustwallet/connect-react \
@trustwallet/connect-eip155-react \
@trustwallet/connect-walletconnectEIP-155 requires these peer dependencies:
pnpm add @tanstack/react-query viemOther chains? Add
@trustwallet/connect-solana-reactfor Solana or@trustwallet/connect-bip122-reactfor Bitcoin. See Solana and Bitcoin for details.
Wrap your app with TrustConnectProvider and configure the namespaces and services:
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { mainnet, polygon } from 'viem/chains'
import { createEIP155 } from '@trustwallet/connect-eip155-react'
import { createWalletConnect } from '@trustwallet/connect-walletconnect'
import { TrustConnectProvider } from '@trustwallet/connect-react'
const queryClient = new QueryClient()
const projectId = import.meta.env.VITE_WALLETCONNECT_ID
const eip155 = createEIP155({
chains: [mainnet, polygon],
})
const walletConnect = createWalletConnect({
projectId,
metadata: {
name: 'My dApp',
url: 'https://example.com',
description: 'My awesome dApp',
icons: ['https://example.com/icon.png'],
},
})
function App() {
return (
<TrustConnectProvider
config={{
namespaces: [eip155],
services: [walletConnect],
}}
>
<QueryClientProvider client={queryClient}>
<YourApp />
</QueryClientProvider>
</TrustConnectProvider>
)
}WalletConnect project ID — get yours at cloud.walletconnect.com.
Use the useTrustModal hook to open the wallet selection modal:
import { useTrustModal } from '@trustwallet/connect-react'
function ConnectButton() {
const { open } = useTrustModal()
return <button onClick={() => open()}>Connect Wallet</button>
}Use useConnection to check if a wallet is connected and read its details:
import { useConnection } from '@trustwallet/connect-react'
function WalletInfo() {
const { isConnected, address, wallet, chain } = 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>
</div>
)
}- Modal & Connection Management — fine-grained modal and connection control
- EVM (EIP-155) — sign messages, write contracts, and send transactions
- Solana — Solana wallet interactions
- Bitcoin (BIP-122) — Bitcoin wallet interactions
- Theming & Customization — match the modal to your brand