12. Metadata
The runtime metadata structure contains all the information necessary on how to interact with the Polkadot runtime. Considering that Polkadot runtimes are upgradable and, therefore, any interfaces are subject to change, the metadata allows developers to structure any extrinsics or storage entries accordingly.
The metadata of a runtime is provided by a call to Metadata_metadata
(Section C.5.1.) and is returned as a scale encoded (Section A.2.2.) binary blob. How to interpret and decode this data is described in this chapter.
12.1. Structure
The Runtime Metadata is a data structure of the following format:
where
are the first four constant bytes, spelling "meta" in ASCII.
is an unsigned 8-bit integer indicating the format version of the metadata structure (currently the value of
14
).is a sequence (Definition 202) of type definitions (Definition 169).
is a sequence (Definition 202) of pallet metadata (Section 12.2.).
is the type Id (Definition 170) of the extrinsics.
is an unsigned 8-bit integer indicating the format version of the extrinsics (implying a possible breaking change).
is a sequence (Definition 202) of extrinsics metadata (Definition 180).
is the type Id (Definition 170) of the runtime.
Image 8. Metadata
Definition 169. Runtime Registry Type Entry
A registry entry contains information about a type in its portable form for serialization. The entry is a data structure of the following format:
where
is a compact integer indicating the identifier of the type.
is the path of the type, optional and based on the source file location. Encoded as a sequence (Definition 202) of strings.
is a sequence (Definition 202) of generic parameters (empty for non-generic types).
is the name string of the generic type parameter
is a Option type containing a type Id (Definition 170).
is the type definition (Definition 171).
is the documentation as sequence (Definition 202) of strings.
Image 9. Metadata Type
Definition 170. Runtime Type Id
The runtime type Id is a compact integer representing the index of the entry (Definition 169) in or of the runtime metadata structure (Section 12.1.), depending on context (starting at ).
Definition 171. Type Variant
The type definition is a varying datatype (Definition 198) and indicates all the possible types of encodable values a type can have.
where
is a sequence of the following format:
- is a field (Definition 172).
is a sequence of the following format:
- is a variant (Definition 173).
is a type Id (Definition 170).
is of the following format:
is an unsigned 32-bit integer indicating the length
is a type Id (Definition 170).
is a sequence (Definition 202) of type Ids (Definition 170).
is a varying datatype (Definition 198) of the following structure:
is a type Id (Definition 170).
is a data structure of the following format:
is a type Id (Definition 170) representing the bit store order (external reference)
is a type Id (Definition 170) the bit order type (external reference).
Image 10. Metadata Type Definition
Definition 172. Field
A field of a data structure of the following format:
where
is an Option type containing the string that indicates the field name.
is a type Id (Definition 170).
is an Option type containing a string that indicates the name of the type as it appears in the source code.
is a sequence of varying length containing strings of documentation.
Image 11. Metadata Type Fields
Definition 173. Variant
A struct variant of the following format:
where
is a string representing the name of the variant.
is a possible empty array of varying length containing field (Definition 172) elements.
is an unsigned 8-bit integer indicating the index of the variant.
is a sequence of strings containing the documentation.
Image 12. Metadata Type Variants
12.2. Pallet Metadata
All the metadata about a pallet, part of the main structure (Section 12.1.) and of the following format:
where
is a string representing the pallet name.
is an Option type containing the pallet storage metadata (Definition 174).
is an Option type (Definition 200) containing the type Id (Definition 170) of pallet calls.
is an Option type (Definition 200) containing the type Id (Definition 170) of pallet events.
is an Sequence (Definition 202) of all pallet constant metadata (Definition 179).
is an Option type (Definition 200) containing the type Id (Definition 170) of the pallet error.
is an unsigned 8-bit integer indicating the index of the pallet, which is used for encoding pallet events and calls.
Image 13. Metadata Pallet
Definition 174. Pallet Storage Metadata
The metadata about pallets storage.
where
is the string representing the common prefix used by all storage entries.
is an array of varying lengths containing elements of storage entries (Definition 175).
Definition 175. Storage Entry Metadata
The metadata about a pallets storage entry.
where
is the string representing the variable name of the storage entry.
is an enum type determining the storage entry modifier (Definition 176).
is the type of the value stored in the entry (Definition 177).
is a byte array containing the default value.
is an array of varying lengths of strings containing the documentation.
Image 14. Pallet Storage
Definition 176. Storage Entry Modifier
This might be incorrect and has to be reviewed.
The storage entry modifier is a varying datatype (Definition 198) and indicates how the storage entry is returned and how it behaves if the entry is not present.
where 0 indicates that the entry returns an Option type and therefore None if the storage entry is not present. 1 indicates that the entry returns the type with default value (in Definition 175) if the entry is not present.
Definition 177. Storage Entry Type
The type of the storage value is a varying datatype (Definition 198) that indicates how the entry is stored.
where , (key) and (value) are all of type Ids (Definition 170). is an array of varying length containing the storage hasher (Definition 178).
Image 15. Storage Definition
Definition 178. Storage Hasher
The hashing algorithm is used by storage maps.
Definition 179. Pallet Constants
The metadata about the pallets constants.
where
is a string representing the name of the pallet constant.
is the type Id (Definition 170) of the pallet constant.
is a byte array containing the value of the constant.
is an array of varying lengths containing a string with the documentation.
Image 16. Pallet Constant
12.3. Extrinsic Metadata
The metadata about a pallets extrinsics, part of the main structure (Section 12.1.) and of the following format:
Definition 180. Signed Extension Metadata
The metadata about the additional, signed data required to execute an extrinsic.
where
is a string representing the unique signed extension identifier, which may be different from the type name.
is a type Id (Definition 170) of the signed extension, with the data to be included in the extrinsic.
is the type Id (Definition 170) of the additional signed data, with the data to be included in the signed payload.