RPC client
mero.rpc (RpcClient) calls the methods a context’s WASM application exposes,
over the node’s /jsonrpc endpoint. It shares the SDK’s transport, so
authentication, refresh, and the error model apply. A
contract-level failure surfaces as MeroError.rpc(RpcError).
See the executing methods guide for task-oriented examples.
execute<T: Decodable>(...)
Section titled “execute<T: Decodable>(...)”func execute<T: Decodable>( contextId: String, method: String, argsJson: [String: JSONValue] = [:]) async throws -> TCalls method on the application in contextId and decodes result.output
into T. argsJson is a [String: JSONValue] map (JSONValue is
ExpressibleBy…Literal, so ["id": "42", "n": 3] works). A JSON-RPC error
object is mapped to MeroError.rpc(RpcError).
struct Post: Decodable { let id: String; let title: String }
let post: Post = try await mero.rpc.execute( contextId: contextId, method: "get_post", argsJson: ["id": "42"])migrateMyEntries(_ contextId:) -> MigrateMyEntriesSummary
Section titled “migrateMyEntries(_ contextId:) -> MigrateMyEntriesSummary”Owner-driven migration: re-signs the caller’s identity-gated entries to the current schema in a single sweep (it does not loop). Returns the counts.
public struct MigrateMyEntriesSummary: Codable, Sendable, Equatable { public let converted: Int // entries re-signed this call public let remaining: Int // still below the target schema}
let summary = try await mero.rpc.migrateMyEntries(contextId)executeWithMetadata<T>(...) -> RpcExecuteResult<T>
Section titled “executeWithMetadata<T>(...) -> RpcExecuteResult<T>”The same call as execute, returning { returns, transport } with transport
always .node. It mirrors mero-js’s transport-agnostic shape.
let result: RpcExecuteResult<Int> = try await mero.rpc.executeWithMetadata( contextId: contextId, method: "get")Refusals since core rc.83
Section titled “Refusals since core rc.83”- An execute needs
context:executein a scoped token (oradmin). - An account-authenticated session cannot execute; it writes through a warranted
intent (
mero.admin.performIntent). - A node whose role in the context is read-only answers
{"type":"ReadOnlyWriteRefused","data":{"context_id":...}}. CheckrpcError.isReadOnlyWriteRefusedand send the write elsewhere.
countMyPending(_ contextId:) -> Int
Section titled “countMyPending(_ contextId:) -> Int”Read-only count of the caller’s entries still below the target schema — decide whether to migrate, or show progress.
let pending = try await mero.rpc.countMyPending(contextId)if pending > 0 { _ = try await mero.rpc.migrateMyEntries(contextId) }