System module

The system module has nothing more than just runtime version and getting account details. But for your convenience we've added a huge list for all possible account retrieval options:

public protocol SystemModule: AnyObject {
    func runtimeVersion() async throws -> RuntimeVersion?
    func account(accountId: AccountId) async throws -> Account?
    func account(accountIdHex: String) async throws -> Account?
    func account(publicKey: Data) async throws -> Account?
    func account(publicKeyHex: String) async throws -> Account?
    func account(keyPair: KeyPair) async throws -> Account?
}

Runtime version

Runtime version is declared like this:

public struct RuntimeVersion: Codable {
    public let specName: String
    public let implName: String
    public let authoringVersion: Index
    public let specVersion: Index
    public let implVersion: Index
    public let apis: [RuntimeVersionApi]
    public let txVersion: Index
    public let stateVersion: UInt8
}

public struct RuntimeVersionApi: Codable {
    @Array8 public var id: [UInt8]
    public let index: Index
}

Index is a dynamic type, and you can read more about this here.

And to get runtime version, it's simple as that:

let client: SubstrateClient
let metadata = try await client.modules.system.runtimeVersion()

Account details

You can take a look at Account details struct below:

public struct Account: Codable {
    public let nonce: Index
    public let consumers: Index
    public let providers: Index
    public let sufficients: Index
    public let data: AccountData
    
    public struct AccountData: Codable {
        public let free: Balance
        public let reserved: Balance
        public let miscFrozen: Balance
        public let feeFrozen: Balance
    }
}

In addition to Index, here you can find Balance type, which is also another dynamic type.

So here are all examples of how to get account details using different approaches:

let client: SubstrateClient

let keyPair: KeyPair
let account: Account? = try await client.modules.system.account(keyPair: keyPair)

let publicKey = keyPair.publicKey
let account: Account? = try await client.modules.system.account(publicKey: publicKey)
let account: Account? = try await client.modules.system.account(publicKeyHex: publicKey.hex.encode())

let accountId: AccountId = try publicKey.ss58.accountId()
let account: Account? = try await client.modules.system.account(accountId: accountId)
let account1: Account? = try await client.modules.system.account(accountIdHex: accountId.hex.encode())

Last updated