Skip to content

Block number 0 in getBalance is ignored #3629

@fvictorio

Description

@fvictorio

Check existing issues

Viem Version

2.29.0

Current Behavior

Getting the balance of an account using publicClient.getBalance and blockNumber: 0n returns the balance of the account in the latest block.

Expected Behavior

The balance in the block zero should be returned.

Steps To Reproduce

Start an anvil node and run this script:

import { createPublicClient, createWalletClient, http } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { anvil } from "viem/chains";

const publicClient = createPublicClient({
    chain: anvil,
    transport: http()
})

const walletClient = createWalletClient({
    account: privateKeyToAccount("0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"),
    chain: anvil,
    transport: http()
})

await walletClient.sendTransaction({
    to: "0xff000000000000000000000000000000000000ff",
    value: 1000n
})

console.log(await publicClient.getBalance({
    address:  "0xff000000000000000000000000000000000000ff",
    blockNumber: 0n,
}))

Link to Minimal Reproducible Example

No response

Anything else?

I guess this is a non-strict check that is interpreting 0n as falsy.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions