Providing settings for client

Before connecting with Substrate network, you need to provide all required settings. Here is a settings class declaration:

data class SubstrateClientSettings(
    val rpcPath: String?,
    val rpcParams: Map<String, Any?>,
    val webSocketSecure: Boolean,
    val webSocketPath: String?,
    val webSocketParams: Map<String, Any?>,
    val webSocketPort: Int?,
    val runtimeMetadataUpdateTimeoutMs: Long,
    val namingPolicy: SubstrateClientNamingPolicy,
    val objectStorageFactory: ObjectStorageFactory

All nodes are different, and their configurations are different.

For a regular Kusama node by Parity (, you might provide rpcPath, rpcParams, webSocketPath, webSocketParams, webSocketPort as null. These will be fully ignored.

But for OnFinality nodes, with your own API key with RPC at<YOUR_KEY> and web socket as wss://<YOUR_KEY> you need to provide settings like that:

val onFinalitySettings = SubstrateClientSettings(
    rpcPath = "rpc",
    rpcParams = mapOf("apikey", "YOUR_KEY"),
    webSocketSecure = true,
    webSocketPath = "ws",
    webSocketParams = mapOf("apikey", "YOUR_KEY"),
    webSocketPort = null,
    runtimeMetadataUpdateTimeoutMs = yourTimeoutPreference,
    namingPolicy = yourNamingPolicyPreference,
    objectStorageFactory = yourObjectStoragePreference

Speaking of other parameters, runtimeMetadataUpdateTimeoutMs is delay in milliseconds (1 hour by default) which defines how often runtime metadata should be updated. Applicable only after your receive a runtime metadata at least once.

Naming policy is a enum:

enum class SubstrateClientNamingPolicy {

It is used in all services to match your outgoing requests. If you're sure that you can provide pallets, constants, storage, and functions names exactly as they're declared in metadata, feel free to apply NONE policy to avoid extra computation.

And the last, but not least is object storage factory, which is an interface:

interface ObjectStorageFactory {
    fun <T> make(): MutableStateFlow<T?>

This is used for storing a runtime metadata. You can provide whatever implementation you want to store metadata on disk, cache, database, and whatnot.

But for convenience we added simple implementation in memory factory, which simply creates Kotlin's MutableStateFlow from coroutines:

class InMemoryObjectStorageFactory: ObjectStorageFactory {
    override fun <T> make() = MutableStateFlow<T?>(null)

Last updated