SCALE Encoding

Substrate uses a lightweight and efficient encoding and decoding program to optimize how data is sent and received over the network. The program used to serialize and deserialize data is called the SCALE codec, with SCALE being an acronym for simple concatenated aggregate little-endian.

The SCALE codec is a critical component for communication between the runtime and the outer node.

It is designed for high-performance, copy-free encoding and decoding of data in resource-constrained execution environments like the Substrate WebAssembly runtime.

The SCALE codec is not self-describing in any way. It assumes the decoding context has all type knowledge about the encoded data. Front-end libraries maintained by Parity use the parity-scale-codec crate—which is a Rust implementation of the SCALE codec—to encode and decode interactions between RPCs and the runtime.

SCALE codec is advantageous for Substrate and blockchain systems because:

  • It is lightweight relative to generic serialization frameworks like serde, which add significant boilerplate that can bloat the size of the binary.

  • It does not use Rust libstd making it compatible with no_std environments that compile to Wasm, such as the Substrate runtime.

  • It is built to have great support in Rust for deriving codec logic for new types using: #[derive(Encode, Decode)].

It's important to define the encoding scheme used in Substrate rather than reuse an existing Rust codec library because this codec needs to be re-implemented on other platforms and languages that want to support interoperability among Substrate blockchains.

The following table shows how the Rust implementation of the Parity SCALE codec encodes different types.

SCALE codec examples of different types

SCALE Codec has been implemented in other languages, including:

Last updated