# Encoding

Learn about the encoding formats used on Haqq.

# Pre-requisite Readings

# Encoding Formats

# Protocol Buffers

The Cosmos Stargate (opens new window) release introduces protobuf (opens new window) as the main encoding format for both client and state serialization. All the EVM module types that are used for state and clients (transaction messages, genesis, query services, etc) will be implemented as protocol buffer messages.

# Amino

The Cosmos SDK also supports the legacy Amino encoding format for backwards compatibility with previous versions, specially for client encoding and signing with Ledger devices. Haqq does not support Amino in the EVM module, but it is supported for all other Cosmos SDK modules that enable it.

# RLP

Recursive Length Prefix (RLP (opens new window)), is an encoding/decoding algorithm that serializes a message and allows for quick reconstruction of encoded data. Haqq uses RLP to encode/decode Ethereum messages for JSON-RPC handling to conform messages to the proper Ethereum format. This allows messages to be encoded and decoded in the exact format as Ethereum's.

The x/evm transactions (MsgEthereumTx) encoding is performed by casting the message to a go-ethereum's Transaction and then marshaling the transaction data using RLP:

Copy // TxEncoder overwrites sdk.TxEncoder to support MsgEthereumTx func (g txConfig) TxEncoder() sdk.TxEncoder { return func(tx sdk.Tx) ([]byte, error) { msg, ok := tx.(*evmtypes.MsgEthereumTx) if ok { return msg.AsTransaction().MarshalBinary() } return g.TxConfig.TxEncoder()(tx) } } // TxDecoder overwrites sdk.TxDecoder to support MsgEthereumTx func (g txConfig) TxDecoder() sdk.TxDecoder { return func(txBytes []byte) (sdk.Tx, error) { tx := &ethtypes.Transaction{} err := tx.UnmarshalBinary(txBytes) if err == nil { msg := &evmtypes.MsgEthereumTx{} msg.FromEthereumTx(tx) return msg, nil } return g.TxConfig.TxDecoder()(txBytes) } }

# Next

Learn how pending state is handled on Haqq.