checkAvailableBNBBalance method

  1. @override
Future<bool> checkAvailableBNBBalance({
  1. required String toAddress,
  2. required String privateKey,
  3. required double amount,
})
override

Implementation

@override
Future<bool> checkAvailableBNBBalance({
  required String toAddress,
  required String privateKey,
  required double amount,
}) async {
  // 개인키로부터 자격증명 생성
  final credentials = EthPrivateKey.fromHex(privateKey);
  final from = credentials.address;

  // 잔액 확인
  final balance = await _client.getBalance(from);

  // BNB 단위를 Wei로 변환
  final amountInWei = BigInt.from(amount * pow(10, 18));

  final gasFee = await estimateGasFee(
      from: from.hex,
      toAddress: toAddress,
      amount: amount,
      isBEP20: false
  );

  // 총 필요한 금액 (전송액 + 가스비)
  final totalNeeded = amountInWei + gasFee['totalGasFee']!;

  if (balance.getInWei < totalNeeded) {
    return false;
  }

  return true;
}