Skip to content

Proto Encoder

Helper that includes all the needed interfaces to decode the proto messages included inside the cosmos transactions.

Decode proto messages

To decode a proto message you just need to instantiate your message object and directly use the Encoder object from the codec package.

var m authz.MsgExec
err := codec.Encoder.Unmarshal(value, &m)

Decode a complete transaction

To convert the bytes from a transaction to the proto objects, the BytesToTx function is included in the codec package.

tx, err := codec.BytesToTx(txBytes)

Transaction From the Rest API

If you go the transaction using the Rest endpoint, it will be encoded in base64, the function Base64ToTx can consume that format directly.

tx, err := codec.Base64ToTx(txInBase64)

Convert a Cosmos Transaction to Ethereum Transaction

When the Ethereum transaction was received using the cosmos endpoints, it will be wrapped inside a protobuf any object.

The protobuf object needs to unmarshalled to read the signed Ethereum transaction info.

The ConvertEvmosTxToEthTx can be used to convert the protobuf object to an Ethereum transaction.

tx, err := codec.ConvertEvmosTxToEthTx(txInBase64)
if err != nil{
    return err
}
txHash, err := tx.Hash().Hex()