Skip to content

Instantly share code, notes, and snippets.

@pedrouid
Last active December 13, 2020 11:35
Show Gist options
  • Save pedrouid/99efba3e1c8780a6351f1e26c1c117d1 to your computer and use it in GitHub Desktop.
Save pedrouid/99efba3e1c8780a6351f1e26c1c117d1 to your computer and use it in GitHub Desktop.
CAIP-XX: JSON-RPC Provider API Specification

Multi-Chain JSON-RPC Provider API Specification

Multi-chain provider would require primarly two main methods to interface with a multi-chain cryptocurrency wallet: enable and request.

Enable Method

Enable method would translate the same JSON-RPC parameters of CAIP-25 as Javascript arguments

CAIP-25 Request

interface CAIP25Request {
  id: number;
  jsonrpc: "2.0";
  method: "caip_handshake";
  params: {
    chains: string[];
    methods: string[];
  };
}

CAIP-25 Response

interface CAIP25Response {
  id: number;
  jsonrpc: "2.0";
  result: {
    accounts: string[];
  };
}

Enable JS Interface

interface CAIPXXProvider {
  enable(chains: string[], methods: string[]): Promise<string[]>;
}

Request Method

Request method would translate the same JSON-RPC parameters of CAIP-27 as Javascript arguments

CAIP-27 Request

interface CAIP27Request {
  id: number;
  jsonrpc: "2.0";
  method: "caip_request";
  params: {
    chainId: string;
    request: {
      method: string;
      params: any;
    };
  };
}

CAIP-27 Response

interface CAIP27Response {
  id: number;
  jsonrpc: "2.0";
  result: any;
}

Request JS Interface

interface CAIPXXProvider {
  request(chainId: string, request: { method: string; params: any }): Promise<string[]>;
}

Multi-Chain JSON-RPC Provider API

interface CAIPXXProvider {
  enable(chains: string[], methods: string[]): Promise<string[]>;
  request(chainId: string, request: JsonRpcRequest): Promise<string[]>;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment