@trustwallet/connect-react 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (112) hide show
  1. package/LICENSE.md +76 -0
  2. package/README.md +567 -0
  3. package/cli.js +144 -0
  4. package/dist/global-NUJAOJRO.css +132 -0
  5. package/dist/index.d.ts +13 -0
  6. package/dist/index.js +705 -0
  7. package/dist/styles.module-27BC6Q35.module.css +7 -0
  8. package/dist/styles.module-2IXPYHX5.module.css +33 -0
  9. package/dist/styles.module-4I5UVTXZ.module.css +34 -0
  10. package/dist/styles.module-4QHLSLTJ.module.css +9 -0
  11. package/dist/styles.module-5C4YIUDE.module.css +26 -0
  12. package/dist/styles.module-5FM5SDSC.module.css +8 -0
  13. package/dist/styles.module-5L4UXGVZ.module.css +62 -0
  14. package/dist/styles.module-5S7A3MI3.module.css +6 -0
  15. package/dist/styles.module-5TDOAM3X.module.css +5 -0
  16. package/dist/styles.module-BH6BB6HX.module.css +23 -0
  17. package/dist/styles.module-FMH4FUT5.module.css +35 -0
  18. package/dist/styles.module-GCRMKZIZ.module.css +9 -0
  19. package/dist/styles.module-GSNHG7ET.module.css +92 -0
  20. package/dist/styles.module-HR3VQZUH.module.css +44 -0
  21. package/dist/styles.module-IZSJLNB4.module.css +9 -0
  22. package/dist/styles.module-JFMC6A5G.module.css +6 -0
  23. package/dist/styles.module-KIOD6JAJ.module.css +5 -0
  24. package/dist/styles.module-NDDQJHO2.module.css +21 -0
  25. package/dist/styles.module-PXUDS327.module.css +7 -0
  26. package/dist/styles.module-RKS6GYHN.module.css +6 -0
  27. package/dist/styles.module-U5TRY5PT.module.css +123 -0
  28. package/dist/styles.module-U6N4VKTA.module.css +72 -0
  29. package/dist/styles.module-VWMJAIVE.module.css +20 -0
  30. package/dist/styles.module-WGWNXHEK.module.css +5 -0
  31. package/dist/styles.module-Y3MUWEOL.module.css +5 -0
  32. package/dist/styles.module-YJSZIZTZ.module.css +32 -0
  33. package/dist/styles.module-ZISFY5AO.module.css +15 -0
  34. package/dist/styles.module-ZPYBUUD6.module.css +8 -0
  35. package/package.json +53 -0
  36. package/src/context/index.tsx +25 -0
  37. package/src/index.ts +9 -0
  38. package/src/styles/global.css +132 -0
  39. package/src/types/css-modules.d.ts +4 -0
  40. package/src/ui/TrustModal.tsx +31 -0
  41. package/src/ui/buttons/GetTrustButton/components/GetTrustMessage/index.tsx +10 -0
  42. package/src/ui/buttons/GetTrustButton/components/GetTrustMessage/styles.module.css +7 -0
  43. package/src/ui/buttons/GetTrustButton/components/GetTrustWrapper/index.tsx +10 -0
  44. package/src/ui/buttons/GetTrustButton/components/GetTrustWrapper/styles.module.css +5 -0
  45. package/src/ui/buttons/GetTrustButton/index.tsx +21 -0
  46. package/src/ui/buttons/NamespaceButton/index.tsx +62 -0
  47. package/src/ui/buttons/NamespaceButton/styles.module.css +72 -0
  48. package/src/ui/buttons/WalletButton/index.tsx +76 -0
  49. package/src/ui/buttons/WalletButton/styles.module.css +123 -0
  50. package/src/ui/buttons/WalletConnectButton/components/WCGrid/index.tsx +10 -0
  51. package/src/ui/buttons/WalletConnectButton/components/WCGrid/styles.module.css +5 -0
  52. package/src/ui/buttons/WalletConnectButton/components/WCTitle/index.tsx +5 -0
  53. package/src/ui/buttons/WalletConnectButton/components/WCTitle/styles.module.css +8 -0
  54. package/src/ui/buttons/WalletConnectButton/index.tsx +16 -0
  55. package/src/ui/components/Footer/components/FooterDescription/index.tsx +10 -0
  56. package/src/ui/components/Footer/components/FooterDescription/styles.module.css +6 -0
  57. package/src/ui/components/Footer/components/FooterLink/index.tsx +15 -0
  58. package/src/ui/components/Footer/components/FooterLink/styles.module.css +20 -0
  59. package/src/ui/components/Footer/components/FooterWrapper/index.tsx +10 -0
  60. package/src/ui/components/Footer/components/FooterWrapper/styles.module.css +21 -0
  61. package/src/ui/components/Footer/index.tsx +16 -0
  62. package/src/ui/icons/BackIcon.tsx +14 -0
  63. package/src/ui/icons/CheckIcon.tsx +17 -0
  64. package/src/ui/icons/ClearIcon.tsx +13 -0
  65. package/src/ui/icons/CloseIcon.tsx +14 -0
  66. package/src/ui/icons/CopyIcon.tsx +16 -0
  67. package/src/ui/icons/SearchIcon.tsx +20 -0
  68. package/src/ui/icons/Spinner.tsx +7 -0
  69. package/src/ui/inputs/SearchBar/index.tsx +44 -0
  70. package/src/ui/inputs/SearchBar/styles.module.css +62 -0
  71. package/src/ui/layout/ModalBody/index.tsx +15 -0
  72. package/src/ui/layout/ModalBody/styles.module.css +15 -0
  73. package/src/ui/layout/ModalError/index.tsx +9 -0
  74. package/src/ui/layout/ModalError/styles.module.css +9 -0
  75. package/src/ui/layout/ModalHeader/index.tsx +26 -0
  76. package/src/ui/layout/ModalHeader/styles.module.css +92 -0
  77. package/src/ui/layout/ModalOverlay/index.tsx +15 -0
  78. package/src/ui/layout/ModalOverlay/styles.module.css +33 -0
  79. package/src/ui/layout/ModalWrapper/index.tsx +23 -0
  80. package/src/ui/layout/ModalWrapper/styles.module.css +26 -0
  81. package/src/ui/views/MobileWalletsView/components/MobileEmptyState/index.tsx +13 -0
  82. package/src/ui/views/MobileWalletsView/components/MobileEmptyState/styles.module.css +9 -0
  83. package/src/ui/views/MobileWalletsView/components/MobileLoading/index.tsx +5 -0
  84. package/src/ui/views/MobileWalletsView/components/MobileLoading/styles.module.css +9 -0
  85. package/src/ui/views/MobileWalletsView/components/MobileSearch/index.tsx +36 -0
  86. package/src/ui/views/MobileWalletsView/components/MobileSearch/styles.module.css +44 -0
  87. package/src/ui/views/MobileWalletsView/components/MobileWalletsList/index.tsx +46 -0
  88. package/src/ui/views/MobileWalletsView/components/MobileWalletsList/styles.module.css +35 -0
  89. package/src/ui/views/MobileWalletsView/components/MobileWrapper/index.tsx +10 -0
  90. package/src/ui/views/MobileWalletsView/components/MobileWrapper/styles.module.css +6 -0
  91. package/src/ui/views/MobileWalletsView/index.tsx +22 -0
  92. package/src/ui/views/NamespaceView/components/NamespaceGrid/index.tsx +10 -0
  93. package/src/ui/views/NamespaceView/components/NamespaceGrid/styles.module.css +5 -0
  94. package/src/ui/views/NamespaceView/components/NamespaceHeader/index.tsx +20 -0
  95. package/src/ui/views/NamespaceView/components/NamespaceHeader/styles.module.css +34 -0
  96. package/src/ui/views/NamespaceView/index.tsx +16 -0
  97. package/src/ui/views/QRView/components/QRActions/index.tsx +11 -0
  98. package/src/ui/views/QRView/components/QRActions/styles.module.css +8 -0
  99. package/src/ui/views/QRView/components/QRButton/index.tsx +15 -0
  100. package/src/ui/views/QRView/components/QRButton/styles.module.css +32 -0
  101. package/src/ui/views/QRView/components/QRError/index.tsx +9 -0
  102. package/src/ui/views/QRView/components/QRError/styles.module.css +5 -0
  103. package/src/ui/views/QRView/components/QRPlaceholder/index.tsx +10 -0
  104. package/src/ui/views/QRView/components/QRPlaceholder/styles.module.css +7 -0
  105. package/src/ui/views/QRView/components/QRWrapper/index.tsx +14 -0
  106. package/src/ui/views/QRView/components/QRWrapper/styles.module.css +23 -0
  107. package/src/ui/views/QRView/index.tsx +24 -0
  108. package/src/ui/views/WalletsView/components/WalletsGrid/index.tsx +10 -0
  109. package/src/ui/views/WalletsView/components/WalletsGrid/styles.module.css +5 -0
  110. package/src/ui/views/WalletsView/components/WalletsHeader/index.tsx +9 -0
  111. package/src/ui/views/WalletsView/components/WalletsHeader/styles.module.css +6 -0
  112. package/src/ui/views/WalletsView/index.tsx +20 -0
