Lookup Service

Lookup service is the entry point for every of our services to find exact indexes in order to form requests in a proper way.

Here is its protocol:

public protocol SubstrateLookup: AnyObject {
    func findRuntimeItem(index: BigUInt) async throws -> RuntimeType?
    func findRuntimeType(index: BigUInt) async throws -> RuntimeType?
    func module(name: String) async throws -> RuntimeModule?
    func findConstant(
        moduleName: String,
        constantName: String
    ) async throws -> RuntimeModuleConstant?
    func findStorageItem(
        moduleName: String,
        itemName: String
    ) async throws -> FindStorageItemResult?

Everything is returned via async-await because runtime metadata is considered as endless flow, even though it's supposed to be updated only like once a minute by default. This might be useful if you want to automatically update values on some constants, or storage values to display on your mobile (or not so mobile) application.

To access lookup service simply use this:

let client: SubstrateClient
let lookupService: SubstrateLookup = client.lookup


As per our library, modules are defined this way:

public class RuntimeModule: Codable {
    public let name: String
    public let storage: RuntimeModuleStorage?
    public let callIndex: BigUInt?
    public let eventsIndex: BigUInt?
    public let constants: [RuntimeModuleConstant]
    public let errorsIndex: BigUInt?
    public let index: UInt8

This is the core runtime metadata's component, which we rely on for most of our logic.

You're free to use this as much as you want to create your special behavior.


Constants is the one of the parts of each module/pallet. It's absolutely the same as in Substrate:

public class RuntimeModuleConstant: Codable {
    public let name: String
    public let type: BigUInt
    public let valueBytes: [UInt8]
    public let docs: [String]

Name is the name which you just provided in search, type is its index in metadata, and value as described above: byte representation in SCALE coding of value in it.

Still, play with this as much as you want. But we strongly encourage using our constants service directly.


Same, as for constants, it's better to use our storage service in case if you want to get actual values. But if you have specific needs, don't hesitate to use it in whatever way you want. Here is its declaration:

public class RuntimeModuleStorage: Codable {
    public let prefix: String
    public let items: [RuntimeModuleStorageItem]

You can go deeper to analyze its contents, at least its storage item subtype:

public class RuntimeModuleStorageItem: Codable {
    public let name: String
    public let modifier: RuntimeModuleStorageItemModifier
    public let type: RuntimeModuleStorageItemType
    public var fallbackBytes: [UInt8]
    public let docs: [String]

At least for getting names of these items. But storage key generation for RPC calls is not the easiest thing, so again, our storage service is your very best friend here.

Runtime types resolving

If you want to get the declaration of exact type by its index you can definitely use findRuntimeType method. It has a long list of subtypes, so if you really want to dive so deep, please look at this at our API reference website.

Last updated