Skip to content

Commit

Permalink
v1 (#2235)
Browse files Browse the repository at this point in the history
* wip: initial

* feat: migrate fetchBalance

* feat: migrate signMessage

* wip: remove wrapped user rejected request error

* wip: readContract

* wip: multicall

* wip: readContracts

* wip: unskip fetchBalance tests

* wip: waitForTransaction

* wip: fetchToken

* wip: signTypedData

* wip: fetchEnsAddress

* wip: fetchEnsName

* fix: multicall merge

* wip: fetchBlockNumber

* wip: fetchFeeData

* wip: fetchTransaction

* wip: fixes

* wip: watchBlockNumber

* wip: remove console.log

* wip: watchPendingTransactions

* wip: add  to watch actions

* wip: amend notes

* wip: prepareWriteContract

* wip: writeContract

* wip: update watchProvider, watchWebSocketProvider tests

* wip: prepareSendTransaction

* wip: sendTransaction

* wip: unskip tests

* wip: watchContractEvent

* wip: watchMulticall

* wip: watchReadContracts

* wip: assertActiveChain test

* wip: useProvider, useWebSocketProvider

* wip: useSigner tests

* wip: useEnsName tests

* wip: use eip1193 provider for signer

* wip: useBlockNumber

* wip: useFeeData

* wip: useWaitForTransaction

* wip: usePrepareSendTransaction

* wip: update types

* wip: getContract

* wip: fetchEnsAvatar, fetchEnsResolver

* wip: update tests

* wip: useEnsAvatar

* wip: useSendTransaction

* useWatchPendingTransactions

* wip: usePrepareContractWrite

* wip: useContractWrite

* wip: useSignTypedData

* wip: remove useContract + other contract refactors

* wip: useContractEvent

* wip: useContractRead

* wip: useContractReads

* lint

* wip: update tests

* wip: useContractReads type

* wip: useContractInfiniteReads

* wip: useContractInfiniteReads types

* wip: remove useContract from cli

* wip: remove parseContractResult

* wip: remove normalizeFunctionName

* wip: remove unused utils

* wip: update examples

* wip: example

* wip: notes

* wip: update notes

* wip: update viem

* wip: update tests

* wip: update deps

* wip: update references

* wip: remove signer generics

* wip: update references

* wip: migrate configureChains

* wip: remove more ethers

* wip: update sign message example

* wip: remove ethers

* wip: misc changes

* tests: update

* refactor: cli updates for viem

* chore: remove ethers dep

* chore: format

* wip: omit chain check

* docs: remove ethers

* wip: remove @wagmi/core as dependency for connectors

* wip: remove more redundant types/modules

* wip: update tests

* wip: make build happy

* trigger

* wip: lock nextra version

* wip: update lockfile

* wip: update watchPendingTransactions

* wip: update lockfile

* wip: update viem

* wip: update references

* wip: update references

* wip: set storage in connectors

* wip: update notes

* wip: update

* wip: update node version

* wip: update anvil block number

* wip: update

* wip: fix allowFailure type

* wip: update notes

* wip: update configureChains

* wip: fix types

* wip: add gas estimation to prepareSendTransaction

* wip - docs: migrate a bunch of hooks & actions

* wip: remove ethers references

* wip: update snapshots

* wip: more docs migration

* wip: fix

* wip: update viem

* wip: update viem

* wip: update pnpm

* wip: migrate to publicClient + walletClient terminology

* wip: update

* docs: client

* docs: client

* docs: getting started

* docs: core actions

* wip: more docs

* wip: remove prepared requirement for sendTransaction

* wip: drop prepared requirement on useContractWrite

* docs: more docs

* docs: update

* docs: update

* wip: update docs

* wip: update example

* wip: update viem

* wip: export types

* update testbench

* docs: start migration guide

* wip: migration guide

* wip: add window types entrypoint

* wip: add window entrypoint

* wip: update migration guide

* docs: add multicall to migration guide

* docs: add useContractReads/readContracts

* docs: useContractInfiniteReads migration

* docs: usePrepareContractWrite/prepareWriteContract migration

* docs: useContractRead/readContract migration

* docs: signMessage/signTypedData migration

* docs: waitForTransaction/useWaitForTransaction migration

* docs: watchPendingTransactions/useWatchPendingTransactions migration

* wip: add `unwatch` to useContractEvent

* docs: useContractWrite/writeContract migration

* docs: useContractEvent/watchContractEvent migration

* docs: update migration guide

* docs: update

* docs: connector migration

* wip: errors migration

* wip: fix send transaction

* wip: update tests

* wip: update viem

* wip: update send txn

* docs: connect

* docs: balance and block number

* docs: ens name

* docs: wip

* docs: token

* docs: transaction

* docs: contract

* docs: provider

* docs: signer

* chore: prerelease mode

* chore: version packages

* update lockfile

* docs: wagmi@next

* chore: update viem

* chore: version

* refactor: client -> config

* refactor: remove `request` config on `sendTransaction` (now hoisted to root)

* chore: format

* chore: update package.json

* tests: update

* chore: version packages

* chore: update references

* chore: version packages

* chore: update viem

* chore: format

* refactor: remove goerli from main entrypoint

* chore: update references

* chore: version packages

* docs: add faq for bigint serialization

* feat: added methods to dynamically set viem clients

* chore: version packages

* feat: setConnectors

* chore: version packages

* chore: update references

* chore: update lockfile

* chore: update tests

* chore: version packages

* fix: cli react plugin generic

* chore: version packages

* feat: add 'use client' banner

* chore: version packages

* fix: useContractEvent deps

* chore: version packages

* docs: fix useWalletClient route

* chore: update viem

* chore: update abitype

* chore: update

* chore: format

* tests: update

* chore: update references

* chore: amend changeset

* docs: add callouts to migration guide

---------

Co-authored-by: Tom Meagher <[email protected]>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored May 9, 2023
1 parent ef0e302 commit 5be0655
Show file tree
Hide file tree
Showing 396 changed files with 14,913 additions and 14,330 deletions.
7 changes: 7 additions & 0 deletions .changeset/popular-onions-sip.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@wagmi/cli': major
'@wagmi/core': major
'wagmi': major
---

Released v1. Read [Migration Guide](https://next.wagmi.sh/react/migration-guide#1xx-breaking-changes).
16 changes: 16 additions & 0 deletions .changeset/pre.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"mode": "pre",
"tag": "next",
"initialVersions": {
"docs": "0.0.1",
"example-dev": "0.0.1",
"@wagmi/cli": "0.1.15",
"@wagmi/core": "0.10.9",
"wagmi": "0.12.10",
"@wagmi/chains": "0.2.18",
"@wagmi/connectors": "1.0.0-next.0"
},
"changesets": [
"popular-onions-sip"
]
}
9 changes: 8 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,14 @@
}
}
],
"ignorePatterns": ["CHANGELOG.md", "build", "dist", "node_modules", "**/*.config.js", "**/*.config.mjs"],
"ignorePatterns": [
"CHANGELOG.md",
"build",
"dist",
"node_modules",
"**/*.config.js",
"**/*.config.mjs"
],
"settings": {
"import/parsers": {
"@typescript-eslint/parser": [".ts", ".tsx", ".d.ts"]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ jobs:
needs: lint
runs-on: ubuntu-latest
env:
ANVIL_BLOCK_NUMBER: 15578840
ANVIL_BLOCK_NUMBER: 16773780
strategy:
matrix:
node-version: [19]
Expand Down
19 changes: 11 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,28 +60,31 @@ For full documentation and examples, visit [wagmi.sh](https://wagmi.sh).

## Installation

Install wagmi and its ethers peer dependency.
Install wagmi and its [viem](https://viem.sh) peer dependency.

```bash
npm install wagmi ethers@^5
npm install wagmi viem
```

## Quick Start

Connect a wallet in under 60 seconds. LFG.

```tsx
import { WagmiConfig, createClient } from 'wagmi'
import { getDefaultProvider } from 'ethers'
import { WagmiConfig, createConfig, mainnet } from 'wagmi'
import { createPublicClient, http } from 'viem'

const client = createClient({
const config = createConfig({
autoConnect: true,
provider: getDefaultProvider(),
publicClient: createPublicClient({
chain: mainnet,
transport: http(),
}),
})

function App() {
return (
<WagmiConfig client={client}>
<WagmiConfig config={config}>
<Profile />
</WagmiConfig>
)
Expand Down Expand Up @@ -110,7 +113,7 @@ function Profile() {
}
```

In this example, we create a wagmi `Client` and pass it to the `WagmiConfig` React Context. The client is set up to use the ethers Default Provider and automatically connect to previously connected wallets.
In this example, we create a wagmi `config` and pass it to the `WagmiConfig` React Context. The config is set up to use viem's Public Client and automatically connect to previously connected wallets.

Next, we use the `useConnect` hook to connect an injected wallet (e.g. MetaMask) to the app. Finally, we show the connected account's address with `useAccount` and allow them to disconnect with `useDisconnect`.

Expand Down
12 changes: 6 additions & 6 deletions docs/components/core/Providers.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react'

import { WagmiConfig, configureChains, createClient } from 'wagmi'
import { WagmiConfig, configureChains, createConfig } from 'wagmi'
import { goerli, mainnet } from 'wagmi/chains'

import { CoinbaseWalletConnector } from 'wagmi/connectors/coinbaseWallet'
Expand All @@ -10,12 +10,12 @@ import { WalletConnectConnector } from 'wagmi/connectors/walletConnect'

import { alchemyProvider } from 'wagmi/providers/alchemy'

const { chains, provider, webSocketProvider } = configureChains(
const { chains, publicClient, webSocketPublicClient } = configureChains(
[mainnet, goerli],
[alchemyProvider({ apiKey: process.env.NEXT_PUBLIC_ALCHEMY_ID! })],
)

const client = createClient({
const config = createConfig({
autoConnect: true,
connectors: [
new MetaMaskConnector({
Expand Down Expand Up @@ -44,14 +44,14 @@ const client = createClient({
},
}),
],
provider,
webSocketProvider,
publicClient,
webSocketPublicClient,
})

type Props = {
children?: React.ReactNode
}

export function Providers({ children }: Props) {
return <WagmiConfig client={client}>{children}</WagmiConfig>
return <WagmiConfig config={config}>{children}</WagmiConfig>
}
8 changes: 3 additions & 5 deletions docs/components/examples/SendTransaction.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Box, Button, Input, Stack, Text } from 'degen'
import { parseEther } from 'ethers/lib/utils'
import * as React from 'react'
import { parseEther } from 'viem'
import {
useAccount,
usePrepareSendTransaction,
Expand Down Expand Up @@ -40,10 +40,8 @@ export function SendTransaction() {
isError: isPrepareError,
isLoading: isPreparing,
} = usePrepareSendTransaction({
request: {
to: debouncedTo,
value: debouncedValue ? parseEther(debouncedValue) : undefined,
},
to: debouncedTo,
value: debouncedValue ? parseEther(debouncedValue) : undefined,
})
const { data, error, isLoading, isError, sendTransaction } =
useSendTransaction(config)
Expand Down
27 changes: 18 additions & 9 deletions docs/components/examples/SignMessage.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,35 @@
import { Box, Button, Text, Textarea } from 'degen'
import { verifyMessage } from 'ethers/lib/utils'
import * as React from 'react'
import { recoverMessageAddress } from 'viem'
import type { Address } from 'wagmi'
import { useAccount, useSignMessage } from 'wagmi'

import { PreviewWrapper } from '../core'
import { Account, WalletSelector } from '../web3'

export function SignMessage() {
const recoveredAddress = React.useRef<string>()
const [recoveredAddress, setRecoveredAddress] = React.useState<Address>()

const { isConnected } = useAccount()
const {
data: signMessageData,
variables,
error,
isLoading,
signMessage,
} = useSignMessage({
onSuccess(data, variables) {
const address = verifyMessage(variables.message, data)
recoveredAddress.current = address
},
})
} = useSignMessage()

React.useEffect(() => {
;(async () => {
if (variables?.message && signMessageData) {
const recoveredAddress = await recoverMessageAddress({
message: variables?.message,
signature: signMessageData,
})
setRecoveredAddress(recoveredAddress)
}
})()
}, [signMessageData, variables?.message])

if (isConnected)
return (
Expand Down Expand Up @@ -52,7 +61,7 @@ export function SignMessage() {

{signMessageData && (
<Box color="textSecondary">
<Box>Recovered Address: {recoveredAddress.current}</Box>
<Box>Recovered Address: {recoveredAddress}</Box>
<Box style={{ wordBreak: 'break-all' }}>
Signature: {signMessageData}
</Box>
Expand Down
9 changes: 9 additions & 0 deletions docs/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,22 @@ import { NextResponse } from 'next/server'
import { locales } from 'nextra/locales'

const redirects: Record<string, string> = {
'/core/actions/fetchSigner': '/core/actions/getWalletClient',
'/core/actions/getProvider': '/core/actions/getPublicClient',
'/core/actions/getWebSocketProvider':
'/core/actions/getWebSocketPublicClient',
'/core/client': '/core/config',
'/docs/connectors/coinbase-wallet': '/docs/connectors/coinbaseWallet',
'/docs/connectors/metamask': '/docs/connectors/metaMask',
'/docs/connectors/walletconnect': '/docs/connectors/walletConnect',
'/docs/create-wagmi': '/cli/create-wagmi',
'/docs/migrating-to-030': '/docs/migrating-to-03', // Tweeted wrong link: https://twitter.com/awkweb/status/1518607780332122116
'/docs/migrating-to-03': '/docs/migration-guide',
'/docs/provider': '/docs/WagmiConfig',
'/react/client': '/react/config',
'/react/hooks/useProvider': '/react/hooks/usePublicClient',
'/react/hooks/useSigner': '/react/hooks/useWalletClient',
'/react/hooks/useWebSocketProvider': '/react/hooks/useWebSocketPublicClient',
'/react/prepare-hooks/intro': '/react/prepare-hooks',
}

Expand Down
10 changes: 5 additions & 5 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@
},
"dependencies": {
"degen": "^0.0.49",
"ethers": "^5.7.1",
"fathom-client": "^3.5.0",
"iron-session": "^6.1.3",
"next": "^13.0.5",
"next-themes": "^0.2.0",
"nextra": "^2.0.0",
"nextra-theme-docs": "^2.0.0",
"nextra": "2.0.0",
"nextra-theme-docs": "2.0.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"siwe": "^1.1.6",
"wagmi": "workspace:*"
"wagmi": "workspace:*",
"viem": "~0.3.18"
},
"devDependencies": {
"@preconstruct/next": "^4.0.0",
Expand All @@ -34,4 +34,4 @@
"tailwindcss": "^3.2.4",
"typescript": "^4.9.4"
}
}
}
4 changes: 2 additions & 2 deletions docs/pages/cli/getting-started.en-US.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ For example, we can add the `ERC20` contract from `wagmi`, and the [`etherscan`]
import { defineConfig } from '@wagmi/cli'
import { etherscan, react } from '@wagmi/cli/plugins'
import { erc20ABI } from 'wagmi'
import { mainnet, goerli } from 'wagmi/chains'
import { mainnet, sepolia } from 'wagmi/chains'

export default defineConfig({
out: 'src/generated.ts',
Expand All @@ -98,7 +98,7 @@ export default defineConfig({
name: 'EnsRegistry',
address: {
[mainnet.id]: '0x314159265dd8dbb310642f98f50c066173c1259b',
[goerli.id]: '0x112234455c3a32fd11230c42e7bccd4a84e02010',
[sepolia.id]: '0x112234455c3a32fd11230c42e7bccd4a84e02010',
},
},
],
Expand Down
7 changes: 4 additions & 3 deletions docs/pages/core/_meta.en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
"getting-started": "Getting Started",
"migration-guide": "Migration Guide",
"typescript": "TypeScript",
"client": "Client",
"config": "Config",
"chains": "Chains",
"providers": "Providers",
"connectors": "Connectors",
"actions": "Actions",
"constants": "Constants",
"module-types": "Module Types"
}
"module-types": "Module Types",
"faq": "FAQ"
}
8 changes: 4 additions & 4 deletions docs/pages/core/actions/_meta.en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
"fetchEnsName": "fetchEnsName",
"fetchEnsResolver": "fetchEnsResolver",
"fetchFeeData": "fetchFeeData",
"fetchSigner": "fetchSigner",
"fetchTransaction": "fetchTransaction",
"fetchToken": "fetchToken",
"getAccount": "getAccount",
"getContract": "getContract",
"getNetwork": "getNetwork",
"getProvider": "getProvider",
"getWebSocketProvider": "getWebSocketProvider",
"getPublicClient": "getPublicClient",
"getWalletClient": "getWalletClient",
"getWebSocketPublicClient": "getWebSocketPublicClient",
"multicall": "multicall",
"prepareSendTransaction": "prepareSendTransaction",
"prepareWriteContract": "prepareWriteContract",
Expand All @@ -38,4 +38,4 @@
"watchSigner": "watchSigner",
"watchWebSocketProvider": "watchWebSocketProvider",
"writeContract": "writeContract"
}
}
1 change: 0 additions & 1 deletion docs/pages/core/actions/connect.en-US.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ const result = await connect({
unsupported?: boolean
}
connector: Connector
provider: Provider
}
```

Expand Down
8 changes: 5 additions & 3 deletions docs/pages/core/actions/fetchBalance.en-US.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ description: 'Action for fetching balance information for Ethereum or ERC-20 tok

Action for fetching balance information for Ethereum or ERC-20 tokens.

This is a wrapper around viem's [`getBalance`](https://viem.sh/docs/actions/public/getBalance.html).

```ts
import { fetchBalance } from '@wagmi/core'
```
Expand All @@ -28,7 +30,7 @@ const balance = await fetchBalance({
decimals: number
formatted: string
symbol: string
value: BigNumber
value: bigint
}
```

Expand All @@ -48,7 +50,7 @@ const balance = await fetchBalance({

### chainId (optional)

Force a specific chain id for the request. The @wagmi/core `Client`'s ethers `provider` must be set up as a [chain-aware function](/core/client#provider-optional) for this to work correctly.
Force a specific chain id for the request. The @wagmi/core `Client`'s `publicClient` must be set up as a [chain-aware function](/core/config#publicclient-optional) for this to work correctly.

```ts {5}
import { fetchBalance } from '@wagmi/core'
Expand All @@ -61,7 +63,7 @@ const balance = await fetchBalance({

### formatUnits (optional)

Formats balance using ethers [units](https://docs.ethers.io/v5/api/utils/display-logic/#display-logic--units). Defaults to `ether` or `token`'s decimal value.
Formats balance. Defaults to `ether` or `token`'s decimal value.

```ts {5}
import { fetchBalance } from '@wagmi/core'
Expand Down
6 changes: 4 additions & 2 deletions docs/pages/core/actions/fetchBlockNumber.en-US.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ description: 'Action for fetching the current block number.'

Action for fetching the current block number.

This is a wrapper around viem's [`getBlockNumber`](https://viem.sh/docs/actions/public/getBlockNumber.html).

```ts
import { fetchBlockNumber } from '@wagmi/core'
```
Expand All @@ -22,14 +24,14 @@ const blockNumber = await fetchBlockNumber()
## Return Value

```ts
number
bigint
```

## Configuration

### chainId (optional)

Force a specific chain id for the request. The wagmi `Client`'s ethers `provider` must be set up as a [chain-aware function](/core/client#provider-optional) for this to work correctly.
Force a specific chain id for the request. The wagmi `Client`'s `publicClient` must be set up as a [chain-aware function](/core/config#publicclient-optional) for this to work correctly.

```ts {4}
import { fetchBlockNumber } from '@wagmi/core'
Expand Down
Loading

1 comment on commit 5be0655

@vercel
Copy link

@vercel vercel bot commented on 5be0655 May 9, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.