viem

TypeScript Interface for Ethereum

OTHER License

Downloads
2.5M
Stars
2K
Committers
391

Bot releases are visible (Hide)

viem - [email protected]

Published by github-actions[bot] over 1 year ago

Patch Changes

viem - [email protected]

Published by github-actions[bot] over 1 year ago

👉 Migration Guide 👈

Minor Changes

  • #355 b1acfc9 Thanks @jxom! - Breaking: Renamed RequestError to RpcError.
    Breaking: Removed RpcRequestError – use RpcError instead.
    Breaking: Renamed RpcError to RpcRequestError.

Patch Changes

  • #355 b1acfc9 Thanks @jxom! - Added ProviderRpcError subclass.

    Added EIP-1193 UnauthorizedProviderError, UnsupportedProviderMethodError, ProviderDisconnectedError, and ChainDisconnectedError.

  • #349 b275811 Thanks @jxom! - Fixed an issue where Filter querying (eth_getFilterChanges, etc) was not being scoped to the Transport that created the Filter.

viem - [email protected]

Published by github-actions[bot] over 1 year ago

Patch Changes

viem - [email protected]

Published by github-actions[bot] over 1 year ago

Patch Changes

  • #331 cd7b642 Thanks @jxom! - Migrated to TypeScript 5.
    Migrated build process from tsup to tsc.

  • #343 579171d Thanks @fubhy! - Fixed conditional types for poll options on watchBlocks & watchPendingTransactions.

viem - [email protected]

Published by github-actions[bot] over 1 year ago

Patch Changes

  • #328 ee87fe7 Thanks @jxom! - Tweaked error inheritence for UserRejectedRequestError & SwitchChainError to be more friendly with custom errors.
viem - [email protected]

Published by github-actions[bot] over 1 year ago

Patch Changes

  • #326 c83616a Thanks @jxom! - Fixed an issue where filtered logs that do not conform to the provided ABI would cause getLogs, getFilterLogs or getFilterChanges to throw – these logs are now skipped. See #323 for more info.
viem - [email protected]

Published by github-actions[bot] over 1 year ago

Patch Changes

  • #322 ea019d7 Thanks @tmm! - Fixed properties passed to ethers adapter signTransaction
viem - [email protected]

Published by github-actions[bot] over 1 year ago

Patch Changes

  • #317 2720ba5 Thanks @jxom! - Fixed transports property type on FallbackTransport.
viem - [email protected]

Published by github-actions[bot] over 1 year ago

Patch Changes

  • #313 eb2280c Thanks @jxom! - Migrated from idna-uts46-hx to @adraffy/ens-normalize for normalize.
viem - [email protected]

Published by github-actions[bot] over 1 year ago

Patch Changes

  • #310 6dfc225 Thanks @jxom! - Made GetValue return { value?: never } instead of unknown for contract functions that are not payable.
viem - [email protected]

Published by github-actions[bot] over 1 year ago

Patch Changes

  • #295 9a15a61 Thanks @fubhy! - Return discrimated union type from decodeFunctionData

  • #304 8e1b712 Thanks @fubhy! - Fixed getTransactionType to honor undefined EIP-1559, EIP-2930 or Legacy attributes.

  • #302 c00a459 Thanks @fubhy! - Fixed forwarding of options to transport for wallet client

viem - [email protected]

Published by github-actions[bot] over 1 year ago

Patch Changes

viem - [email protected]

Published by github-actions[bot] over 1 year ago

Patch Changes

  • #293 859352c Thanks @TateB! - Fixed ENS address resolution for when resolver returns with a null address, or resolvers that do not support addr. getEnsAddress returns null for these cases.
viem - [email protected]

Published by github-actions[bot] over 1 year ago

Patch Changes

  • #290 ef2bbaf Thanks @holic! - Fixed ENS address resolution for "0x"-prefixed names.
viem - [email protected]

Published by github-actions[bot] over 1 year ago

Patch Changes

viem - [email protected]

Published by github-actions[bot] over 1 year ago

Patch Changes

  • #285 ab9fd12 Thanks @tmm! - Exported hdKeyToAccount and mnemonicToAccount.
viem - [email protected]

Published by github-actions[bot] over 1 year ago

👉 Migration Guide 👈

Minor Changes

  • #229 098f342 Thanks @jxom! - Breaking: Removed the getAccount 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: Removed assertChain argument on sendTransaction, writeContract & deployContract. If you wish to bypass the chain check (not recommended unless for testing purposes), you can pass chain: null.

    await walletClient.sendTransaction({
    - assertChain: false,
    + chain: null,
      ...
    })
    
  • #229 098f342 Thanks @jxom! - Breaking: A chain is now required for the sendTransaction, 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 now InferErrorName
    • ExtractEventNameFromAbi is now InferEventName
    • ExtractFunctionNameFromAbi is now InferFunctionName
    • ExtractItemNameFromAbi is now InferItemName
    • ExtractConstructorArgsFromAbi is now GetConstructorArgs
    • ExtractErrorArgsFromAbi is now GetErrorArgs
    • ExtractEventArgsFromAbi is now GetEventArgs
    • ExtractEventArgsFromTopics is now GetEventArgsFromTopics
    • ExtractArgsFromAbi is now GetFunctionArgs
  • #229 098f342 Thanks @jxom! - Breaking: The following functions are now async 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 WebSocket eth_subscribe support watchBlocks, watchBlockNumber, and watchPendingTransactions.
  • #229 098f342 Thanks @jxom! - Added verifyTypedData, hashTypedData, recoverTypedDataMessage
  • #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')
    })
    
viem - [email protected]

Published by github-actions[bot] over 1 year ago

Patch Changes

  • 93e402d Thanks @jxom! - Fixed a decodeAbiParameters case where static arrays with a dynamic child would consume the size of the child instead of 32 bytes.
viem - [email protected]

Published by github-actions[bot] over 1 year ago

Patch Changes

  • #263 53fda1a Thanks @fubhy! - Fixed issue where ABIs with constructors would throw for decodeFunctionData.
viem - [email protected]

Published by github-actions[bot] over 1 year ago

Patch Changes