sdk.Msg
objects represented as Any
types, the transactions must be encoded as bytes within InterchainAccountPacketData
.
data
field must be encoded as a CosmosTx
.
CosmosTx
is determined during the channel handshake process. If the channel version metadata’s encoding
field is marked as proto3
, then CosmosTx
undergoes protobuf encoding. Conversely, if the field is set to proto3json
, then proto3 json encoding takes place, which generates a JSON representation of the protobuf message.
Protobuf Encoding
Protobuf encoding serves as the standard encoding process forCosmosTx
. This occurs if the channel handshake initiates with an empty channel version metadata or if the encoding
field explicitly denotes proto3
. In Golang, the protobuf encoding procedure utilizes the proto.Marshal
function. Every protobuf autogenerated Golang type comes equipped with a Marshal
method that can be employed to encode the message.
(Protobuf) JSON Encoding
The proto3 JSON encoding presents an alternative encoding technique forCosmosTx
. It is selected if the channel handshake begins with the channel version metadata encoding
field labeled as proto3json
. In Golang, the Proto3 canonical encoding in JSON is implemented by the "github.com/cosmos/gogoproto/jsonpb"
package. Within Cosmos SDK, the ProtoCodec
structure implements the JSONCodec
interface, leveraging the jsonpb
package. This method generates a JSON format as follows:
"messages"
array is populated with transactions. Each transaction is represented as a JSON object with the @type
field denoting the transaction type and the remaining fields representing the transaction’s attributes.