github.com/cosmos/cosmos-sdk@v0.50.10/x/auth/tx/README.md (about) 1 --- 2 sidebar_position: 1 3 --- 4 5 # `x/auth/tx` 6 7 :::note Pre-requisite Readings 8 9 * [Transactions](https://docs.cosmos.network/main/core/transactions#transaction-generation) 10 * [Encoding](https://docs.cosmos.network/main/core/encoding#transaction-encoding) 11 12 ::: 13 14 ## Abstract 15 16 This document specifies the `x/auth/tx` package of the Cosmos SDK. 17 18 This package represents the Cosmos SDK implementation of the `client.TxConfig`, `client.TxBuilder`, `client.TxEncoder` and `client.TxDecoder` interfaces. 19 20 ## Contents 21 22 * [Transactions](#transactions) 23 * [`TxConfig`](#txconfig) 24 * [`TxBuilder`](#txbuilder) 25 * [`TxEncoder`/ `TxDecoder`](#txencoder-txdecoder) 26 * [Client](#client) 27 * [CLI](#cli) 28 * [gRPC](#grpc) 29 30 ## Transactions 31 32 ### `TxConfig` 33 34 `client.TxConfig` defines an interface a client can utilize to generate an application-defined concrete transaction type. 35 The interface defines a set of methods for creating a `client.TxBuilder`. 36 37 ```go reference 38 https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc1/client/tx_config.go#L25-L31 39 ``` 40 41 The default implementation of `client.TxConfig` is instantiated by `NewTxConfig` in `x/auth/tx` module. 42 43 ```go reference 44 https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc1/x/auth/tx/config.go#L22-L28 45 ``` 46 47 ### `TxBuilder` 48 49 ```go reference 50 https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc1/client/tx_config.go#L33-L50 51 ``` 52 53 The [`client.TxBuilder`](https://docs.cosmos.network/main/core/transactions#transaction-generation) interface is as well implemented by `x/auth/tx`. 54 A `client.TxBuilder` can be accessed with `TxConfig.NewTxBuilder()`. 55 56 ### `TxEncoder`/ `TxDecoder` 57 58 More information about `TxEncoder` and `TxDecoder` can be found [here](https://docs.cosmos.network/main/core/encoding#transaction-encoding). 59 60 ## Client 61 62 ### CLI 63 64 #### Query 65 66 The `x/auth/tx` module provides a CLI command to query any transaction, given its hash, transaction sequence or signature. 67 68 Without any argument, the command will query the transaction using the transaction hash. 69 70 ```shell 71 simd query tx DFE87B78A630C0EFDF76C80CD24C997E252792E0317502AE1A02B9809F0D8685 72 ``` 73 74 When querying a transaction from an account given its sequence, use the `--type=acc_seq` flag: 75 76 ```shell 77 simd query tx --type=acc_seq cosmos1u69uyr6v9qwe6zaaeaqly2h6wnedac0xpxq325/1 78 ``` 79 80 When querying a transaction given its signature, use the `--type=signature` flag: 81 82 ```shell 83 simd query tx --type=signature Ofjvgrqi8twZfqVDmYIhqwRLQjZZ40XbxEamk/veH3gQpRF0hL2PH4ejRaDzAX+2WChnaWNQJQ41ekToIi5Wqw== 84 ``` 85 86 When querying a transaction given its events, use the `--type=events` flag: 87 88 ```shell 89 simd query txs --events 'message.sender=cosmos...' --page 1 --limit 30 90 ``` 91 92 The `x/auth/block` module provides a CLI command to query any block, given its hash, height, or events. 93 94 When querying a block by its hash, use the `--type=hash` flag: 95 96 ```shell 97 simd query block --type=hash DFE87B78A630C0EFDF76C80CD24C997E252792E0317502AE1A02B9809F0D8685 98 ``` 99 100 When querying a block by its height, use the `--type=height` flag: 101 102 ```shell 103 simd query block --type=height 1357 104 ``` 105 106 When querying a block by its events, use the `--query` flag: 107 108 ```shell 109 simd query blocks --query 'message.sender=cosmos...' --page 1 --limit 30 110 ``` 111 112 #### Transactions 113 114 The `x/auth/tx` module provides a convinient CLI command for decoding and encoding transactions. 115 116 #### `encode` 117 118 The `encode` command encodes a transaction created with the `--generate-only` flag or signed with the sign command. 119 The transaction is seralized it to Protobuf and returned as base64. 120 121 ```bash 122 $ simd tx encode tx.json 123 Co8BCowBChwvY29zbW9zLmJhbmsudjFiZXRhMS5Nc2dTZW5kEmwKLWNvc21vczFsNnZzcWhoN3Jud3N5cjJreXozampnM3FkdWF6OGd3Z3lsODI3NRItY29zbW9zMTU4c2FsZHlnOHBteHU3Znd2dDBkNng3amVzd3A0Z3d5a2xrNnkzGgwKBXN0YWtlEgMxMDASBhIEEMCaDA== 124 $ simd tx encode tx.signed.json 125 ``` 126 127 More information about the `encode` command can be found running `simd tx encode --help`. 128 129 #### `decode` 130 131 The `decode` commands decodes a transaction encoded with the `encode` command. 132 133 134 ```bash 135 simd tx decode Co8BCowBChwvY29zbW9zLmJhbmsudjFiZXRhMS5Nc2dTZW5kEmwKLWNvc21vczFsNnZzcWhoN3Jud3N5cjJreXozampnM3FkdWF6OGd3Z3lsODI3NRItY29zbW9zMTU4c2FsZHlnOHBteHU3Znd2dDBkNng3amVzd3A0Z3d5a2xrNnkzGgwKBXN0YWtlEgMxMDASBhIEEMCaDA== 136 ``` 137 138 More information about the `decode` command can be found running `simd tx decode --help`. 139 140 ### gRPC 141 142 A user can query the `x/auth/tx` module using gRPC endpoints. 143 144 #### `TxDecode` 145 146 The `TxDecode` endpoint allows to decode a transaction. 147 148 ```shell 149 cosmos.tx.v1beta1.Service/TxDecode 150 ``` 151 152 Example: 153 154 ```shell 155 grpcurl -plaintext \ 156 -d '{"tx_bytes":"Co8BCowBChwvY29zbW9zLmJhbmsudjFiZXRhMS5Nc2dTZW5kEmwKLWNvc21vczFsNnZzcWhoN3Jud3N5cjJreXozampnM3FkdWF6OGd3Z3lsODI3NRItY29zbW9zMTU4c2FsZHlnOHBteHU3Znd2dDBkNng3amVzd3A0Z3d5a2xrNnkzGgwKBXN0YWtlEgMxMDASBhIEEMCaDA=="}' \ 157 localhost:9090 \ 158 cosmos.tx.v1beta1.Service/TxDecode 159 ``` 160 161 Example Output: 162 163 ```json 164 { 165 "tx": { 166 "body": { 167 "messages": [ 168 {"@type":"/cosmos.bank.v1beta1.MsgSend","amount":[{"denom":"stake","amount":"100"}],"fromAddress":"cosmos1l6vsqhh7rnwsyr2kyz3jjg3qduaz8gwgyl8275","toAddress":"cosmos158saldyg8pmxu7fwvt0d6x7jeswp4gwyklk6y3"} 169 ] 170 }, 171 "authInfo": { 172 "fee": { 173 "gasLimit": "200000" 174 } 175 } 176 } 177 } 178 ``` 179 180 #### `TxEncode` 181 182 The `TxEncode` endpoint allows to encode a transaction. 183 184 ```shell 185 cosmos.tx.v1beta1.Service/TxEncode 186 ``` 187 188 Example: 189 190 ```shell 191 grpcurl -plaintext \ 192 -d '{"tx": { 193 "body": { 194 "messages": [ 195 {"@type":"/cosmos.bank.v1beta1.MsgSend","amount":[{"denom":"stake","amount":"100"}],"fromAddress":"cosmos1l6vsqhh7rnwsyr2kyz3jjg3qduaz8gwgyl8275","toAddress":"cosmos158saldyg8pmxu7fwvt0d6x7jeswp4gwyklk6y3"} 196 ] 197 }, 198 "authInfo": { 199 "fee": { 200 "gasLimit": "200000" 201 } 202 } 203 }}' \ 204 localhost:9090 \ 205 cosmos.tx.v1beta1.Service/TxEncode 206 ``` 207 208 Example Output: 209 210 ```json 211 { 212 "txBytes": "Co8BCowBChwvY29zbW9zLmJhbmsudjFiZXRhMS5Nc2dTZW5kEmwKLWNvc21vczFsNnZzcWhoN3Jud3N5cjJreXozampnM3FkdWF6OGd3Z3lsODI3NRItY29zbW9zMTU4c2FsZHlnOHBteHU3Znd2dDBkNng3amVzd3A0Z3d5a2xrNnkzGgwKBXN0YWtlEgMxMDASBhIEEMCaDA==" 213 } 214 ``` 215 216 #### `TxDecodeAmino` 217 218 The `TxDecode` endpoint allows to decode an amino transaction. 219 220 ```shell 221 cosmos.tx.v1beta1.Service/TxDecodeAmino 222 ``` 223 224 Example: 225 226 ```shell 227 grpcurl -plaintext \ 228 -d '{"amino_binary": "KCgWqQpvqKNhmgotY29zbW9zMXRzeno3cDJ6Z2Q3dnZrYWh5ZnJlNHduNXh5dTgwcnB0ZzZ2OWg1Ei1jb3Ntb3MxdHN6ejdwMnpnZDd2dmthaHlmcmU0d241eHl1ODBycHRnNnY5aDUaCwoFc3Rha2USAjEwEhEKCwoFc3Rha2USAjEwEMCaDCIGZm9vYmFy"}' \ 229 localhost:9090 \ 230 cosmos.tx.v1beta1.Service/TxDecodeAmino 231 ``` 232 233 Example Output: 234 235 ```json 236 { 237 "aminoJson": "{\"type\":\"cosmos-sdk/StdTx\",\"value\":{\"msg\":[{\"type\":\"cosmos-sdk/MsgSend\",\"value\":{\"from_address\":\"cosmos1tszz7p2zgd7vvkahyfre4wn5xyu80rptg6v9h5\",\"to_address\":\"cosmos1tszz7p2zgd7vvkahyfre4wn5xyu80rptg6v9h5\",\"amount\":[{\"denom\":\"stake\",\"amount\":\"10\"}]}}],\"fee\":{\"amount\":[{\"denom\":\"stake\",\"amount\":\"10\"}],\"gas\":\"200000\"},\"signatures\":null,\"memo\":\"foobar\",\"timeout_height\":\"0\"}}" 238 } 239 ``` 240 241 #### `TxEncodeAmino` 242 243 The `TxEncodeAmino` endpoint allows to encode an amino transaction. 244 245 ```shell 246 cosmos.tx.v1beta1.Service/TxEncodeAmino 247 ``` 248 249 Example: 250 251 ```shell 252 grpcurl -plaintext \ 253 -d '{"amino_json":"{\"type\":\"cosmos-sdk/StdTx\",\"value\":{\"msg\":[{\"type\":\"cosmos-sdk/MsgSend\",\"value\":{\"from_address\":\"cosmos1tszz7p2zgd7vvkahyfre4wn5xyu80rptg6v9h5\",\"to_address\":\"cosmos1tszz7p2zgd7vvkahyfre4wn5xyu80rptg6v9h5\",\"amount\":[{\"denom\":\"stake\",\"amount\":\"10\"}]}}],\"fee\":{\"amount\":[{\"denom\":\"stake\",\"amount\":\"10\"}],\"gas\":\"200000\"},\"signatures\":null,\"memo\":\"foobar\",\"timeout_height\":\"0\"}}"}' \ 254 localhost:9090 \ 255 cosmos.tx.v1beta1.Service/TxEncodeAmino 256 ``` 257 258 Example Output: 259 260 ```json 261 { 262 "amino_binary": "KCgWqQpvqKNhmgotY29zbW9zMXRzeno3cDJ6Z2Q3dnZrYWh5ZnJlNHduNXh5dTgwcnB0ZzZ2OWg1Ei1jb3Ntb3MxdHN6ejdwMnpnZDd2dmthaHlmcmU0d241eHl1ODBycHRnNnY5aDUaCwoFc3Rha2USAjEwEhEKCwoFc3Rha2USAjEwEMCaDCIGZm9vYmFy" 263 } 264 ```