-
Notifications
You must be signed in to change notification settings - Fork 128
/
types.ts
47 lines (40 loc) · 1.43 KB
/
types.ts
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
export interface ProviderRpcError extends Error {
message: string;
code: number;
data?: unknown;
}
export interface ProviderMessage {
type: string;
data: unknown;
}
export interface ProviderInfo {
chainId: string;
}
export interface RequestArguments {
method: string;
params?: unknown[] | Record<string, unknown>;
}
export type ProviderChainId = string;
export type ProviderAccounts = string[];
export interface SimpleEventEmitter {
on(event: string, listener: (...args: any[]) => void): void;
once(event: string, listener: (...args: any[]) => void): void;
removeListener(event: string, listener: (...args: any[]) => void): void;
off(event: string, listener: (...args: any[]) => void): void;
}
export interface EIP1193Provider extends SimpleEventEmitter {
connect(params?: any): Promise<void>;
disconnect(): Promise<void>;
// connection event
on(event: 'connect', listener: (info: ProviderInfo) => void): void;
// disconnection event
on(event: 'disconnect', listener: (error: ProviderRpcError) => void): void;
// arbitrary messages
on(event: 'message', listener: (message: ProviderMessage) => void): void;
// chain changed event
on(event: 'chainChanged', listener: (chainId: ProviderChainId) => void): void;
// accounts changed event
on(event: 'accountsChanged', listener: (accounts: ProviderAccounts) => void): void;
// make an Ethereum RPC method call.
request(args: RequestArguments): Promise<unknown>;
}