The request method allows apps to make Ethereum RPC requests to the wallet.

Specification

interface RequestArguments {
  readonly method: string;
  readonly params?: readonly unknown[] | object;
}

interface ProviderRpcError extends Error {
  message: string;
  code: number;
  data?: unknown;
}

interface ProviderInterface {
  /**
   * @param {RequestArguments} args request arguments.
   * @returns A promise that resolves with the result.
   * @throws {ProviderRpcError} in case of error.
   */
  request(args: RequestArguments): Promise<unknown>;
  disconnect(): Promise<void>;
  emit<K extends keyof ProviderEventMap>(event: K, ...args: [ProviderEventMap[K]]): boolean;
  on<K extends keyof ProviderEventMap>(event: K, listener: (_: ProviderEventMap[K]) => void): this;
}

type CreateProviderOptions = Partial<AppMetadata> & {
  preference?: Preference;
  subAccounts?: Omit<SubAccountOptions, 'enableAutoSubAccounts'>;
  paymasterUrls?: Record<number, string>;
};

interface BaseAccountSDK {
  getProvider(): ProviderInterface;
  subAccount: {
    create(account: AddSubAccountAccount): Promise<SubAccount>;
    get(): Promise<SubAccount | null>;
    addOwner(params: { address?: `0x${string}`; publicKey?: `0x${string}`; chainId: number }): Promise<string>;
    setToOwnerAccount(toSubAccountOwner: ToOwnerAccountFn): void;
  };
}

Example

import {provider} from "./setup";

const addresses = await provider.request({method: 'eth_requestAccounts'});
const txHash = await provider.request({
    method: 'eth_sendTransaction',
    params: [{from: addresses[0], to: addresses[0], value: 1}]
  }
);

Request Handling

Requests are handled in one of three ways
  1. Sent to the Wallet application (Wallet mobile app, extension, or popup window).
  2. Handled locally by the SDK.
  3. Passed onto default RPC provider for the given chain, if it exists.

1. Sent to the Wallet application

The following RPC requests are sent to the Wallet application:

2. Handled Locally by the SDK

The following requests are handled locally by the SDK, with no external calls:

3. Passed to RPC Provider

Standard Ethereum RPC methods are passed to the configured RPC provider for the current chain, including: