github wevm/viem viem@1.5.0

latest releases: viem@2.21.10, viem@2.21.9, viem@2.21.8...
13 months ago

Minor Changes

  • #847 1e5d4545 Thanks @jxom! - Narrowed getBlock, watchBlocks, getFilterChanges, getFilterLogs & getLogs return types for when blockTag or includeTransactions is provided.

    • When blockTag !== 'pending', the return type will now include some non-nullish properties if it were dependent on pending blocks. Example: For getBlock, the block.number type is now non-nullish since blockTag !== 'pending'.
    • On the other hand, when blockTag: 'pending', some properties will be nullish. Example: For getBlock, the block.number type is now null since blockTag === 'pending'.
    • When includeTransactions is provided, the return type of will narrow the transactions property type. Example: block.transactions will be Transaction[] when includeTransactions: true instead of Hash[] | Transaction[].

    TLDR;

    // Before
    const block = publicClient.getBlock({ includeTransactions: true });
    block.transactions;
    //    ^? Hash[] | Transaction[]
    block.transactions[0].blockNumber;
    //                    ^? bigint | null
    
    // After
    const block = publicClient.getBlock({ includeTransactions: true });
    block.transactions;
    //    ^? Transaction[]
    block.transactions[0].blockNumber;
    //                    ^? bigint
    
    // Before
    const block = publicClient.getBlock({
      blockTag: "pending",
      includeTransactions: true
    });
    block.number;
    //    ^? number | null
    block.transactions[0].blockNumber;
    //                    ^? bigint | null
    
    // After
    const block = publicClient.getBlock({
      blockTag: "pending",
      includeTransactions: true
    });
    block.number;
    //    ^? null
    block.transactions[0].blockNumber;
    //                    ^? null
  • #847 1e5d4545 Thanks @jxom! - Type Change: TPending has been added to slot 2 of the Log generics.

    type Log<
      TQuantity = bigint,
      TIndex = number,
    + TPending extends boolean = boolean,
      TAbiEvent extends AbiEvent | undefined = undefined,
      TStrict extends boolean | undefined = undefined,
      TAbi extends Abi | readonly unknown[] = [TAbiEvent],
      TEventName extends string | undefined = TAbiEvent extends AbiEvent
        ? TAbiEvent['name']
        : undefined,
    >
  • #958 f7976fd0 Thanks @jxom! - Added cacheTime as a parameter to getBlockNumber & createClient.

  • 28a82125 Thanks @jxom! - Exported number constants (ie. maxInt128, maxUint256, etc).

  • #951 c75d3b60 Thanks @jxom! - Added support for multiple events on Filters/Log Actions:

    • createEventFilter
    • getLogs
    • watchEvent

    Example:

    import { parseAbi } from "viem";
    import { publicClient } from "./client";
    
    const logs = publicClient.getLogs({
      events: parseAbi([
        "event Approval(address indexed owner, address indexed sender, uint256 value)",
        "event Transfer(address indexed from, address indexed to, uint256 value)"
      ])
    });
  • #957 7950df80 Thanks @jxom! - Added hexToSignature & signatureToHex.

  • #847 1e5d4545 Thanks @jxom! - Type Change: TIncludeTransactions & TBlockTag has been added to slot 1 & 2 of the Block generics.

    type Block<
      TQuantity = bigint,
    + TIncludeTransactions extends boolean = boolean,
    + TBlockTag extends BlockTag = BlockTag,
      TTransaction = Transaction<
        bigint,
        number,
        TBlockTag extends 'pending' ? true : false
      >,
    >

Don't miss a new viem release

NewReleases is sending notifications on new releases.