Experience effortless interaction with a Cosmos SDK-based network in Dart, facilitating the seamless creation, signing, and transmission of transactions. (Beta version)
* This version is in beta and requires comprehensive testing for each model implementation. **
Create and sign transactions related to the Cosmos Hub.
/// Generating BIP39 seed from mnemonic phrase
final seedBytes = Bip39SeedGenerator(Mnemonic.fromString(
"this dove indoor skin shed gap east welcome gift buffalo silent high"))
.generate();
/// Deriving hierarchical deterministic (HD) wallet using BIP44
final bip44 = Bip44.fromSeed(seedBytes, Bip44Coins.cosmos).deriveDefaultPath;
final pubkey = CosmosSecp256K1PublicKey.fromBytes(bip44.publicKey.compressed);
final privateKey = CosmosSecp256K1PrivateKey.fromBytes(bip44.privateKey.raw);
// Initializing provider to interact with Tendermint node of Theta testnet
final provider = TendermintProvider(TendermintHTTPProvider(
url: "https://rpc.sentry-02.theta-testnet.polypore.xyz"));
/// Querying account info from the blockchain
final accountInfo = await provider.request(TendermintRequestAbciQuery(
request: QueryAccountInfoRequest(pubkey.toAddresss())));
/// Querying the latest block information
final latestBlock = await provider.request(
TendermintRequestAbciQuery(request: const GetLatestBlockRequest()));
/// Creating authentication info for transaction
final authInfo = AuthInfo(
signerInfos: [
SignerInfo(
publicKey: pubkey,
modeInfo: const ModeInfo(ModeInfoSignle(SignMode.signModeDirect)),
sequence: accountInfo.info.sequence)
],
fee: Fee(amount: [
Coin(
denom: "uatom",
amount: BigInt.from(1000),
)
], gasLimit: BigInt.from(200000)));
/// Creating a transaction message to send tokens
final message = MsgSend(
fromAddress: pubkey.toAddresss(),
toAddress: CosmosBaseAddress("cosmos1qhslf0sx2fegltfqq0p5j6etmdznjgfnm2j6nc"),
amount: [Coin(denom: "uatom", amount: BigInt.from(1000000))]);
/// Creating transaction body with the message
final txbody = TXBody(messages: [message]);
/// Creating a signable document for the transaction
final SignDoc signDoc = SignDoc(
bodyBytes: txbody.toBuffer(),
authInfoBytes: authInfo.toBuffer(),
chainId: latestBlock.block!.header.chainId!,
accountNumber: accountInfo.info.accountNumber);
/// Signing the document with the private key
final sign = privateKey.sign(signDoc.toBuffer());
/// Creating a raw transaction with body, authentication info, and signature
final txRaw = TxRaw(
bodyBytes: txbody.toBuffer(),
authInfoBytes: authInfo.toBuffer(),
signatures: [sign]);
/// Broadcasting the raw transaction to the network
await provider.request(TendermintRequestBroadcastTxCommit(
BytesUtils.toHexString(txRaw.toBuffer(), prefix: "0x")));
Support for Secp256k1, ED25519 and NIST P-256 keys.
/// Generate seed bytes from a mnemonic
final seedBytes = Bip39SeedGenerator(Mnemonic.fromString(
"this dove indoor skin shed gap east welcome gift buffalo silent high"))on
.generate();
/// Derive BIP44 path
final bip44 = Bip44.fromSeed(seedBytes, Bip44Coins.cosmos).deriveDefaultPath;
/// Create a Cosmos Secp256k1 private key from the derived private key bytes
final privateKey = CosmosSecp256K1PrivateKey.fromBytes(bip44.privateKey.raw);
/// Generate the corresponding public key and address for Secp256k1
final pubkey = CosmosSecp256K1PublicKey.fromBytes(bip44.publicKey.compressed);
final cosmosAddress = pubkey.toAddresss(hrp: "cosmos");
/// Sign the provided digest using the Secp256k1 private key
final sign = privateKey.sign(digest);
/// Create a Cosmos ED25519 private key from the provided key bytes
final ed25519PrivateKey = CosmosED25519PrivateKey.fromBytes(keyBytes);
/// Generate the corresponding public key and address for ED25519
final edPublicKey = ed25519PrivateKey.toPublicKey();
final validatorAddr = edPublicKey.toAddresss(hrp: "cosmosvaloper");
/// Sign the provided digest using the ED25519 private key
final edSign = ed25519PrivateKey.sign(digest);
/// Create a Cosmos NIST P-256 private key from the provided key bytes
final nistPrivateKey = CosmosNist256p1PrivateKey.fromBytes(keyBytes);
/// Generate the corresponding public key and base address for NIST P-256
final nistPublicKey = nistPrivateKey.toPublicKey();
final baseAddress = nistPublicKey.toAddresss();
/// Sign the provided digest using the NIST P-256 private key
final nistSign = nistPrivateKey.sign(digest);
Support Tendermint RPC.
/// Define a Tendermint provider with a HTTP URL
final provider = TendermintProvider(TendermintHTTPProvider(
url: "https://rpc.sentry-02.theta-testnet.polypore.xyz"));
/// Query account information using the provider
final accountInfo = await provider.request(TendermintRequestAbciQuery(
request: QueryAccountInfoRequest(pubkey.toAddresss())));
/// Get the latest block information using the provider
final latestBlock = await provider.request(
TendermintRequestAbciQuery(request: const GetLatestBlockRequest()));
/// Broadcast a transaction and wait for a commit using the provider
final transaction = await provider.request(TendermintRequestBroadcastTxCommit(
BytesUtils.toHexString(txRaw.toBuffer(), prefix: "0x")));
Contributions are welcome! Please follow these guidelines:
Please file feature requests and bugs in the issue tracker.