The Future of wagmi #2207
Replies: 15 comments 26 replies
-
Keep up the great work. WAGMI |
Beta Was this translation helpful? Give feedback.
-
What's the purpose of transitioning to viem? |
Beta Was this translation helpful? Give feedback.
-
Removing infuraProvider and alchemyProvider is good for everybody. Using rpc urls is a general practic everybody should follow so you can more quickly swap to a different provider at any moment with a simple env variable change without a code change |
Beta Was this translation helpful? Give feedback.
-
Keep up the great work. |
Beta Was this translation helpful? Give feedback.
-
Have no FUD on the above and excited for both of these releases! Am a strong +1 to removal of provider-specific RPC utilities and new changes to wagmi config to make injecting a custom viem config easier. |
Beta Was this translation helpful? Give feedback.
-
I would say more of a focus on SSR and integration with next js. Right now if you look at the wagmi example you see that the example waits until we are client side to render anything and provide access to hooks, if youre using a next.js app and try and display an account address using the useAccount() hook it spits a hydration error and you have to abstract the hook to use it. I see that React Query may be able to help this, another option I like is swr. In my opinion swr is the better choice since its SSR first, and for all use cases of dapps, the extra bells and whistles on react query arent that necessary since dapps in general are quite simple. |
Beta Was this translation helpful? Give feedback.
-
I wonder if RainbowKit will work with Wagmi 1.0 out of the box? Are they synced about switching to viem? |
Beta Was this translation helpful? Give feedback.
-
Curious why this is a bigint now. Is number insufficient? We do stuff with blocknumbers and haven't run into issues w/ precision. |
Beta Was this translation helpful? Give feedback.
-
Exporting query keys from @wagmi/core will be super helpful. Right now I had to manually copy the functions over to do things like invalidate data when a user sends a transaction. I am also wondering if the full react-query api will be supported? Specifically |
Beta Was this translation helpful? Give feedback.
-
I might be missing something, but i had a use case when i needed to use |
Beta Was this translation helpful? Give feedback.
-
hi all, just would like to broadcast this here: is there any way we get the ability to retrieve blocks in wagmi v1? does anyone else have this need? please see this discussion. huge thanks in advance. |
Beta Was this translation helpful? Give feedback.
-
Thanks for this attention to detail! I have interest in wrapping the contract interaction part of |
Beta Was this translation helpful? Give feedback.
-
Thank for article. wagmi2.0, give me writecontract example vs wagmi1.0 writecontract example. |
Beta Was this translation helpful? Give feedback.
-
Over the past couple of months, the wagmi core team have actively been planning and designing the future of wagmi, including: the migration to viem, refactor of surface APIs, docs polish, internal library upgrades (TypeScript 5, React Query 5, etc), and more.
The future of wagmi will come in two phases: v1 and v2. This discussion outlines the timeline of the v1 and v2 rollout, and what to expect from from each phase (general overview & breaking changes).
The largest notable change is that wagmi v1 will no longer be built on top of Ethers.js. We will be migrating to viem.
wagmi v2 will include other API refactors, unrelated to viem, to improve the general developer experience of wagmi.
v1
Release Date: May 2023
NPM:
npm i wagmi@1
The v1 release will only include the migration from ethers.js to viem, and nothing else. v1 will be wagmi how it is today, and the APIs will still be & feel very similar to 0.x. However, we will need to introduce some small breaking changes to escape "ethers" terminology. We expect these breaking changes will make the API more clear though.
v1 will be a stable release.
Below, we have listed the approximated breaking changes, so you can start thinking ahead.
Breaking Changes Overview
General
BigNumber
will be removed in favor of nativeBigInt
gasLimit
is nowgas
(still means the same, but aligns closer to Ethereum terminology / EIP-1474)provider
/webSocketProvider
is nowpublicClient
/webSocketPublicClient
signer
is nowwalletClient
Actions & Hooks
Many of the Actions & Hooks below map one-to-one and share a similar API to viem's Actions.
connect
/useConnect
provider
property. Useconnector.getProvider()
instead.fetchBalance
/useBalance
bigint
instead ofBigNumber
forvalue
getBalance
fetchBlockNumber
/useBlockNumber
bigint
instead of anumber
getBlockNumber
fetchEnsAvatar
/useEnsAvatar
address
withname
getEnsAvatar
fetchFeeData
/useFeeData
bigint
instead of aBigNumber
forgasPrice
,maxFeePerGas
,maxPriorityFeePerGas
fetchSigner
/useSigner
/watchSigner
account
) instead of EthersJsonRpcSigner
fetchToken
/useToken
bigint
instead of aBigNumber
fortotalSupply.value
fetchTransaction
/useTransaction
Transaction
instead of an ethersTransaction
getTransaction
getContract
getProvider
/useProvider
/watchProvider
getPublicClient
/usePublicClient
Provider
getWebSocketProvider
/useWebSocketProvider
/watchWebSocketProvider
getWebSocketPublicClient
/useWebSocketPublicClient
Provider
multicall
allowFailure: true
(default), returns{ error, result, status }[]
shape instead of an array of resultsResult[]
allowFailure: false
, returns array of resultsResult[]
error
andstatus
so a consumer can inspect and retrieve error data without it being silently disposed of.allowFailure: true
readContract
parametersmulticall
.prepareSendTransaction
/usePrepareSendTransaction
overrides
option in favor top-levelaccount
,gas
,maxFeePerGas
, etc options.sendTransaction
parametersprepareWriteContract
/usePrepareContractWrite
abi
,address
,functionName
from the return value, they now belong inrequest
request
now returns the shape of viem'sWriteContractParameters
instead of Ethers'TransactionRequest
overrides
option in favor top-levelaccount
,gas
,maxFeePerGas
, etc options.simulateContract
parameterseth_sendTransaction
parameter.simulateContract
readContract
/useContractRead
overrides
option in favor top-levelblockNumber
&blockTag
options.readContract
parameterseth_call
parameter.readContract
readContracts
/useContractReads
/useContractInfiniteReads
overrides
option in favor top-levelblockNumber
&blockTag
options.readContract
parameterseth_call
parameter.allowFailure: true
(default), returns{ error, result, status }[]
shape instead of an array of resultsResult[]
allowFailure: false
, returns array of resultsResult[]
error
andstatus
so a consumer can inspect and retrieve error data without it being silently disposed of.allowFailure: true
multicall
signMessage
/useSignMessage
message
no longer accepts a byte array, only a string value.signMessage
signTypedData
value
has been renamed tomessage
primaryType
is now required.signTypedData
useContract
getContract
Action instead.waitForTransaction
/useWaitForTransaction
onSpeedUp
toonReplaced
TransactionReceipt
instead of an EthersTransactionReceipt
watchPendingTransactions
/useWatchPendingTransactions
watchPendingTransactions
writeContract
/useContractWrite
wait
has been removed from the return type, favorwaitForTransaction
/useWaitForTransaction
instead.overrides
option in favor top-levelaccount
,gas
,maxFeePerGas
, etc options.writeContract
parameterseth_sendTransaction
parameter.writeContract
watchContractEvent
/useContractEvent
once
config option.watchContractEvent
configureChains
priority
,minQuorum
andtargetQuorum
(for now). viem does not support quorum in thefallback
Transport yet, but will in the future!Connectors
getSigner
now returns a viemWalletClient
instead of an EthersSigner
Signer
generic.Errors
ChainDoesNotSupportMulticallError
,ContractMethodDoesNotExistError
,ContractMethodNoResultError
,ContractMethodRevertedError
,ContractResultDecodeError
,ProviderRpcError
,ResourceUnavailableError
v2
Release Date: June 2023
NPM:
npm i wagmi@2
Approximately a month after the v1 release, we will be releasing v2. This phase will include other API refactors, unrelated to viem, that we have been meaning to do. These include: upgrading to React Query 5 + more flexible React Query patterns, TypeScript 5, consolidating
configureChains
intocreateConfig
, removing/repurposing Prepare Hooks (!!), and more.Features Overview
Renaming the wagmi "Client" to the wagmi "Config"
To remove ambiguity between the wagmi Client and the viem Clients, we are going to be renaming the wagmi "Client" to the wagmi "Config".
Remove
configureChains
& RPC Provider (alchemyProvider
, etc) utilitiesWe will be removing the
configureChains
utility and be directly integrating it intocreateConfig
. This means that consumers will import less and have less code to set up a wagmi project, while still having the flexibility to configure chains, connectors & RPC URLS.We will also most likely removing the RPC Provider utilties (
alchemyProvider
,infuraProvider
, etc) in favor of the consumer directly passing the RPC URL themselves for each chain. We understand this may be more verbose, but it is much a "set & forget" kind of thing.By default, we will recommend consumers to provide a "high-level" config to
createClient
, which will internally create a multi-chain viem Public Client to use in wagmi.Consumers will also be able to pass in a "low-level" config (escape hatch), where they will be able to directly pass through a viem Public Client instead of wagmi doing it under-the-hood (as seen in the "high-level" config above).
The removal of the global wagmi Client
The global wagmi Client has deemed to be problematic for
@wagmi/core
(and somewagmi
) consumers, and caused some issues around "No wagmi client found.". This was mostly a side-effect from the "dual-package hazard" when wagmi published CJS + ESM packages. We will be removing the global wagmi Client in favour of a Client in which the consumer will have to inject (only applies to @wagmi/core).Regardless, we think that setting global variables in a JavaScript library is an anti-pattern anyway, so we are going to remove it.
As the global Client will be removed, this will mean that consumers will need to provide Client context to
@wagmi/core
Actions. We think injecting the Client (or Config) as a first parameter might be the way to go (subject to change):Repurpose Prepare Hooks
One of the main reasons why we introduced Prepare Hooks was to mitigate iOS universal link issues seen when performing long-running asynchronous tasks in an event handler (ie. you would be redirected to a wallet app store or fallback page if you pressed an action). However, WalletConnect is now prioritizing deep links over universal links which come with the advantage that end-users will no longer be unexpectedly redirected – they will instead see a prompt to open the app.
As a result, this means that consumers no longer need to use Prepare Hooks. We aren't going to be completely removing them, as they are still useful for reducing the "time-to-open-wallet" and for contract/transaction simulation, but we may rename them to
useSimulateContract
&useSimulateTransaction
. This means that imperatively passing dynamic arguments will be easier, and also means we will be removing all the "recklessly" terminology.If you were familiar with
useContractWrite
&useSendTransaction
before Prepare Hooks were introduced, the API will be very similar.Upgrade to React (TanStack) Query 5
We will be upgrading to React (TanStack) Query to version 5. This comes with it's own list of features & breaking changes: TanStack/query#4252
Export Query Keys/Functions from
@wagmi/core
We will be moving the React Query (TanStack Query) query keys & functions from the React entrypoint (
wagmi
), to the Vanilla JS core@wagmi/core
. We will also be exporting them!This means that consumers will be able to use native TanStack Query functionality like
prefetchQuery
,setQueryData
, etc with wagmi's Query Keys & Functions.This also means that consumers will easily be able to extend wagmi onto other frameworks such as Vue, Svelte & Solid by utilizing TanStack Query's framework adapters (Vue, Solid, Svelte, etc).
You could imagine that
@wagmi/core
will have a "Query Options" API: https://twitter.com/tkdodo/status/1628453270401294337?s=46&t=JT6DdzO0r2xvkFHm1auj1wRename
autoConnect
toreconnect
and make it default truthyautoConnect
will be renamed toreconnect
Most of the wagmi usages (and the docs) set
autoConnect: true
, and it generally accompanies a better user experience, so we are going to defaultreconnect
totrue
.Function-based Connectors
Currently, our Connectors are class-based. We plan to migrate Connectors to be function-based for better internal config currying DX.
Beta Was this translation helpful? Give feedback.
All reactions