Sacco.kt is a Kotlin-JVM library 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 Kotlin-JVM means that you can use it inside your Android application as well as any JVM-based program.
val derivationPath = "m/44'/118'/0'/0/0"
val networkInfo = NetworkInfo(bech32Hrp = "cosmos", lcdUrl = "")
val mnemonicString = "sibling auction sibling flavor judge foil tube dust work mixed crush action menu property project ride crouch hat mom scale start ill spare panther"
val mnemonic = mnemonicString.split(" ")
val wallet = Wallet.derive(mnemonic, derivationPath, networkInfo)
val message = MsgSend(
fromAddress = "cosmos1hafptm4zxy5nw8rd2pxyg83c5ls2v62tstzuv2",
toAddress = "cosmos12lla7fg3hjd2zj6uvf4pqj7atx273klc487c5k",
amount = listOf(StdCoin(amount = "100", denom = "uatom"))
)
// The fee object is optional
val fee = StdFee(gas = "200000", amount = listOf(StdCoin(amount = "250", denom = "uatom")))
val tx = TxBuilder.buildStdTx(stdMsgs = listOf(message), fee = fee)
val signedTx = TxSigner.signStdTx(wallet = wallet, stdTx = tx)
val txHash = TxSender.broadcastStdTx(wallet = wallet, stdTx = signedTx)
println("Tx sent successfully. Hash: $txHash")
A working example can be found inside the Main.kt file.