sacco 0.2.0 copy "sacco: ^0.2.0" to clipboard
sacco: ^0.2.0 copied to clipboard

Pure Dart library allowing you to easily create an HD Wallet and create, sign and send Cosmos-SDK transactions.

example/example.dart

import 'package:sacco/sacco.dart';

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

  final networkInfo = NetworkInfo(
    bech32Hrp: 'did:com:',
    lcdUrl: Uri.parse('http://localhost:1337'),
  );

  const 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': const [
        {
          '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}');
  }
}
5
likes
120
pub points
54%
popularity

Publisher

verified publishercommercio.network

Pure Dart library allowing you to easily create an HD Wallet and create, sign and send Cosmos-SDK transactions.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

bech32, convert, equatable, http, pointycastle

More

Packages that depend on sacco