bch_wallet 0.0.3

  • Readme
  • Changelog
  • Installing
  • 46

Bitcoin Cash Wallet for Flutter #

A wallet management library, that does all the basic necessary stuff:

  • generates one or multiple wallets (optionally password protected)
  • creates one or more account in each wallet
  • receive and send transactions
  • imports wallet from a backup
  • works with testnet and mainnet

Built on Bitbox for Flutter, which is built on Bitcoin.com's Bitbox API.

Getting Started #

1) Depend on it #

If you just want to get this from Dart's public package directory:

dependencies:
  bch_wallet: ^0.0.1

If you checked this out from Github, add a local dependency into the pubspec.yaml of your testing or development projet:

dependencies:
  bch_wallet:
    path: <path to the directory>/

2) Import it #

import 'package:bch_wallet/bch_wallet.dart';

3) Use it #

await BchWallet.createWallet(
  defaultAccountName: "wallet's first account",
  name: "new wallet",
  password: "q7PWSLDQduXEvBE"
);

// get list of all locally stored wallets
List<Wallet> wallets = await BchWallet.getWalletList();

// when using only one wallet in the app, this method will suffice
Wallet newWallet = await BchWallet.getWallet();

// get all wallet's accounts
List<Account> accounts = await newWallet.accounts;

// one account is always created by default for each wallet.
// When using only one account per wallet, this method will suffice
Account firstAccount = await newWallet.getAccount();

// create a second account - password is necessary for password-protected wallets
// because accounts are hardened
newWallet.createAccount("second account", password: "q7PWSLDQduXEvBE");

// the newly created account will be added to the end of the list
Account secondAccount = await newWallet.getAccount(1);

// generate an empty address - if the address was used before (e.g. when the wallet
// is used in some other app, it will be saved with its balance and transactions
// and another one will be generated until an empty one is found)
Address address = await firstAccount.getReceivingAddress();

// Wait until a desired amount is received to the address.
// All functions in this library work with satoshi amounts
List<Transaction> transaction = await address.receive(BchWallet.toSatoshi(0.1));

// This is a getter for overall (balanced + unconfirmed) balance.
int addressBalance = address.balance;

// The library's local storage doesn't distinguish confirmed and unconfirmed balance.
// When you restart the app or retrieve this address in a new state even before the
// receiving tansaction is confirmed, the returned value will look as follows:
int confirmedBalance = address.confirmedBalance;     // 10000000
int unconfirmedBalance = address.unconfirmedBalance; // 0

// To get confirmed and unconfirmed balance state from the blockchain, do this:
address.updateBalanceFromBlockchain();

// address (and thus account's) balance is always maintained locally for fast retrieval
int accountbalance = await firstAccount.getStoredBalance();

// however, to get account's confirmed and unconfirmed balance, or to check if the
// addresses have not been used in some other app, do this
Map updatedBalance = await firstAccount.getBalanceFromBlockchain();

// to send an amount from the account, first retrieve its utxos. Please store the utxos
// in your state so it doesn't need to be retrieved repeatedly to lower the API load
this.addrsUtxo = await firstAccount.getUtxos();

int amount = firstAccount.getMaxSpendable(this.addrsUtxo);

// when storing the utxos in the state, it is possible to synchronously calculate fee
// after every user's input.
double fee = BchWallet.fromSatoshi(firstAccount.calculateFee(amount, 1, addrsUtxo));

// ready to send
Transaction sendingTx = await firstAccount.send(
  [{"bitcoincash:qqy3au5nur3tn0n4v69xqxa3m72e5ve9rqht7pp0ee" : amount}], addrsUtxo);

// list of transactions (by default ordered from the newest)
List<Transaction> transactions = await firstAccount.getTransactions();

[0.0.2] - 2020-06-03 #

Expanded package description

[0.0.2] - 2020-06-03 #

Fixed README readability

[0.0.1] - 2020-06-03 #

Stateful BCH wallet management for Flutter

  • works one or multiple wallets (optionally password protected)
  • works with one or multiple accounts per wallet
  • receive and send transactions
  • imports wallet from a backup
  • works with testnet and mainnet

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  bch_wallet: ^0.0.3

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:bch_wallet/bch_wallet.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
80
Overall:
Weighted score of the above. [more]
46
Learn more about scoring.

