Skip to content

Commit 60775cc

Browse files
committed
Update wagmi docs
1 parent 7ee9a03 commit 60775cc

File tree

5 files changed

+166
-140
lines changed

5 files changed

+166
-140
lines changed

docs/src/routes/docs/[...3]modules/[...1]core/+page.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ type InitOptions {
108108
wallets: WalletInit[]
109109
chains: Chain[]
110110
appMetadata?: AppMetadata
111+
/** Web3-Onboard module to add Wagmi support
112+
* see https://www.npmjs.com/package/@web3-onboard/wagmi
113+
*/
114+
wagmi?: typeof wagmi
111115
i18n?: i18nOptions
112116
accountCenter?: AccountCenterOptions
113117
apiKey?: string
@@ -388,6 +392,57 @@ It will allow you to customize the look and feel of Web3 Onboard, try different
388392
389393
---
390394
395+
#### wagmi
396+
397+
To add [WAGMI API](https://wagmi.sh/core/getting-started) support to your project you can simply install `web3-onboard/wagmi` import and pass in the [wagmi package](/docs/modules/wagmi) export directly into your onboard configuration. After doing so you can use all of the native WAGMI API functions directly from `@web3-onboard/wagmi`. This will give access to all WAGMI function available on or before `@wagmi/core` version `2.10.4`.
398+
After initialization an up-to-date WAGMI config will will be available from the onboard state object `onboard.state.get().wagmiConfig` which will need to be passed as the first prop of most [@wagmi/core](https://wagmi.sh/core/getting-started) methods. Wallets will also have a [wagmiConnector](#state) prop within the onboard state object which will allow you to target specific wallets for interactions. This can also be bi-passed if the primary or most recently connected wallet is the wallet meant for the transactions.
399+
The config and connectors can be used with the WAGMI API returned from this module or an external WAGMI instance.
400+
401+
Full documentation for the `@web3-onboard/wagmi` module can be found [here](/docs/modules/wagmi).
402+
403+
```typescript
404+
import Onboard from '@web3-onboard/core'
405+
import wagmi from '@web3-onboard/wagmi'
406+
import {
407+
sendTransaction as wagmiSendTransaction,
408+
switchChain,
409+
disconnect,
410+
getConnectors
411+
} from '@web3-onboard/wagmi'
412+
413+
const injected = injectedModule()
414+
415+
const onboard = Onboard({
416+
// This javascript object is unordered meaning props do not require a certain order
417+
wagmi,
418+
wallets: [injected],
419+
chains: [
420+
{
421+
id: '0x1',
422+
token: 'ETH',
423+
label: 'Ethereum',
424+
rpcUrl: 'https://mainnet.infura.io/v3/17c1e1500e384acfb6a72c5d2e67742e'
425+
}
426+
]
427+
// ... other Onboard options
428+
})
429+
430+
const sendTransaction = async () => {
431+
// current primary wallet - as multiple wallets can connect this value is the currently active
432+
const [activeWallet] = onboard.state.get().wallets
433+
const { wagmiConnector } = activeWallet
434+
const wagmiConfig = onboard.state.get().wagmiConfig
435+
const result = await wagmiSendTransaction(wagmiConfig, {
436+
to: toAddress,
437+
// desired connector to send txn from
438+
connector: wagmiConnector,
439+
value: parseEther('0.001')
440+
})
441+
console.log(result)
442+
}
443+
```
444+
---
445+
391446
#### disableFontDownload
392447

393448
If set to `true` the default `Inter` font will not be imported and instead the web based `sans-serif` font will be used if a font is not defined through the `Theme` or exposed css variable.

docs/src/routes/docs/[...3]modules/[...3]react/+page.md

Lines changed: 64 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,11 @@ function MyApp({ Component, pageProps }) {
137137
export default MyApp
138138
```
139139

140-
## `init`
140+
## init
141141

142142
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`](../../modules/core.md#initialization)
143143

144-
## `useConnectWallet`
144+
## useConnectWallet
145145

146146
This hook allows you to connect the user's wallet and track the state of the connection status and the wallet that is connected.
147147

@@ -203,7 +203,7 @@ setPrimaryWallet(wallets[1])
203203
setPrimaryWallet(wallets[1], wallets[1].accounts[2].address)
204204
```
205205

206-
## `useSetChain`
206+
## useSetChain
207207

208208
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. Passing in a wallet label will operate on that connected wallet, otherwise it will default to the last connected wallet. If a chain was instantiated without an rpcUrl, token, or label, add these options for wallets that require this information for adding a new chain.
209209

@@ -243,7 +243,64 @@ const [
243243
] = useSetChain()
244244
```
245245

246-
## `useNotifications`
246+
## useWagmiConfig
247+
248+
This hook allows you to get the WagmiConfig (Config from the Wagmi project) from @web3-onboard/core if W3O has been initialized with the [WAGMI property imported and passing into the web3-onboard/core config](../../modules/wagmi.md#usage).
249+
250+
```ts
251+
import Onboard from '@web3-onboard/core'
252+
import injectedModule from '@web3-onboard/injected-wallets'
253+
import wagmi from '@web3-onboard/wagmi'
254+
import {
255+
sendTransaction as wagmiSendTransaction,
256+
switchChain,
257+
disconnect,
258+
getConnectors
259+
} from '@web3-onboard/wagmi'
260+
import { parseEther, isHex, fromHex } from 'viem'
261+
262+
const injected = injectedModule()
263+
264+
const onboard = Onboard({
265+
wagmi,
266+
wallets: [injected],
267+
chains: [
268+
{
269+
id: '0x1',
270+
token: 'ETH',
271+
label: 'Ethereum',
272+
rpcUrl: 'https://mainnet.infura.io/v3/17c1e1500e384acfb6a72c5d2e67742e'
273+
}
274+
]
275+
// ... other Onboard options
276+
})
277+
278+
const sendTransaction = async () => {
279+
// current primary wallet - as multiple wallets can connect this value is the currently active
280+
const [activeWallet] = onboard.state.get().wallets
281+
const { wagmiConnector } = activeWallet
282+
const wagmiConfig = onboard.state.get().wagmiConfig
283+
const result = await wagmiSendTransaction(wagmiConfig, {
284+
to: toAddress,
285+
// desired connector to send txn from
286+
connector: wagmiConnector,
287+
value: parseEther('0.001')
288+
})
289+
console.log(result)
290+
}
291+
292+
async function signMessage(chainId) {
293+
// current primary wallet - as multiple wallets can connect this value is the currently active
294+
const [activeWallet] = onboard.state.get().wallets
295+
const wagmiConfig = onboard.state.get().wagmiConfig
296+
await wagmiSignMessage(wagmiConfig, {
297+
message: 'This is my message to you',
298+
connector: activeWallet.wagmiConnector
299+
})
300+
}
301+
```
302+
303+
## useNotifications
247304

248305
This hook allows the dev to access all notifications if enabled, send custom notifications, and update notify <enable/disable & update transactionHandler function>
249306
**note** This requires an API key be added to the initialization, enabled by default if an API key exists
@@ -410,7 +467,7 @@ const sendTransactionWithPreFlightNotifications = async () => {
410467
</button>
411468
```
412469

413-
## `useWallets`
470+
## useWallets
414471

415472
This hook allows you to track the state of all the currently connected wallets:
416473

@@ -422,7 +479,7 @@ type UseWallets = (): WalletState[]
422479
const connectedWallets = useWallets()
423480
```
424481

425-
## `useAccountCenter`
482+
## useAccountCenter
426483

427484
This hook allows you to track and update the state of the Account Center:
428485

@@ -449,7 +506,7 @@ type AccountCenter = {
449506
const updateAccountCenter = useAccountCenter()
450507
```
451508

452-
## `useSetLocale`
509+
## useSetLocale
453510

454511
This hook allows you to set the locale of your application to allow language updates associated with the i18n config:
455512

@@ -725,60 +782,3 @@ export default {
725782
}
726783
}
727784
```
728-
729-
## `useWagmiConfig`
730-
731-
This hook allows you to get the WagmiConfig (Config from the Wagmi project) from @web3-onboard/core if W3O has been initialized with the [WAGMI property imported and passing into the web3-onboard/core config](../../modules/wagmi.md#usage).
732-
733-
```ts
734-
import Onboard from '@web3-onboard/core'
735-
import injectedModule from '@web3-onboard/injected-wallets'
736-
import wagmi from '@web3-onboard/wagmi'
737-
import {
738-
sendTransaction as wagmiSendTransaction,
739-
switchChain,
740-
disconnect,
741-
getConnectors
742-
} from '@web3-onboard/wagmi'
743-
import { parseEther, isHex, fromHex } from 'viem'
744-
745-
const injected = injectedModule()
746-
747-
const onboard = Onboard({
748-
wagmi,
749-
wallets: [injected],
750-
chains: [
751-
{
752-
id: '0x1',
753-
token: 'ETH',
754-
label: 'Ethereum',
755-
rpcUrl: 'https://mainnet.infura.io/v3/17c1e1500e384acfb6a72c5d2e67742e'
756-
}
757-
]
758-
// ... other Onboard options
759-
})
760-
761-
const sendTransaction = async () => {
762-
// current primary wallet - as multiple wallets can connect this value is the currently active
763-
const [activeWallet] = onboard.state.get().wallets
764-
const { wagmiConnector } = activeWallet
765-
const wagmiConfig = onboard.state.get().wagmiConfig
766-
const result = await wagmiSendTransaction(wagmiConfig, {
767-
to: toAddress,
768-
// desired connector to send txn from
769-
connector: wagmiConnector,
770-
value: parseEther('0.001')
771-
})
772-
console.log(result)
773-
}
774-
775-
async function signMessage(chainId) {
776-
// current primary wallet - as multiple wallets can connect this value is the currently active
777-
const [activeWallet] = onboard.state.get().wallets
778-
const wagmiConfig = onboard.state.get().wagmiConfig
779-
await wagmiSignMessage(wagmiConfig, {
780-
message: 'This is my message to you',
781-
connector: activeWallet.wagmiConnector
782-
})
783-
}
784-
```

docs/src/routes/docs/[...3]modules/[...8]wagmi/+page.md

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: wagmi
2+
title: WAGMI
33
---
44

55
# {$frontmatter.title}
@@ -25,15 +25,24 @@ npm install @web3-onboard/wagmi
2525
</TabPanel>
2626
</Tabs>
2727

28-
## Usage
28+
## WAGMI Usage
2929

30-
This example assumes you have already setup web3-onboard to connect wallets to your dapp.
31-
For more information see [web3-onboard docs](https://onboard.blocknative.com/docs/modules/core#install).
30+
To add [WAGMI API](https://wagmi.sh/core/getting-started) support to your project you can simply install `web3-onboard/wagmi` import and pass in the WAGMI package default export directly into your onboard configuration. After doing so you can use all of the native WAGMI API functions directly from `@web3-onboard/wagmi`. This will give access to all WAGMI function available on or before `@wagmi/core` version `2.10.4`.
31+
32+
Full documentation for `wagmi/core` API functions can be found [here](https://wagmi.sh/core/getting-started).
33+
34+
### wagmiConfig
3235

33-
### `wagmiConnector` and Connectors
36+
After initialization an up-to-date WAGMI config will will be available from the onboard state object `onboard.state.get().wagmiConfig` which will need to be passed as the first prop of most [@wagmi/core](https://wagmi.sh/core/getting-started) methods.
3437

35-
`wagmiConnector` is a property returned as part of the wallet state object and can be used to interact with
36-
the WAGMI API returned from this module or an external WAGMI instance. Please see examples below...
38+
### wagmiConnector and Connectors
39+
Wallets will also have a `wagmiConnector` prop within the onboard state object which will allow you to target specific wallets for interactions. This can also be bi-passed if the primary or most recently connected wallet is the wallet meant for the transactions.
40+
The config and connectors can be used with the WAGMI API returned from this module or an external WAGMI instance.
41+
42+
## WAGMI Example
43+
44+
This example assumes you have already setup web3-onboard to connect wallets to your dapp.
45+
For more information see [web3-onboard docs](https://onboard.blocknative.com/docs/modules/core#install).
3746

3847
```ts
3948
import Onboard from '@web3-onboard/core'

0 commit comments

Comments
 (0)