alan 0.41.4+1 copy "alan: ^0.41.4+1" to clipboard
alan: ^0.41.4+1 copied to clipboard

Pure Dart library to easily integrate with any Cosmos-based chain.

example/example.dart

import 'package:alan/alan.dart';
import 'package:alan/proto/cosmos/bank/v1beta1/export.dart' as bank;

void main() async {
  // Create a wallet
  final networkInfo = NetworkInfo.fromSingleHost(
    bech32Hrp: 'desmos',
    host: 'localhost',
  );

  final mnemonic = [
    'roast',
    'stomach',
    'welcome',
    'please',
    'gauge',
    'funny',
    'coconut',
    'baby',
    'bird',
    'announce',
    'bind',
    'jacket',
    'title',
    'vibrant',
    'tomorrow',
    'indoor',
    'bitter',
    'initial',
    'ill',
    'analyst',
    'thought',
    'strike',
    'answer',
    'cotton',
  ];
  final wallet = Wallet.derive(mnemonic, networkInfo);

  // 3. Create and sign the transaction
  final message = bank.MsgSend.create()
    ..fromAddress = wallet.bech32Address
    ..toAddress = 'cosmos1cx7mec8x567xh8f4x7490ndx7xey8lnr9du2qy';
  message.amount.add(Coin.create()
    ..denom = 'uatom'
    ..amount = '100');

  final signer = TxSigner.fromNetworkInfo(networkInfo);
  final tx = await signer.createAndSign(wallet, [message]);

  // 4. Broadcast the transaction
  final txSender = TxSender.fromNetworkInfo(networkInfo);
  final response = await txSender.broadcastTx(tx);

  // Check the result
  if (response.isSuccessful) {
    print('Tx sent successfully. Response: $response');
  } else {
    print('Tx errored: $response');
  }
}
6
likes
110
points
5
downloads

Publisher

unverified uploader

Weekly Downloads

Pure Dart library to easily integrate with any Cosmos-based chain.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

analyzer, asn1lib, bech32, bip39, convert, equatable, fixnum, grpc, hex, http, json_annotation, json_serializable, meta, pointycastle, protobuf

More

Packages that depend on alan