Executing Methods
sdk.rpc executes methods on the WASM application running inside a context. It
speaks JSON-RPC to the node’s /jsonrpc endpoint and hands you back the method’s
decoded return value.
Execute a method
Section titled “Execute a method”const value = await sdk.rpc.execute<{ value: string }>({ contextId: 'ctx-id', method: 'get_value', argsJson: { key: 'hello' },});contextId— the context to run in.method— the contract method name.argsJson— an object of named arguments (optional; omit for none).- The type parameter
Ttypes the decoded return value;executeunwraps the JSON-RPC envelope and returnsresult.output.
Handling contract errors
Section titled “Handling contract errors”When the WASM method returns a JSON-RPC error, execute throws an RpcError:
import { RpcError } from '@calimero-network/mero-js';
try { await sdk.rpc.execute({ contextId, method: 'transfer', argsJson: { to, amount } });} catch (err) { if (err instanceof RpcError) { console.error(`Contract error ${err.code}: ${err.message}`); console.error('type:', err.type); // optional error type from the contract console.error('data:', err.data); // optional structured payload } throw err;}RpcError carries the numeric code, the human-readable message, and optional
type/data from the contract. Transport failures (HTTP 4xx/5xx, timeouts) are
not RpcError — see the error model for the full
picture.
Migration helpers
Section titled “Migration helpers”Two convenience wrappers over execute support the entry-migration flow (used
when an application upgrades its state schema):
// Convert this identity's entries to the current schema.const { converted, remaining } = await sdk.rpc.migrateMyEntries(contextId);
// How many of my entries are still pending migration?const pending = await sdk.rpc.countMyPending(contextId);Typing tips
Section titled “Typing tips”Give execute the shape you expect back so call sites are type-checked:
interface Message { id: string; author: string; text: string }
const messages = await sdk.rpc.execute<Message[]>({ contextId, method: 'list_messages', argsJson: { limit: 50 },});// messages: Message[]If you don’t pass a type, the return is unknown — narrow it before use.