checkAvailableBNBBalance method
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;
}