Constant queries will introduce you to the concepts behind the types and the interaction of the API with those types. The same concepts are implemented in the remainder of the API - the runtime constants is just the simplest starting point.
For some background: constants are values that are defined in the runtime and used as part of chain operations. These constants can be changed as part of an upgrade.
Since these are constants and defined by the metadata, it is not a call, but rather the values immediately available - as you'll see in subsequent sections, there is no need for
await on these, it immediately returns the type and value for you to work with.
There is some magic applied by the API. For instance, as the
createFee result is returned, the API knows the expected type and makes a
Balance object available, hence the
toNumber. This result mapping is consistent in retrieving constants, making queries or even sending transactions:
- when values are passed to the API, the API will convert whatever is provided into the correct type as required by the call
- when a value is retrieved, the API will provide an object of the correct type that wraps this value
From the last point, this means that a
Balance will be returned as a number object extending bn.js. In a later section we will go through a breakdown of all the commonly-used types and all the basics available on types.
In the next section we will take an initial dive into chain state and state queries, allowing the use of the API to retrieve information contained in the chain state.