[SNIP] Check Support for Starknet Provider JavaScript API

Simple Summary

Two methods of the JavaScript API to ensure support of specific RPC methods and events.

Abstract

Dapps want to use a single JavaScript API to interact with different wallet providers.

A “Starknet Provider JavaScript API” was proposed to define a common API that wallet providers could use.
Nevertheless, those providers may have a different level of development, and may not support all the RPC methods and events defined in the different SIMPs.

Two methods may be implemented to ensure a RPC method is supported by the current wallet provider (supportRequest) and to ensure an event is supported (supportEvent).

Specification

The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in this document are to be interpreted as described in RFC-2119.

supportRequest

This method supportRequest take the name of the RPC method as a parameter and returns true if the RPC method is supported by the current wallet provider.

  • The method MUST return a boolean.
  • If no parameters are given or if it is not a string, the method MUST simply return false.
  • If the RPC method is not supported by the current wallet provider, the method MUST return false.

Here is an example of how to use the method:

const isWatchAssetSupported: boolean = Provider.supportRequest("wallet_watchAsset");

supportEvent

This method take the name of an event as a parameter and returns true if the event is supported by the current wallet provider.

  • The method MUST return a boolean.
  • If no parameters are given or if it is not a string, the method MUST simply return false.
  • If the event is not supported by the current wallet provider, the method MUST return false.

Here is an example of how to use the method:

const isDisconnectEventSupported: boolean = Provider.supportEvent("chainChanged");

Appendix

Appendix I

New methods to add to WalletProviderInterface

interface WalletProviderInterface {
  ...
  supportRequest: (request: string) => boolean;
  supportEvent: (event: string) => boolean;
}
22 Likes