getBalance method

Future<EtherAmount> getBalance(
  1. EthereumAddress? address,
  2. {BlockNum atBlock = const BlockNum.current()}
)

Gets the amount of Ether held by a contract.

  • address: The address to get the balance of.

Returns a Future representing the balance.

Implementation

Future<EtherAmount> getBalance(EthereumAddress? address,
    {BlockNum atBlock = const BlockNum.current()}) {
  if (address == null) {
    return Future.value(EtherAmount.zero());
  }
  return _provider
      .send<String>('eth_getBalance', [address.hex, atBlock.toBlockParam()])
      .then(BigInt.parse)
      .then((value) => EtherAmount.fromBigInt(EtherUnit.wei, value));
}