Skip to main content

getBalance

Callable

  • getBalance<ReturnFormat>(web3Context: Web3Context<EthExecutionAPI, any>, address: string, blockNumber?: BlockNumberOrTag, returnFormat: ReturnFormat): Promise<NumberTypes[ReturnFormat[number]]>

  • Get the balance of an address at a given block.


    Type parameters

    • ReturnFormat: DataFormat

    Parameters

    • web3Context: Web3Context<EthExecutionAPI, any>

      (Web3Context) Web3 configuration object that contains things such as the provider, request manager, wallet, etc.

    • address: string

      The address to get the balance of.

    • blockNumber: BlockNumberOrTag = web3Context.defaultBlock

      (BlockNumberOrTag defaults to Web3Eth.defaultBlock) Specifies what block to use as the current state for the balance query.

    • returnFormat: ReturnFormat

      (DataFormat defaults to DEFAULT_RETURN_FORMAT) Specifies how the return data should be formatted.

    Returns Promise<NumberTypes[ReturnFormat[number]]>

    The current balance for the given address in wei.

    web3.eth.getBalance("0x407d73d8a49eeb85d32cf465507dd71d507100c1").then(console.log);
    > 1000000000000n

    web3.eth.getBalance("0x407d73d8a49eeb85d32cf465507dd71d507100c1", { number: FMT_NUMBER.HEX , bytes: FMT_BYTES.HEX }).then(console.log);
    > "0xe8d4a51000"