Releases: wevm/viem
[email protected]
👉 Migration Guide 👈
Minor Changes
-
#229
098f342
Thanks @jxom! - Breaking: Removed thegetAccount
function.For JSON-RPC Accounts, use the address itself.
import { createWalletClient, custom } from 'viem' import { mainnet } from 'viem/chains' const address = '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2' const client = createWalletClient({ - account: getAccount(address), + account: address, chain: mainnet, transport: custom(window.ethereum) })
For Ethers Wallet Adapter, use
ethersWalletToAccount
.If you were using the Ethers Wallet adapter, you can use the
ethersWalletToAccount
function.Note: viem 0.2.0 now has a Private Key & Mnemonic Account implementation. You probably do not need this adapter anymore. This adapter may be removed in a future version.
import { createWalletClient, custom } from 'viem' import { mainnet } from 'viem/chains' - import { getAccount } from 'viem/ethers' + import { ethersWalletToAccount } from 'viem/ethers' import { Wallet } from 'ethers' - const account = getAccount(new Wallet('0x...')) + const account = ethersWalletToAccount(new Wallet('0x...')) const client = createWalletClient({ account, chain: mainnet, transport: custom(window.ethereum) })
For Local Accounts, use
toAccount
.- import { createWalletClient, http, getAccount } from 'viem' + import { createWalletClient, http } from 'viem' + import { toAccount } from 'viem/accounts' import { mainnet } from 'viem/chains' import { getAddress, signMessage, signTransaction } from './sign-utils' const privateKey = '0x...' - const account = getAccount({ + const account = toAccount({ address: getAddress(privateKey), signMessage(message) { return signMessage(message, privateKey) }, signTransaction(transaction) { return signTransaction(transaction, privateKey) }, signTypedData(typedData) { return signTypedData(typedData, privateKey) } }) const client = createWalletClient({ account, chain: mainnet, transport: http() })
-
#229
098f342
Thanks @jxom! - Breaking: RemovedassertChain
argument onsendTransaction
,writeContract
&deployContract
. If you wish to bypass the chain check (not recommended unless for testing purposes), you can passchain: null
.await walletClient.sendTransaction({ - assertChain: false, + chain: null, ... })
-
#229
098f342
Thanks @jxom! - Breaking: A chain is now required for thesendTransaction
,writeContract
,deployContract
Actions.You can hoist the Chain on the Client:
import { createWalletClient, custom, getAccount } from 'viem' import { mainnet } from 'viem/chains' export const walletClient = createWalletClient({ + chain: mainnet, transport: custom(window.ethereum) }) const account = getAccount('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266') const hash = await walletClient.sendTransaction({ account, to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8', value: 1000000000000000000n })
Alternatively, you can pass the Chain directly to the Action:
import { createWalletClient, custom, getAccount } from 'viem' import { mainnet } from 'viem/chains' export const walletClient = createWalletClient({ - chain: mainnet, transport: custom(window.ethereum) }) const account = getAccount('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266') const hash = await walletClient.sendTransaction({ account, + chain: mainnet, to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8', value: 1000000000000000000n })
-
#229
098f342
Thanks @jxom! - Breaking: Updated utility type names to reflect their purposes:ExtractErrorNameFromAbi
is nowInferErrorName
ExtractEventNameFromAbi
is nowInferEventName
ExtractFunctionNameFromAbi
is nowInferFunctionName
ExtractItemNameFromAbi
is nowInferItemName
ExtractConstructorArgsFromAbi
is nowGetConstructorArgs
ExtractErrorArgsFromAbi
is nowGetErrorArgs
ExtractEventArgsFromAbi
is nowGetEventArgs
ExtractEventArgsFromTopics
is nowGetEventArgsFromTopics
ExtractArgsFromAbi
is nowGetFunctionArgs
-
#229
098f342
Thanks @jxom! - Breaking: The following functions are nowasync
functions instead of synchronous functions:recoverAddress
recoverMessageAddress
verifyMessage
import { recoverMessageAddress } from 'viem' - recoverMessageAddress({ message: 'hello world', signature: '0x...' }) + await recoverMessageAddress({ message: 'hello world', signature: '0x...' })
Patch Changes
-
#229
098f342
Thanks @jxom! - Added Local Account implementations:privateKeyToAccount
mnemonicToAccount
hdKeyToAccount
If you were previously relying on the
viem/ethers
wallet adapter, you no longer need to use this.- import { Wallet } from 'ethers' - import { getAccount } from 'viem/ethers' + import { privateKeyToAccount } from 'viem/accounts' const privateKey = '0x...' - const account = getAccount(new Wallet(privateKey)) + const account = privateKeyToAccount(privateKey) const client = createWalletClient({ account, chain: mainnet, transport: http() })
- #229
098f342
Thanks @jxom! - Added WebSocketeth_subscribe
supportwatchBlocks
,watchBlockNumber
, andwatchPendingTransactions
.
-
#229
098f342
Thanks @jxom! - Added the ability to hoist an Account to the Wallet Client.import { createWalletClient, http } from 'viem' import { mainnnet } from 'viem/chains' const [account] = await window.ethereum.request({ method: 'eth_requestAccounts' }) const client = createWalletClient({ + account, chain: mainnet, transport: http() }) const hash = await client.sendTransaction({ - account, to: '0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC', value: parseEther('0.001') })