-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
label: '🔄 Wagmi usage' | ||
collapsible: true | ||
collapsed: true | ||
link: null | ||
position: 11 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
--- | ||
sidebar_position: 1 | ||
sidebar_label: 'Wagmi Web3js Adaptor' | ||
title: 'Wagmi Web3js Adaptor' | ||
--- | ||
|
||
If you're using [Wagmi](https://wagmi.sh/react/getting-started#use-wagmi) and want to add web3.js, use this provider in your project: | ||
|
||
|
||
```typescript | ||
import {Web3} from 'web3' | ||
import {useMemo} from 'react' | ||
import type {Chain, Client, Transport} from 'viem' | ||
import {type Config, useClient} from 'wagmi' | ||
|
||
export function clientToWeb3js(client?: Client<Transport, Chain>) { | ||
if (!client) { | ||
return new Web3() | ||
} | ||
|
||
const {transport} = client | ||
|
||
if (transport.type === 'fallback') { | ||
return new Web3(transport.transports[0].value.url) | ||
} | ||
|
||
return new Web3(transport.url) | ||
} | ||
|
||
/** Action to convert a viem Client to a web3.js Instance. */ | ||
export function useWeb3js({chainId}: { chainId?: number } = {}) { | ||
const client = useClient<Config>({chainId}) | ||
return useMemo(() => clientToWeb3js(client), [client]) | ||
} | ||
|
||
``` | ||
|
||
Usage example: | ||
|
||
```typescript | ||
import {useWeb3js} from '../web3/useWeb3js' | ||
import {mainnet} from 'wagmi/chains' // for example for mainnet | ||
// somewhere in your React render method | ||
const web3js = useWeb3js({chainId: mainnet.id}) | ||
// ... | ||
``` | ||
|
||
|
||
:::tip | ||
To learn about Wagmi and how to set up a Wagmi project, please follow this [link](https://wagmi.sh/react/getting-started#use-wagmi) | ||
::: |
718b2cc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Benchmark
processingTx
9561
ops/sec (±4.07%
)9301
ops/sec (±4.81%
)0.97
processingContractDeploy
38517
ops/sec (±8.36%
)39129
ops/sec (±7.62%
)1.02
processingContractMethodSend
19426
ops/sec (±7.16%
)19443
ops/sec (±5.19%
)1.00
processingContractMethodCall
38922
ops/sec (±6.44%
)38971
ops/sec (±6.34%
)1.00
abiEncode
46523
ops/sec (±7.09%
)44252
ops/sec (±6.92%
)0.95
abiDecode
31112
ops/sec (±8.77%
)30419
ops/sec (±8.89%
)0.98
sign
1606
ops/sec (±3.39%
)1656
ops/sec (±4.08%
)1.03
verify
383
ops/sec (±0.53%
)373
ops/sec (±0.78%
)0.97
This comment was automatically generated by workflow using github-action-benchmark.