1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { EthEvents, EthMethods } from '../enums';
export interface EthChainParams {
chainId: string; // A 0x-prefixed hexadecimal string
chainName: string;
nativeCurrency: {
name: string;
symbol: string; // 2-6 characters long
decimals: number; // 18
};
rpcUrls: string[];
blockExplorerUrls?: string[];
iconUrls?: string[]; // Currently ignored.
}
export interface ConnectInfo {
chainId: string;
}
export interface ProviderMessage {
data: unknown;
type: string;
}
export interface ProviderRpcError extends Error {
code: number;
data?: unknown;
message: string;
}
export interface RequestArguments {
method: EthMethods | string;
params?: unknown[] | Record<string, unknown>;
}
export interface Ethereum {
isMetaMask: boolean;
selectedAddress: string;
chainId: string;
enable(): Promise<unknown>;
isConnected(): boolean;
on(eventName: EthEvents.AccountsChanged, handler: (accounts: string[]) => void): void;
on(eventName: EthEvents.ChainChanged, handler: (chainId: string) => void): void;
on(eventName: EthEvents.Connect, handler: (connectInfo: ConnectInfo) => void): void;
on(eventName: EthEvents.Disconnect, handler: (error: ProviderRpcError) => void): void;
on(eventName: EthEvents.Message, handler: (message: ProviderMessage) => void): void;
request<T = any>(args: RequestArguments): Promise<T>;
}