# Tx helper
Allows to easily perform common transaction operations.
# Provided operations
- Creates a transaction having the given
msgs
, signs it with the givenwallet
and sends it to the blockchain. Optional parameters can befee
and broadcastingmode
, that can be of type "sync", "async" or "block".
suspend fun createSignAndSendTx(
msgs: List<StdMsg>,
wallet: Wallet,
fee: StdFee? = null,
mode: BroadcastingMode? = null
): TxResponse
1
2
3
4
5
6
2
3
4
5
6
# Usage examples
val info = NetworkInfo(bech32Hrp = "did:com:", lcdUrl = "http://localhost:1317")
val mnemonic = listOf(
"will",
"hard",
"topic",
"spray",
"beyond",
"ostrich",
"moral",
"morning",
"gas",
"loyal",
"couch",
"horn",
"boss",
"across",
"age",
"post",
"october",
"blur",
"piece",
"wheel",
"film",
"notable",
"word",
"man"
)
val wallet = Wallet.derive(mnemonic = mnemonic, networkInfo = info)
val deposit = listOf(StdCoin(denom = "ucommercio", amount = "100"))
val msgDeposit = listOf(
MsgSend(
amount = deposit,
fromAddress = wallet.bech32Address,
toAddress = "did:com:14ttg3eyu88jda8udvxpwjl2pwxemh72w0grsau"
)
)
val fee = StdFee(gas = "200000", amount = listOf(StdCoin(denom = "ucommercio", amount = "10000")))
val mode = TxHelper.BroadcastingMode.BLOCK
try {
TxHelper.createSignAndSendTx(
msgs = msgDeposit,
wallet = wallet,
fee = fee,
mode = mode
)
} catch (e: Exception){
throw e
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54