Skip to content

Commit

Permalink
add wagmi documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
avkos committed Feb 15, 2024
1 parent d8b64a8 commit 718b2cc
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
5 changes: 5 additions & 0 deletions docs/docs/guides/wagmi_usage/_category_.yml
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
51 changes: 51 additions & 0 deletions docs/docs/guides/wagmi_usage/wagmi.md
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)
:::

1 comment on commit 718b2cc

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: 718b2cc Previous: 6c075db Ratio
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.

Please sign in to comment.