bl_wallet_native 0.1.6 copy "bl_wallet_native: ^0.1.6" to clipboard
bl_wallet_native: ^0.1.6 copied to clipboard

BL Wallet Native Code Plugin

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:bl_wallet_native/bl_wallet_native.dart';

import 'dart:io';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _initTrustWallet = 'Unknown';
  final _blWalletNativePlugin = BlWalletNative();

  @override
  void initState() {
    super.initState();
  }

  void restore() async{
    await _blWalletNativePlugin.restoreByMnemonic("");
  }

  void sendBnb() async {
    String address = "";
    if(Platform.isAndroid) {
      address = "0x974Ef61021f245CBBcbcbEF9585A5d73bDD9Bb2C";
    }else {
      address = "0xA57382f2c84647e7799dC20017D58418F82bD84a";
    }
    print(await _blWalletNativePlugin.getBinanceBalance());
    if(!await BlWalletNative().checkAvailableBNBBalance(address, 0.3)) {
      print("잔액 부족");
      return;
    }

    final txHash = await _blWalletNativePlugin.sendBNB(
      address,
      0.01, // 0.01 BNB 전송
    );
    print('Transaction Hash: $txHash');
  }

  Future<double> getGasFee() async {
    String address = "";
    if(Platform.isAndroid) {
      address = "0x974Ef61021f245CBBcbcbEF9585A5d73bDD9Bb2C";
    }else {
      address = "0xA57382f2c84647e7799dC20017D58418F82bD84a";
    }

    final gasFee = await _blWalletNativePlugin.getGasFee(address, 100, false);
    print(gasFee);
    var totalGasFee = gasFee['totalGasFee']!;
    print("${totalGasFee / BigInt.from(10).pow(18)}");
    return totalGasFee / BigInt.from(10).pow(18);
  }


  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('BL Wallet Native Plugin'),
        ),
        body: Column(
          children: [
            ElevatedButton(
            onPressed: () async {
              await BlWalletNative().init();
            },
              child: Text("init"),
        ),

      ElevatedButton(
        onPressed: () async {
          await BlWalletNative().createWallet();
        },
        child: Text("createWallet"),
      ),

      ElevatedButton(
        onPressed: () {
          String address = BlWalletNative().getAddress();
          print("address: ${address}");
        },
        child: Text("address"),
      ),
            ElevatedButton(
              onPressed: () {
                sendBnb();
              },
              child: Text("sendBNB"),
            ),
            ElevatedButton(
              onPressed: () {
                getGasFee();
              },
              child: Text("getGasFee"),
            ),
            ElevatedButton(
              onPressed: () async {
                try{
                  await BlWalletNative().deleteWallet();
                }catch(e) {
                  print(e.toString());
                }
              },
              child: Text("delete"),
            ),
            ElevatedButton(
              onPressed: () async {
                String address = "";
              if(Platform.isAndroid) {
                address = "0x974Ef61021f245CBBcbcbEF9585A5d73bDD9Bb2C";
              }else {
                address = "0xA57382f2c84647e7799dC20017D58418F82bD84a";
              }
                var isb = await BlWalletNative().checkAvailableBNBBalance(address, 0.1);
                print("isb : ${isb}");
              },
              child: Text("checkBNB"),
            ),

            ElevatedButton(
              onPressed: () async {
                try{
                  String privateKey = BlWalletNative().getPrivateKey();
                  print("privateKey: ${privateKey}");
                }catch(e) {
                  print(e.toString());
                }
              },
              child: Text("privateKey"),
            ),

            ElevatedButton(
              onPressed: () {
                restore();
              },
              child: Text("restore"),
            ),
      ]
      ),
      )
    );
  }
}