Giter Site home page Giter Site logo

shiddenme / wallet_hd Goto Github PK

View Code? Open in Web Editor NEW

This project forked from shareven/wallet_hd

0.0 0.0 0.0 73 KB

A Flutter package project , it is use for HD wallet . Support BTC, ETH, ERC20-USDT transfer signature. (用于HD钱包,支持BTC、ETH、ERC20-USDT转账签名).

License: MIT License

Kotlin 0.26% Swift 0.85% Objective-C 0.08% Dart 98.81%

wallet_hd's Introduction

wallet_hd

A Flutter package project , it is use for HD wallet . Support BTC, ETH, ERC20-USDT transfer signature. (用于HD钱包,支持BTC、ETH、ERC20-USDT转账签名).

Getting Started

Add this line to pubspec.yaml ( 添加这一行到pubspec.yaml)

dependencies:
     wallet_hd: ^0.0.2

How To Use

Use the class WalletHd

Properties and functions:

  /// 创建随机助记词 | Create Random Mnemonic
  static String createRandomMnemonic

  /// 导入助记词,返回[btc地址 , eth地址] | Import mnemonic words and return [btc address, eth address]
  static Future<Map<String, String>> getAccountAddress

  /// ETH 导入助记词返回私钥 | ETH import mnemonic phrase and return private key
  static EthPrivateKey ethMnemonicToPrivateKey

  /// BTC 导入助记词返回私钥wif | BTC import mnemonic phrase and return private key wif
  static String btcMnemonicToPrivateKey

  /// BTC转账 | BTC transfer
  static Future<String> transactionBTC

  /// ETH转账 | ETH transfer
  static Future<String> transactionETH

  /// ERC20USDT转账 | ERC20USDT transfer
  static Future<String> transactionERC20USDT

Examples

import 'package:wallet_hd/wallet_hd.dart';

void main() async {
  String mnemonic = WalletHd.createRandomMnemonic();
  Map<String, String> mapAddr = await WalletHd.getAccountAddress(mnemonic);
  String btcAddr = mapAddr["BTC"];
  String ethAddr = mapAddr["ETH"];
  String toAddress = "input the to address ...";
  String amount = "0.1";
  String btcTxPack =
      await testTransactionBTC(mnemonic, btcAddr, toAddress, amount);
  String ethTxPack =
      await testTransactionETH(mnemonic, ethAddr, toAddress, amount);
  String erc20USDTTxPack =
      await testTransactionERC20USDT(mnemonic, ethAddr, toAddress, amount);
  print(btcTxPack);
  print(ethTxPack);
  print(erc20USDTTxPack);
}

Future testTransactionBTC(
  String mnemonic,
  String fromAddress,
  String toAddress,
  String amount,
) async {
  List unspandList = [
    {"txid": "0x12312313aaaaaaaaa", "output_no": 11, "value": "0.2323"},
    {"txid": "0x12312313bbbbbbbbb", "output_no": 12, "value": "0.2323"},
  ];
  List pendingList = [
    {"txid": "0x12312313aaaaaaaaa", "value": "0.2323"}
  ];
  double fee = 0.0002655;
  List handledUnspandList = unspandList;
  // 如果未确认交易列表不为空,则要从unspands list中去除待确认的交易 | If the list of unconfirmed transactions is not empty, remove the pending transactions from the unspands list
  if (pendingList.isNotEmpty) {
    pendingList.forEach((e) {
      handledUnspandList.removeWhere((x) => e["txid"] == x["txid"]);
    });
  }
  List<BitcoinIn> unspand = handledUnspandList
      .map(
          (e) => BitcoinIn(e["txid"], e["output_no"], double.parse(e["value"])))
      .toList();

  String txPack = await WalletHd.transactionBTC(
      mnemonic, fromAddress, toAddress, amount, fee, unspand);
  print("btc txPack");
  print(txPack);
}

Future testTransactionETH(
  String mnemonic,
  String fromAddress,
  String toAddress,
  String amount,
) async {
  String gasPrice = "113000000000";

  /// 新创建的账号初始none是-1 | the new account nonce is -1
  int nonce = -1;
  String txPack = await WalletHd.transactionETH(
      mnemonic, fromAddress, toAddress, amount, gasPrice, nonce);
  print("eth txPack");
  print(txPack);
}

Future testTransactionERC20USDT(
  String mnemonic,
  String fromAddress,
  String toAddress,
  String amount,
) async {
  String gasPrice = "113000000000";

  /// 新创建的账号初始none是-1 | the new account nonce is -1
  int nonce = -1;
  String txPack = await WalletHd.transactionERC20USDT(
      mnemonic, fromAddress, toAddress, amount, gasPrice, nonce);
  print("eth txPack");
  print(txPack);
}

wallet_hd's People

Contributors

shareven avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.