sacco 0.0.8

  • Readme
  • Changelog
  • Example
  • Installing
  • 74

Pub Travis (.org)

Sacco.dart is a pure Dart package that allows you to easily perform some operations related to the Cosmos.network ecosystem. This includes:

  1. Creating an HD Wallet.
  2. Creating a transaction.
  3. Signing a transaction.
  4. Broadcasting a transaction.

Being it in pure Dart means that you can use it inside your Dart Web projects as well as Flutter ones.

Usage #

Creating a wallet #

final derivationPath = "m/44'/118'/0'/0/0";
final networkInfo = NetworkInfo(id: "", bech32Hrp: "cosmos", lcdUrl: "");

final mnemonicString = "final random flame cinnamon grunt hazard easily mutual resist pond solution define knife female tongue crime atom jaguar alert library best forum lesson rigid";
final mnemonic = mnemonicString.split(" ");
final wallet = Wallet.derive(mnemonic, derivationPath, networkInfo);

Creating a transaction #

final message = StdMsg(
  type: "cosmos-sdk/MsgSend",
  value: {
    "from_address": "cosmos1huydeevpz37sd9snkgul6070mstupukw00xkw9",
    "to_address": "cosmos12lla7fg3hjd2zj6uvf4pqj7atx273klc487c5k",
    "amount": [
      {"denom": "uatom", "amount": "100"}
    ]
  },
);

final stdTx = TxBuilder.buildStdTx(stdMsgs: [message]);

Signing a transaction #

final signedStdTx = TxSigner.signStdTx(wallet: wallet, stdTx: stdTx);

Sending a transaction #

try {
  final hash = await TxSender.broadcastStdTx(wallet: wallet, stdTx: signedStdTx);
  print("Tx send successfully. Hash: $hash");
} catch (error) {
  print("Error while sending the tx: $error");
}

Version 0.0.8 - 2019-09-25 #

  • Removed the id field from the NetworkInfo object
  • Removed the derivationPath field from the Wallet.derive method
  • Changed the return type of the TxSender.broadcastTx method.
    Now it returns a TransactionResponse that include a success field and any error that might have occurred during the broadcast.
  • Fixed some typos inside the exceptions messages

Version 0.0.7 - 2019-08-30 #

  • Added the defaultTokenDenom field inside NetworkInfo

Version 0.0.6 - 2019-08-30 #

  • Added the serialization of the Bech32 address inside Wallet

Version 0.0.5 - 2019-08-30 #

  • Renamed HexWallet to Wallet
  • Added the Wallet.convert factory method
  • Added the optional name and iconUrl fields to NetworkInfo
  • Added the toJson and fromJson methods to both Wallet and NetworkInfo
  • Added the Equatable implementation to both Wallet and NetworkInfo

Version 0.0.4 - 2019-08-29 #

  • Changed the example
  • Fixed some CHANGELOG typos

Version 0.0.3 - 2019-08-29 #

  • Improved the example by adding how to send a transaction

Version 0.0.2 - 2019-08-29 #

  • Improved the package.yaml description
  • Added some examples inside the example/ folder
  • Removed some unused dependencies
  • Improved the README

Version 0.0.1 - 2019-08-29 #

  • Initial release

example/example.dart

import 'package:sacco/sacco.dart';

void main() async {
  // -----------------------------------
  // --- Creating a wallet
  // -----------------------------------

  final networkInfo = NetworkInfo(
    bech32Hrp: "did:com:",
    lcdUrl: "http://localhost:1317",
  );

  final mnemonicString =
      "vivid favorite regular curve check word bubble echo disorder cute parade neck rib evidence option glimpse couple force angry section dizzy puppy express cream";
  final mnemonic = mnemonicString.split(" ");
  final wallet = Wallet.derive(mnemonic, networkInfo);

  // -----------------------------------
  // --- Creating a transaction
  // -----------------------------------

  final message = StdMsg(
    type: "cosmos-sdk/MsgSend",
    value: {
      "from_address": wallet.bech32Address,
      "to_address": "did:com:1lys5uu683wrmupn4zguz7f2gqw45qae98pzn3d",
      "amount": [
        {"denom": "uatom", "amount": "100"}
      ]
    },
  );

  final stdTx = TxBuilder.buildStdTx(stdMsgs: [message]);

  // -----------------------------------
  // Signing a transaction
  // -----------------------------------

  final signedStdTx = await TxSigner.signStdTx(wallet: wallet, stdTx: stdTx);

  // -----------------------------------
  // --- Sending a transaction
  // -----------------------------------

  final result = await TxSender.broadcastStdTx(
    wallet: wallet,
    stdTx: signedStdTx,
  );

  // Check the result
  if (result.success) {
    print("Tx send successfully. Hash: ${result.hash}");
  } else {
    print("Tx send error: ${result.error.errorMessage}");
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  sacco: ^0.0.8

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or 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:sacco/sacco.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
55
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]
74
Learn more about scoring.

We analyzed this package on Oct 22, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.1
  • pana: 0.12.21

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:sacco/sacco.dart.

Health suggestions

Format lib/network_info.dart.

Run dartfmt to format lib/network_info.dart.

Format lib/tx_sender.dart.

Run dartfmt to format lib/tx_sender.dart.

Format lib/tx_signer.dart.

Run dartfmt to format lib/tx_signer.dart.

Fix additional 3 files with analysis or formatting issues.

Additional issues in the following files:

  • lib/utils/account_data_retriever.dart (Run dartfmt to format lib/utils/account_data_retriever.dart.)
  • lib/utils/node_info_retriever.dart (Run dartfmt to format lib/utils/node_info_retriever.dart.)
  • lib/wallet.dart (Run dartfmt to format lib/wallet.dart.)

Maintenance issues and suggestions

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (equatable).

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
bip32 ^1.0.5 1.0.5
bip39 ^1.0.3 1.0.3
bip_bech32 ^0.1.3 0.1.3
bitcoin_flutter ^1.0.7 1.0.7
equatable ^0.5.0 0.5.1 0.6.1
hex ^0.1.2 0.1.2
http ^0.12.0 0.12.0+2
meta ^1.1.7 1.1.7
pointycastle ^1.0.1 1.0.1
Transitive dependencies
async 2.4.0
bs58check 1.0.1
charcode 1.1.2
collection 1.14.12
convert 2.1.1
crypto 2.1.3
http_parser 3.1.3
path 1.6.4
pedantic 1.8.0+1
source_span 1.5.5
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
Dev dependencies
test ^1.6.8