Zeth - Zerocash on Ethereum  0.8
Reference implementation of the Zeth protocol by Clearmatics
eth_get_balance.py
Go to the documentation of this file.
1 # Copyright (c) 2015-2022 Clearmatics Technologies Ltd
2 #
3 # SPDX-License-Identifier: LGPL-3.0+
4 
5 from zeth.cli.constants import ETH_ADDRESS_DEFAULT
6 from zeth.cli.utils import \
7  load_eth_address, get_eth_network, open_web3_from_network
8 from zeth.core.utils import EtherValue
9 from click import command, option, pass_context
10 from typing import Optional, Any
11 
12 
13 @command()
14 @option(
15  "--eth-addr",
16  help=f"Address or address filename (default: {ETH_ADDRESS_DEFAULT})")
17 @option(
18  "--wei",
19  is_flag=True,
20  default=False,
21  help="Display in Wei instead of Ether")
22 @pass_context
23 def eth_get_balance(ctx: Any, eth_addr: Optional[str], wei: bool) -> None:
24  """
25  Command to get the balance of specific addresses. Support multiple queries
26  per invocation (outputs one per line), for efficiency.
27  """
28  eth_addr = load_eth_address(eth_addr)
29  web3 = open_web3_from_network(get_eth_network(ctx.obj["eth_network"]))
30  balance_wei = web3.eth.getBalance(eth_addr) # pylint: disable=no-member
31  if wei:
32  print(balance_wei)
33  else:
34  print(EtherValue(balance_wei, "wei").ether())
zeth.cli.utils.get_eth_network
NetworkConfig get_eth_network(Optional[str] eth_network)
Definition: utils.py:84
zeth.cli.utils.load_eth_address
str load_eth_address(Optional[str] eth_addr)
Definition: utils.py:444
zeth.cli.utils
Definition: utils.py:1
zeth.cli.constants
Definition: constants.py:1
zeth.core.utils
Definition: utils.py:1
zeth.helper.eth_get_balance.eth_get_balance
None eth_get_balance(Any ctx, Optional[str] eth_addr, bool wei)
Definition: eth_get_balance.py:23
zeth.cli.utils.open_web3_from_network
Any open_web3_from_network(NetworkConfig eth_net)
Definition: utils.py:114
zeth.core.utils.EtherValue
Definition: utils.py:46