We analyzed this package on Jul 9, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.14
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform linux

Because:

  • package:bch_wallet/bch_wallet.dart that imports:
  • package:bch_wallet/src/account.dart that imports:
  • package:bch_wallet/src/utils/database.dart that imports:
  • package:sqflite/sqflite.dart that declares support for platforms: android, ios, macos

Package does not support Flutter platform macos

Because:

  • package:bch_wallet/bch_wallet.dart that imports:
  • package:bch_wallet/src/account.dart that imports:
  • package:bch_wallet/src/utils/utils.dart that imports:
  • package:flutter_secure_storage/flutter_secure_storage.dart that declares support for platforms: android, ios

Package does not support Flutter platform web

Because:

  • package:bch_wallet/bch_wallet.dart that imports:
  • package:bch_wallet/src/account.dart that imports:
  • package:bch_wallet/src/utils/database.dart that imports:
  • package:sqflite/sqflite.dart that declares support for platforms: android, ios, macos

Package does not support Flutter platform windows

Because:

  • package:bch_wallet/bch_wallet.dart that imports:
  • package:bch_wallet/src/account.dart that imports:
  • package:bch_wallet/src/utils/database.dart that imports:
  • package:sqflite/sqflite.dart that declares support for platforms: android, ios, macos

Package not compatible with SDK dart

Because:

  • bch_wallet that is a package requiring null.

Health suggestions

Fix lib/src/bch_wallet.dart. (-0.50 points)

Analysis of lib/src/bch_wallet.dart reported 1 hint:

line 67 col 48: Avoid using braces in interpolation when not needed.

Format lib/bch_wallet.dart.

Run flutter format to format lib/bch_wallet.dart.

Format lib/src/account.dart.

Run flutter format to format lib/src/account.dart.

Fix additional 5 files with analysis or formatting issues.

Additional issues in the following files:

  • lib/src/address.dart (Run flutter format to format lib/src/address.dart.)
  • lib/src/transaction.dart (Run flutter format to format lib/src/transaction.dart.)
  • lib/src/utils/database.dart (Run flutter format to format lib/src/utils/database.dart.)
  • lib/src/utils/utils.dart (Run flutter format to format lib/src/utils/utils.dart.)
  • lib/src/wallet.dart (Run flutter format to format lib/src/wallet.dart.)

Maintenance suggestions

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package.

Common filename patterns include main.dart, example.dart, and bch_wallet.dart. Packages with multiple examples should provide example/README.md.

For more information see the pub package layout conventions.

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
bitbox ^0.0.5 0.0.5
crypto ^2.1.5 2.1.5
flutter 0.0.0
flutter_secure_storage ^3.3.1+1 3.3.3
path ^1.7.0 1.7.0
shared_preferences ^0.5.3+5 0.5.8
sqflite ^1.2.0 1.3.1
Transitive dependencies
bip32 1.0.5
bip39 1.0.3
bs58check 1.0.1
charcode 1.1.3
collection 1.14.12 1.14.13
convert 2.1.1
file 5.2.1
fixnum 0.10.11
flutter_web_plugins 0.0.0
hex 0.1.2
http 0.12.1
http_parser 3.1.4
intl 0.16.1
meta 1.1.8 1.2.2
path_provider_linux 0.0.1+2
path_provider_platform_interface 1.0.2
pedantic 1.9.0 1.9.2
platform 2.2.1
plugin_platform_interface 1.0.2
pointycastle 1.0.2
process 3.0.13
shared_preferences_linux 0.0.2+1
shared_preferences_macos 0.0.1+10
shared_preferences_platform_interface 1.0.4
shared_preferences_web 0.1.2+7
sky_engine 0.0.99
source_span 1.7.0
sqflite_common 1.0.2+1
string_scanner 1.0.5
synchronized 2.2.0+1
term_glyph 1.1.0
typed_data 1.1.6 1.2.0
vector_math 2.0.8 2.1.0-nullsafety
xdg_directories 0.1.0
Dev dependencies
flutter_test