Skip to main content

Provider

The Provider module handles communication with Moki nodes via JSON-RPC.

Functions​

createProvider​

Creates a provider instance for communicating with a Moki node.

function createProvider(rpcUrl: string): MokiProvider

Parameters​

  • rpcUrl: string - URL of the Moki RPC node

Returns​

MokiProvider instance

Example​

import { createProvider } from '@moki-chat/core/provider'

const provider = createProvider("https://moki-node.pingify.io")

Provider Methods​

request​

Makes an RPC request to the Moki node.

const result = await provider.request<ReturnType>({
method: MOKI_RPC_METHODS.ETH_GET_BLOCK,
params: [],
authorizationHeader: "0x..." // Optional
})

Parameters​

  • method: MOKI_RPC_METHODS - The RPC method to call
  • params: unknown[] - Array of parameters for the method (optional)
  • authorizationHeader: 0x${string} - Authorization signature (required for some methods)

Returns​

Promise resolving to the method's return value (type T)

Usage Examples​

Basic Provider Setup​

import { createProvider } from '@moki-chat/core/provider'

const provider = createProvider("https://moki-node.pingify.io")

Looking Up an Identity​

const identity = await provider.request({
method: MOKI_RPC_METHODS.MOKI_GET_IDENTITY_BY_USERNAME,
params: ["alice"]
})

console.log(identity) // MokiRPCIdentity object