diff --git a/docs/pages/typed/constants.md b/docs/pages/typed/constants.md new file mode 100644 index 00000000..0e71ad25 --- /dev/null +++ b/docs/pages/typed/constants.md @@ -0,0 +1,17 @@ +# Constants + +Constants are the simplest structure that we find inside the `TypedApi`. Constants are hard-coded key-value pairs that are embedded in the runtime metadata. In PAPI their structure is just a simple function that return its decoded value, with two alternatives. As explained in [the previous section](/typed) for `isCompatible`, we have two options to get the value: + +- Promise-based call, without passing the runtime +- Synchronous return, passing the runtime previously awaited for + +Let's use `typedApi.constants.System.Version`. See in this example how it's used: + +```ts +// in this case the function is asynchronous +const versionAsync = await typedApi.constants.System.Version() + +const runtime = await typedApi.runtime.latest() // we already learnt about it! +// in this case it's sync +const versionSync = typedApi.constants.System.Version(runtime) +``` diff --git a/vocs.config.tsx b/vocs.config.tsx index 2b2e52b0..049517be 100644 --- a/vocs.config.tsx +++ b/vocs.config.tsx @@ -26,6 +26,10 @@ export default defineConfig({ text: "Typed API", link: "/typed", items: [ + { + text: "Constants", + link: "/typed/constants", + }, { text: "Storage queries", link: "/typed/queries",