Skip to content

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 throws RpcException. See the executing methods guide for task-oriented examples.

suspend inline fun <reified T> execute(
contextId: String,
method: String,
argsJson: JsonObject = JsonObject(emptyMap()),
executorPublicKey: String? = null,
): T

Calls method on the application in contextId and decodes result.output into T with kotlinx.serialization. A non-reified overload taking an explicit DeserializationStrategy<T> is also available.

@Serializable data class Post(val id: String, val title: String)
val post: Post = mero.rpc.execute(
contextId = contextId,
method = "get_post",
argsJson = buildJsonObject { put("id", "42") },
)
suspend fun executeRaw(
contextId: String, method: String,
argsJson: JsonObject = JsonObject(emptyMap()), executorPublicKey: String? = null,
): JsonElement

Returns the undecoded result.output as a JsonElement — use it when you don’t have (or don’t want) a typed result.

suspend fun migrateMyEntries(contextId: String): MigrateMyEntriesSummary
@Serializable data class MigrateMyEntriesSummary(
val converted: Int, // entries re-signed this call
val remaining: Int, // still below the target schema
)

Owner-driven migration: re-signs the caller’s identity-gated entries to the current schema in a single sweep (it does not loop).

suspend fun countMyPending(contextId: String): Int

Read-only count of the caller’s entries still below the target schema.

if (mero.rpc.countMyPending(contextId) > 0) mero.rpc.migrateMyEntries(contextId)