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 datastructure 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 192) of type definitions (Definition 159).
is a sequence (Definition 192) of pallet metadata (Section 12.2.).
is the type Id (Definition 160) 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 192) of extrinsics metadata (Definition 170).
is the type Id (Definition 160) of the runtime.
Image 8. Metadata
Definition 159. Runtime Registry Type Entry
A registry entry contains information about a type in its portable form for serialization. The entry is a datastructure 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 source file location. Encoded as a sequence (Definition 192) of strings.
is a sequence (Definition 192) 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 160).
is the type definition (Definition 161).
is the documentation as sequence (Definition 192) of strings.
Image 9. Metadata Type
Definition 160. Runtime Type Id
The runtime type Id is a compact integer representing the index of the entry (Definition 159) in or of the runtime metadata structure (Section 12.1.), depending on context (starting at ).
Definition 161. Type Variant
The type definition is a varying datatype (Definition 188) 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 162).
is a sequence of the following format:
- is a variant (Definition 163).
is a type Id (Definition 160).
is of the following format:
is a unsigned 32-bit integer indicating the length
is a type Id (Definition 160).
is a sequence (Definition 192) of type Ids (Definition 160).
is a varying datatype (Definition 188) of the following structure:
is a type Id (Definition 160).
is a datastructure of the following format:
is a type Id (Definition 160) representing the bit store order (external reference)
is a type Id (Definition 160) the bit order type (external reference).
Image 10. Metadata Type Definition
Definition 162. Field
A field of a datastructure of the following format:
where
is an Option type containing the string that indicates the field name.
is a type Id (Definition 160).
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 163. 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 162) 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 164).
is an Option type (Definition 190) containing the type Id (Definition 160) of pallet calls.
is an Option type (Definition 190) containing the type Id (Definition 160) of pallet events.
is an Sequence (Definition 192) of all pallet constant metadata (Definition 169).
is an Option type (Definition 190) containing the type Id (Definition 160) of the pallet error.
is an unsigned 8-bit integers indicating the index of the pallet, which is used for encoding pallet events and calls.
Image 13. Metadata Pallet
Definition 164. Pallet Storage Metadata
The metadata about a pallets storage.
where
is the string representing the common prefix used by all storage entries.
is an array of varying length containing elements of storage entries (Definition 165).
Definition 165. 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 166).
is the type of the value stored in the entry (Definition 167).
is an byte array containing the default value.
is an array of varying length of strings containing the documentation.
Image 14. Pallet Storage
Definition 166. Storage Entry Modifier
This might be incorrect and has to be reviewed.
The storage entry modifier is a varying datatype (Definition 188) 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 165) if the entry is not present.
Definition 167. Storage Entry Type
The type of the storage value is a varying datatype (Definition 188) that indicates how the entry is stored.
where , (key) and (value) are all of type Ids (Definition 160). is an array of varying length containing the storage hasher (Definition 168).
Image 15. Storage Definition
Definition 168. Storage Hasher
The hashing algorithm used by storage maps.
Definition 169. Pallet Constants
The metadata about the pallets constants.
where
is a string representing the name of the pallet constant.
is the type Id (Definition 160) of the pallet constant.
is a byte array containing the value of the constant.
is an array of varying length containing 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 170. 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 160) of the signed extension, with the data to be included in the extrinsic.
is the type Id (Definition 160) of the additional signed data, with the data to be included in the signed payload.