You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/react/README.md
+88-1Lines changed: 88 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ A collection of React hooks for implementing web3-onboard in to a React project
6
6
7
7
`npm i @web3-onboard/react`
8
8
9
-
## Usage
9
+
## Example Usage
10
10
11
11
```javascript
12
12
importReactfrom'react'
@@ -142,3 +142,90 @@ function App() {
142
142
143
143
exportdefaultApp
144
144
```
145
+
146
+
## `init`
147
+
148
+
The `init` function must be called before any hooks can be used. The `init` function just initializes `web3-onboard` and makes it available for all hooks to use. For reference check out the [initialization docs for `@web3-onboard/core`](../core/README.md#initialization)
149
+
150
+
## `useConnectWallet`
151
+
152
+
This hook allows you to connect the user's wallet and track the state of the connection status and the wallet that is connected.
autoSelect?:string// wallet name to autoselect for user
164
+
}
165
+
166
+
typeWalletState= {
167
+
label:string
168
+
icon:string
169
+
provider:EIP1193Provider
170
+
accounts:Account[]
171
+
chains:ConnectedChain[]
172
+
instance?:unknown
173
+
}
174
+
175
+
const [
176
+
{
177
+
wallet, // the wallet that has been connected or null if not yet connected
178
+
connecting // boolean indicating if connection is in progress
179
+
},
180
+
connect // function to call to initiate user to connect wallet
181
+
] =useConnectWallet()
182
+
```
183
+
184
+
## `useSetChain`
185
+
186
+
This hook allows you to set the chain of a user's connected wallet, keep track of the current chain the user is connected to and the status of setting the chain.
187
+
188
+
```typescript
189
+
import { useSetChain } from'@web3-onboard/react'
190
+
191
+
typeUseSetChain= (
192
+
walletLabel?:string
193
+
): [
194
+
{
195
+
chains:Chain[]
196
+
connectedChain:ConnectedChain|null
197
+
settingChain:boolean
198
+
},
199
+
(options:SetChainOptions) =>Promise<void>
200
+
]
201
+
202
+
typeSetChainOptions= {
203
+
chainId:string
204
+
chainNamespace?:string
205
+
wallet?:WalletState['label']
206
+
}
207
+
208
+
const [
209
+
{
210
+
chains, // the list of chains that web3-onboard was initialized with
211
+
connectedChain, // the current chain the user's wallet is connected to
212
+
settingChain // boolean indicating if the chain is in the process of being set
213
+
},
214
+
setChain // function to call to initiate user to switch chains in their wallet
215
+
] =useSetChain()
216
+
```
217
+
218
+
## `useWallets`
219
+
220
+
This hook allows you to track the state of all the currently connected wallets.
221
+
222
+
```typescript
223
+
import { useWallets } from'@web3-onboard/react'
224
+
225
+
typeUseWallets= ():WalletState[]
226
+
227
+
const [
228
+
wallets, //
229
+
setChain // function to call to initiate user to switch chains in their wallet
0 commit comments