sacco 0.1.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 83

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.

You can find the latest release of sacco.dart on pub.

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.1.0 - 2019-X-12 #

  • Change a default var in order to maintain backwards compatibility;
  • Added json serialization/deserialization to transaction_result class.

Version 0.0.15 - 2019-4-12 #

  • Fixed errors founded by pub.dev

Version 0.0.14 - 2019-4-12 #

  • Added the possibility to chose the mode (sync, block, async) when you are broadcasting a transaction.

Version 0.0.13 - 2019-28-11 #

  • Fixed the wrong implementation of TxSigner which led to an error in the chain when multiple messages were sent into a single transaction.

Version 0.0.12 - 2019-11-11 #

  • Renamed signData to sign
  • Changed how the signatures are created inside sign, now they are non-deterministic

Version 0.0.11 - 2019-11-11 #

  • Renamed signData to signTxData
  • Added signData that signs the data and returns the ASN.1 DER encoded signature

Version 0.0.10 - 2019-10-23 #

  • Added missing const constructors

Version 0.0.9 - 2019-10-23 #

  • Renamed Wallet.signTxData to Wallet.sign
  • Changed Wallet.sign to accept any Map<String, dynamic> and not just a String
  • Added the MapSorter to the exported types

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.1.0

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]
66
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
83
Learn more about scoring.

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

  • Dart: 2.6.1
  • pana: 0.13.1+4

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
asn1lib ^0.5.13 0.5.14
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 ^1.0.1 1.0.1
hex ^0.1.2 0.1.2
http ^0.12.0 0.12.0+2
json_annotation ^3.0.0 3.0.0
meta ^1.1.7 1.1.8
pointycastle ^1.0.1 1.0.2
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.4
http_parser 3.1.3
path 1.6.4
pedantic 1.9.0
source_span 1.5.5
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
Dev dependencies
build_runner ^1.0.0
build_test ^0.10.9+1
json_serializable ^3.2.0
test ^1.6.8