Sacco.dart is a pure Dart package that allows you to easily perform some operations related to the Cosmos.network ecosystem. This includes:
- Creating an HD Wallet.
- Creating a transaction.
- Signing a transaction.
- 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 networkInfo = NetworkInfo(
bech32Hrp: 'cosmos',
lcdUrl: Uri.parse('http://localhost:1337'),
);
const 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, networkInfo);
Creating a transaction
const 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 = await TxSigner.signStdTx(wallet: wallet, stdTx: stdTx);
Sending a transaction
try {
final txResult = await TxSender.broadcastStdTx(wallet: wallet, stdTx: signedStdTx);
print('Tx send successfully. Hash: ${txResult.hash}');
} catch (error) {
print('Error while sending the tx: $error');
}
Creating a wallet with different index of derivation path
const derivationPathIndex = '1'; // Using index 1 instead 0
final networkInfo = NetworkInfo(
bech32Hrp: 'cosmos',
lcdUrl: Uri.parse('http://localhost:1337'),
);
const 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, networkInfo, derivationPathIndex);
Libraries
- models/account_data
- models/export
- models/node_info
- models/transaction_result
- models/transactions/export
- models/transactions/messages/export
- models/transactions/messages/msg_send
- models/transactions/std_coin
- models/transactions/std_fee
- models/transactions/std_msg
- models/transactions/std_public_key
- models/transactions/std_signature
- models/transactions/std_signature_message
- models/transactions/std_tx
- network_info
- sacco
- tx_builder
- tx_sender
- tx_signer
- utils/account_data_retriever
- utils/bech32_encoder
- utils/big_int_big_endian
- utils/bip32
- utils/bip39
- utils/bip39_wordlist
- utils/ecc_secp256k1
- utils/export
- utils/map_sorter
- utils/node_info_retriever
- utils/tx_signer
- wallet