API Reference
Summary of Protocol Flow
The following illustrates the flow when a Dapp calls methods like eth_requestAccounts
on a Web Wallet.
- The user clicks the "Connect" button on the dApp.
- The dApp uses
window.open
to open the wallet. - The wallet is opened and initialized.
- After initialization, the wallet sends a
webmax_ready
message. - After confirming initialization, the dApp sends a message like
eth_requestAccounts
. - The wallet displays the request to the user.
- The user checks and approves the request.
- The wallet sends a response.
- The dApp receives the response and may close the Window.
Message Format
Extended JSON-RPC
Many wallets for blockchains like Ethereum provide their operations as JSON-RPC methods. Based on these, we define a message format that inherits from JSON-RPC as follows.
export type AbstractRequest<NS extends string = string, Params = unknown> = {
id: number;
namespace: NS | ChainedNamespace<NS>;
method: string;
params: Params;
metadata?: unknown;
};
export type AbstractSuccessResponse<NS extends string = string, Result = unknown> = {
id: number;
namespace: NS | ChainedNamespace<NS>;
method: string;
windowHandling: WindowHandling;
result: Result;
};
export type AbstractErrorResponse<NS extends string = string> = {
id: number;
namespace: NS | ChainedNamespace<NS>;
method: string;
windowHandling: WindowHandling;
error: { code: number; message: string };
};
export type AbstractResponse<NS extends string = string, Result = unknown> =
| AbstractSuccessResponse<NS, Result>
| AbstractErrorResponse<NS>;
Namespace
Each method requires a Namespace, defining the group of methods. The Namespace must be included in each request, and it can also include ChainID information.
type ChainId = string | number;
type Namespace = "eip155" | "webmax";
type ChainedNamespace = `${Namespace}:${ChainId}`;
Window Handling: Specifies how to handle the Wallet's Window after sending a response. This is useful, for example, when the wallet wants to display an error message.
type WindowHandling = "keep" | "close";