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.
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);
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]);
final signedStdTx = TxSigner.signStdTx(wallet: wallet, stdTx: stdTx);
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");
}