package/LICENSE.md ADDED
@@ -0,0 +1,76 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
10
+
11
+ "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
12
+
13
+ "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
14
+
15
+ "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
16
+
17
+ "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
18
+
19
+ "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
20
+
21
+ "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
22
+
23
+ "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
24
+
25
+ "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
26
+
27
+ "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
28
+
29
+ 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
30
+
31
+ 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
32
+
33
+ 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
34
+
35
+ You must give any other recipients of the Work or Derivative Works a copy of this License; and
36
+ You must cause any modified files to carry prominent notices stating that You changed the files; and
37
+ You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
38
+ If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
39
+ You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
40
+
41
+ 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
42
+
43
+ 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
44
+
45
+ 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
46
+
47
+ 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
48
+
49
+ 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
50
+
51
+ END OF TERMS AND CONDITIONS
52
+
53
+ APPENDIX: How to apply the Apache License to your work.
54
+
55
+ To apply the Apache License to your work, attach the following
56
+ boilerplate notice, with the fields enclosed by brackets "[]"
57
+ replaced with your own identifying information. (Don't include
58
+ the brackets!) The text should be enclosed in the appropriate
59
+ comment syntax for the file format. We also recommend that a
60
+ file or class name and description of purpose be included on the
61
+ same "printed page" as the copyright notice for easier
62
+ identification within third-party archives.
63
+
64
+ Copyright [yyyy] [name of copyright owner]
65
+
66
+ Licensed under the Apache License, Version 2.0 (the "License");
67
+ you may not use this file except in compliance with the License.
68
+ You may obtain a copy of the License at
69
+
70
+ http://www.apache.org/licenses/LICENSE-2.0
71
+
72
+ Unless required by applicable law or agreed to in writing, software
73
+ distributed under the License is distributed on an "AS IS" BASIS,
74
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
75
+ See the License for the specific language governing permissions and
76
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,567 @@
1
+ # TrustConnect SDK (Alpha)
2
+
3
+ A [CAIP](https://chainagnostic.org/) compliant, multi-chain wallet connection SDK.
4
+
5
+ ## Installation
6
+
7
+ Install the main React package:
8
+
9
+ ```sh
10
+ pnpm add @trustwallet/connect-react
11
+ ```
12
+
13
+ ### Network-specific packages
14
+
15
+ Install network-specific packages for the chains you want to support:
16
+
17
+ ```sh
18
+ # EIP-155 (EVM chains like Ethereum, Polygon, etc.)
19
+ pnpm add @trustwallet/connect-eip155-react
20
+
21
+ # Solana
22
+ pnpm add @trustwallet/connect-solana-react
23
+
24
+ # Bitcoin (BIP-122)
25
+ pnpm add @trustwallet/connect-bip122-react
26
+ ```
27
+
28
+ For WalletConnect support (mobile and QR code connections):
29
+
30
+ ```sh
31
+ pnpm add @trustwallet/connect-walletconnect
32
+ ```
33
+
34
+ EIP155 peer dependencies (if not already installed):
35
+
36
+ ```sh
37
+ pnpm add @tanstack/react-query viem
38
+ ```
39
+
40
+ ---
41
+
42
+ ## Setup
43
+
44
+ Wrap your app with `TrustConnectProvider` and configure your supported networks:
45
+
46
+ ```tsx
47
+ import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
48
+ import { mainnet, polygon } from 'viem/chains'
49
+
50
+ // Network namespaces
51
+ import { createEIP155 } from '@trustwallet/connect-eip155-react'
52
+ import { createBIP122, mainnet as bip122Mainnet } from '@trustwallet/connect-bip122-react'
53
+ import { createSolana, mainnet as solanaMainnet } from '@trustwallet/connect-solana-react'
54
+
55
+ // Services
56
+ import { createWalletConnect } from '@trustwallet/connect-walletconnect'
57
+
58
+ // Core provider
59
+ import { TrustConnectProvider } from '@trustwallet/connect-react'
60
+
61
+ const queryClient = new QueryClient()
62
+ const projectId = import.meta.env.VITE_WALLETCONNECT_ID
63
+
64
+ // Configure EVM chains
65
+ const eip155 = createEIP155({
66
+ chains: [mainnet, polygon],
67
+ })
68
+
69
+ // Configure Solana
70
+ const solana = createSolana({
71
+ chain: solanaMainnet,
72
+ })
73
+
74
+ // Configure Bitcoin
75
+ const bip122 = createBIP122({
76
+ chain: bip122Mainnet,
77
+ })
78
+
79
+ // Configure WalletConnect service
80
+ const walletConnect = createWalletConnect({
81
+ projectId,
82
+ metadata: {
83
+ name: 'My dApp',
84
+ url: 'https://example.com',
85
+ description: 'My awesome dApp',
86
+ icons: ['https://example.com/icon.png'],
87
+ },
88
+ })
89
+
90
+ function App() {
91
+ return (
92
+ <TrustConnectProvider
93
+ config={{
94
+ namespaces: [eip155, solana, bip122],
95
+ services: [walletConnect],
96
+ }}
97
+ theme="dark" // Optional: 'light', 'dark', or 'auto' (default: 'auto')
98
+ >
99
+ <QueryClientProvider client={queryClient}>
100
+ <YourApp />
101
+ </QueryClientProvider>
102
+ </TrustConnectProvider>
103
+ )
104
+ }
105
+ ```
106
+
107
+ ### Configuration Options
108
+
109
+ **Note:** The EIP-155 package uses [Viem](https://viem.sh). You can configure custom RPC URLs and it will internally create Viem transports:
110
+
111
+ ```ts
112
+ import { mainnet } from 'viem/chains'
113
+ import { formatChainId, createEIP155 } from '@trustwallet/connect-eip155-react'
114
+
115
+ // Since Viem doesn't follow CAIP-2 we need to format the chain reference first.
116
+ const caipMainnetId = formatChainId(mainnet.id)
117
+
118
+ const eip155 = createEIP155({
119
+ chains: [mainnet],
120
+ rpcUrls: {
121
+ [caipMainnetId]: ['https://rpc-node.com'],
122
+ },
123
+ })
124
+ ```
125
+
126
+ ---
127
+
128
+ ## Opening the Modal
129
+
130
+ Use the `useTrustModal` hook to control the connection modal:
131
+
132
+ ```tsx
133
+ import { useTrustModal } from '@trustwallet/connect-react'
134
+
135
+ function ConnectButton() {
136
+ const { open } = useTrustModal()
137
+
138
+ return (
139
+ <>
140
+ {/* Open wallet selection */}
141
+ <button onClick={() => open()}>Connect Wallet</button>
142
+
143
+ {/* Prompt the user to connect to a specific namespace */}
144
+ <button onClick={() => open({ type: 'namespace', namespaceId: 'eip155' })}>
145
+ Connect EVM Wallet
146
+ </button>
147
+ </>
148
+ )
149
+ }
150
+ ```
151
+
152
+ ---
153
+
154
+ ## Reading Connection State
155
+
156
+ Use `useConnections` for all namespaces, and `useConnection` for a single namespace:
157
+
158
+ ```tsx
159
+ import { useConnection, useConnections } from '@trustwallet/connect-react'
160
+ import type { NamespaceId } from '@trustwallet/connect-react'
161
+
162
+ function WalletInfo() {
163
+ // Get all connections
164
+ const { connections } = useConnections()
165
+
166
+ // Get specific namespace connection with type inference
167
+ const { isConnected, address, wallet, chain, status } = useConnection({
168
+ namespaceId: 'eip155'
169
+ })
170
+
171
+ if (!isConnected) return <p>Not connected</p>
172
+
173
+ return (
174
+ <div>
175
+ <p>Wallet: {wallet?.name}</p>
176
+ <p>Address: {address}</p>
177
+ <p>Chain: {chain?.reference}</p>
178
+ <p>Status: {status}</p>
179
+ </div>
180
+ )
181
+ }
182
+ ```
183
+
184
+ ---
185
+
186
+ ## EIP-155 (EVM) Actions
187
+
188
+ The EIP-155 React package provides hooks for interacting with EVM chains using Viem actions.
189
+
190
+ ### Read Operations (Queries)
191
+
192
+ Use `useEIP155Query` for read-only operations:
193
+
194
+ ```tsx
195
+ import { useEIP155Query } from '@trustwallet/connect-eip155-react'
196
+ import { getBalance } from 'viem/actions'
197
+ import { mainnet } from 'viem/chains'
198
+ import { useConnection } from '@trustwallet/connect-react'
199
+
200
+ function Balance() {
201
+ const { address } = useConnection({ namespaceId: 'eip155' })
202
+
203
+ const { data } = useEIP155Query({
204
+ chain: mainnet,
205
+ action: getBalance,
206
+ request: { address },
207
+ })
208
+
209
+ return <p>Balance: {data?.toString()}</p>
210
+ }
211
+ ```
212
+
213
+ ### Write Operations (Mutations)
214
+
215
+ Use `useSignMessage` for a simple message flow, `useWriteContract` for contract writes, `useSendTransaction` for transfers, and `useEIP155Mutation` for other Viem actions:
216
+
217
+ **NOTE:** `useWriteContract` and `useSendTransaction` will handle internally chain switching (if the user is not connected in the target chain ID) and [`waitForTransactionReceipt`](https://viem.sh/docs/actions/public/waitForTransactionReceipt).
218
+ You can disable `switchChain` by setting `autoSwitchChain` to `false`.
219
+
220
+ ```tsx
221
+ import { useSignMessage, useWriteContract, useSendTransaction, useEIP155Mutation } from '@trustwallet/connect-eip155-react'
222
+ import { switchChain } from 'viem/actions'
223
+ import { mainnet } from 'viem/chains'
224
+ import { parseEther } from 'viem'
225
+ import { useConnection } from '@trustwallet/connect-react'
226
+
227
+ // Sign messages
228
+ function SignMessage() {
229
+ const { isConnected } = useConnection({ namespaceId: 'eip155' })
230
+ const { mutate: sign, data, isPending, isSuccess, isError, error } = useSignMessage()
231
+
232
+ return (
233
+ <div>
234
+ <button onClick={() => sign({ message: 'Hello World' })} disabled={!isConnected || isPending}>
235
+ Sign Message
236
+ </button>
237
+ {isPending && <p>Signing...</p>}
238
+ {isSuccess && <p>Signature: {data}</p>}
239
+ {isError && <p>Error: {error?.message}</p>}
240
+ </div>
241
+ )
242
+ }
243
+
244
+ // Write contracts and wait for confirmation
245
+ function WriteContract() {
246
+ const { mutate, hash, receipt, isLoading, isConfirming, isConfirmed } = useWriteContract()
247
+
248
+ const handleWrite = () => {
249
+ mutate({
250
+ chain: mainnet,
251
+ address: '0x...',
252
+ abi: [...],
253
+ functionName: 'transfer',
254
+ args: ['0x...', parseEther('0.01')],
255
+ })
256
+ }
257
+
258
+ return (
259
+ <div>
260
+ <button onClick={handleWrite} disabled={isLoading}>
261
+ {isLoading ? 'Sending...' : 'Send'}
262
+ </button>
263
+ {hash && <p>Hash: {hash}</p>}
264
+ {isConfirming && <p>Waiting for confirmation...</p>}
265
+ {isConfirmed && receipt && <p>Confirmed in block {receipt.blockNumber}</p>}
266
+ </div>
267
+ )
268
+ }
269
+
270
+ // Send transactions
271
+ function SendTransaction() {
272
+ const { mutateAsync, isPending, hash, receipt, isConfirming, isConfirmed } = useSendTransaction()
273
+
274
+ const handleSend = async () => {
275
+ try {
276
+ await mutateAsync({
277
+ chain: mainnet,
278
+ to: '0x...',
279
+ value: parseEther('0.01'),
280
+ })
281
+ } catch (error) {
282
+ console.error('Failed:', error)
283
+ }
284
+ }
285
+
286
+ return (
287
+ <div>
288
+ <button onClick={handleSend} disabled={isPending}>
289
+ {isPending ? 'Sending...' : 'Send 0.01 ETH'}
290
+ </button>
291
+ {hash && <p>Hash: {hash}</p>}
292
+ {isConfirming && <p>Waiting for confirmation...</p>}
293
+ {isConfirmed && receipt && <p>Confirmed in block {receipt.blockNumber}</p>}
294
+ </div>
295
+ )
296
+ }
297
+
298
+ // Custom Viem actions
299
+ function CustomAction() {
300
+ const { mutateAsync, isPending } = useEIP155Mutation({
301
+ chain: mainnet,
302
+ action: switchChain,
303
+ })
304
+
305
+ return (
306
+ <button onClick={() => mutateAsync({ id: mainnet.id })} disabled={isPending}>
307
+ {isPending ? 'Switching...' : 'Switch Chain'}
308
+ </button>
309
+ )
310
+ }
311
+ ```
312
+
313
+ ---
314
+
315
+ **Note**: For Solana and Bitcoin there is a lot of work to be done, at the moment
316
+ we simply wrap wallet features into React Query hooks.
317
+
318
+ ## Solana Actions
319
+
320
+ The Solana React package provides hooks for Solana wallet interactions.
321
+
322
+ ### Sign Messages
323
+
324
+ ```tsx
325
+ import { useSignMessage } from '@trustwallet/connect-solana-react'
326
+ import { useConnection } from '@trustwallet/connect-react'
327
+ import bs58 from 'bs58'
328
+
329
+ function SolanaSignMessage() {
330
+ const { isConnected } = useConnection({ namespaceId: 'solana' })
331
+ const { mutate, data, isPending, isSuccess, error } = useSignMessage()
332
+
333
+ const handleSign = () => {
334
+ if (!isConnected) return
335
+ mutate({ message: 'Hello Solana!' })
336
+ }
337
+
338
+ // Signature is returned as Uint8Array
339
+ const signatureBase58 = data ? bs58.encode(data.signature) : null
340
+
341
+ return (
342
+ <div>
343
+ <button onClick={handleSign} disabled={isPending || !isConnected}>
344
+ {isPending ? 'Signing...' : 'Sign Message'}
345
+ </button>
346
+ {isSuccess && signatureBase58 && (
347
+ <div>
348
+ <p>Message signed successfully!</p>
349
+ <code>{signatureBase58}</code>
350
+ </div>
351
+ )}
352
+ {error && <p>Error: {error.message}</p>}
353
+ </div>
354
+ )
355
+ }
356
+ ```
357
+
358
+ ### Send Transactions
359
+
360
+ ```tsx
361
+ import { useSignSendTransaction } from '@trustwallet/connect-solana-react'
362
+ import { Transaction, SystemProgram, PublicKey } from '@solana/web3.js'
363
+
364
+ function SolanaSendTransaction() {
365
+ const { mutateAsync, isPending } = useSignSendTransaction()
366
+
367
+ const handleSend = async () => {
368
+ try {
369
+ // Create transaction
370
+ const tx = new Transaction().add(
371
+ SystemProgram.transfer({
372
+ fromPubkey: new PublicKey('...'),
373
+ toPubkey: new PublicKey('...'),
374
+ lamports: 1000000, // 0.001 SOL
375
+ })
376
+ )
377
+
378
+ // Serialize and send
379
+ const serialized = tx.serialize({ requireAllSignatures: false })
380
+ const result = await mutateAsync({
381
+ transaction: serialized,
382
+ options: {
383
+ skipPreflight: false,
384
+ preflightCommitment: 'confirmed',
385
+ },
386
+ })
387
+
388
+ console.log('Transaction signature:', result.signature)
389
+ } catch (error) {
390
+ console.error('Transaction failed:', error)
391
+ }
392
+ }
393
+
394
+ return (
395
+ <button onClick={handleSend} disabled={isPending}>
396
+ {isPending ? 'Sending...' : 'Send SOL'}
397
+ </button>
398
+ )
399
+ }
400
+ ```
401
+
402
+ ---
403
+
404
+ ## Bitcoin (BIP-122) Actions
405
+
406
+ The Bitcoin React package provides hooks for Bitcoin wallet interactions.
407
+
408
+ ### Sign Messages
409
+
410
+ ```tsx
411
+ import { useSignMessage, mainnet } from '@trustwallet/connect-bip122-react'
412
+ import { useConnection } from '@trustwallet/connect-react'
413
+
414
+ function BitcoinSignMessage() {
415
+ const { isConnected } = useConnection({ namespaceId: 'bip122' })
416
+
417
+ const {
418
+ mutate: sign,
419
+ data: signature,
420
+ isPending,
421
+ isSuccess,
422
+ error,
423
+ } = useSignMessage({
424
+ chain: mainnet,
425
+ })
426
+
427
+ const handleSign = () => {
428
+ if (!isConnected) return
429
+ sign({
430
+ message: 'Hello from TrustConnect SDK!',
431
+ protocol: 'ecdsa', // or 'bip322'
432
+ })
433
+ }
434
+
435
+ return (
436
+ <div>
437
+ <button onClick={handleSign} disabled={isPending || !isConnected}>
438
+ {isPending ? 'Signing...' : 'Sign Message'}
439
+ </button>
440
+ {isSuccess && signature && (
441
+ <div>
442
+ <p>Message signed!</p>
443
+ <code>{signature.signature}</code>
444
+ </div>
445
+ )}
446
+ {error && <p>Error: {error.message}</p>}
447
+ </div>
448
+ )
449
+ }
450
+ ```
451
+
452
+ ### Sign and Send PSBTs
453
+
454
+ ```tsx
455
+ import { useSignPsbt, useSendTransfer, mainnet } from '@trustwallet/connect-bip122-react'
456
+
457
+ function BitcoinTransaction() {
458
+ // Sign PSBT (Partially Signed Bitcoin Transaction)
459
+ const { mutate: signPsbt, isPending: isSigning } = useSignPsbt({
460
+ chain: mainnet
461
+ })
462
+
463
+ // Send transfer
464
+ const { mutateAsync: sendTransfer, isPending: isSending } = useSendTransfer({
465
+ chain: mainnet
466
+ })
467
+
468
+ const handleSignPsbt = () => {
469
+ signPsbt({
470
+ psbt: 'cHNidP8BA...', // Base64 encoded PSBT
471
+ signInputs: [
472
+ { index: 0, sighashTypes: [1] }
473
+ ],
474
+ broadcast: false, // Don't broadcast after signing
475
+ })
476
+ }
477
+
478
+ const handleTransfer = async () => {
479
+ try {
480
+ const result = await sendTransfer({
481
+ recipient: 'bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh',
482
+ amount: '10000', // satoshis
483
+ memo: 'Payment for services',
484
+ })
485
+ console.log('Transaction ID:', result.txid)
486
+ } catch (error) {
487
+ console.error('Transfer failed:', error)
488
+ }
489
+ }
490
+
491
+ return (
492
+ <div>
493
+ <button onClick={handleSignPsbt} disabled={isSigning}>
494
+ {isSigning ? 'Signing...' : 'Sign PSBT'}
495
+ </button>
496
+ <button onClick={handleTransfer} disabled={isSending}>
497
+ {isSending ? 'Sending...' : 'Send BTC'}
498
+ </button>
499
+ </div>
500
+ )
501
+ }
502
+ ```
503
+
504
+ ---
505
+
506
+ ## Theme Customization
507
+
508
+ Set the initial theme via the provider (see [Configuration Options](#configuration-options)), or toggle it programmatically:
509
+
510
+ ```tsx
511
+ import { useTheme } from '@trustwallet/connect-react'
512
+
513
+ function ThemeToggle() {
514
+ const { theme, resolvedTheme, setTheme, toggleTheme } = useTheme()
515
+
516
+ return (
517
+ <div>
518
+ <p>Current: {resolvedTheme}</p>
519
+ <button onClick={toggleTheme}>Toggle</button>
520
+ <button onClick={() => setTheme('dark')}>Dark</button>
521
+ <button onClick={() => setTheme('light')}>Light</button>
522
+ <button onClick={() => setTheme('auto')}>Auto</button>
523
+ </div>
524
+ )
525
+ }
526
+ ```
527
+
528
+ ---
529
+
530
+ ## Full Control of UI Styles
531
+
532
+ If you want full control of the UI styles, copy the TrustConnect UI components into your app and edit them directly:
533
+
534
+ ```bash
535
+ npx @trustwallet/connect-ui add
536
+ ```
537
+
538
+ You can also choose a custom path:
539
+
540
+ ```bash
541
+ npx @trustwallet/connect-ui add --path ./src/components/trust
542
+ ```
543
+
544
+ This downloads the components and their styles so you can customize everything locally.
545
+
546
+ You can now delete `@trustwallet/connect-react` and import `TrustConnectProvider` and other **TrustConnect**
547
+ hooks directly from your TrustConnect components folder.
548
+
549
+ ## Complete Example
550
+
551
+ See the [playground](./playground) for a complete working example with all features.
552
+
553
+ Run the playground:
554
+
555
+ ```sh
556
+ pnpm install
557
+ pnpm run build
558
+ pnpm run dev:all
559
+ ```
560
+
561
+ ---
562
+
563
+ ## License
564
+
565
+ Copyright 2026 Trust Wallet
566
+
567
+ Licensed under the Apache License, Version 2.0. See the [LICENSE](./LICENSE) file for details.