This repository was archived by the owner on Mar 22, 2023. It is now read-only.
forked from MetaMask/providers
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.d.ts
More file actions
142 lines (114 loc) · 3.86 KB
/
index.d.ts
File metadata and controls
142 lines (114 loc) · 3.86 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// You may have to bring your own Node types (e.g. @types/node) for these imports.
import { EventEmitter } from 'events';
import { Duplex } from 'stream';
import { JsonRpcRequest, JsonRpcResponse } from 'json-rpc-engine';
export interface MetaMaskInpageProviderOptions {
/**
* The name of the stream used to connect to the wallet.
*/
jsonRpcStreamName?: string;
/**
* The logging API to use.
*/
logger?: Pick<Console, 'log' | 'warn' | 'error' | 'debug' | 'info' | 'trace'>;
/**
* The maximum number of event listeners.
*/
maxEventListeners?: number;
/**
* Whether the provider should send page metadata.
*/
shouldSendMetadata?: boolean;
}
export class MetaMaskInpageProvider extends EventEmitter {
/**
* @param connectionStream - A Node.js duplex stream.
* @param options - An options bag.
*/
constructor(connectionStream: Duplex, options?: MetaMaskInpageProviderOptions);
/**
* Returns whether the provider can process RPC requests.
*/
isConnected(): boolean;
/**
* Submits an RPC request for the given method, with the given params.
* Resolves with the result of the method call, or rejects on error.
*/
request(args: RequestArguments): Promise<unknown>;
/**
* Submits an RPC request per the given JSON-RPC request object.
*/
sendAsync(
payload: JsonRpcRequest<unknown>,
callback: (error: Error | null, result?: JsonRpcResponse<unknown>) => void,
): void;
/**
* Submits an RPC request for the given method, with the given params.
* @deprecated Use {@link request} instead.
*/
send(method: string, params?: unknown[]): Promise<JsonRpcResponse<unknown>>;
/**
* Submits an RPC request per the given JSON-RPC request object.
* @deprecated Use {@link request} instead.
*/
send(
payload: JsonRpcRequest<unknown>,
callback: (error: Error | null, result?: JsonRpcResponse<unknown>) => void,
): void;
/**
* Accepts a JSON-RPC request object, and synchronously returns the cached result
* for the given method. Only supports 4 specific methods.
* @deprecated Use {@link request} instead.
*/
send(payload: SendSyncJsonRpcRequest): JsonRpcResponse<unknown>;
readonly isMetaMask: true;
readonly selectedAddress: string | null;
readonly networkVersion: string | null;
readonly chainId: string | undefined;
}
interface InitializeProviderOptions extends MetaMaskInpageProviderOptions {
/**
* The stream used to connect to the wallet.
*/
connectionStream: Duplex;
/**
* Whether the provider should be set as window.ethereum.
*/
shouldSetOnWindow?: boolean;
/**
* Whether the window.web3 shim should be set.
*/
shouldShimWeb3?: boolean;
}
/**
* Initializes a MetaMaskInpageProvider and (optionally) assigns it as window.ethereum.
*
* @returns The initialized provider (whether set or not).
*/
export function initializeProvider(
options: InitializeProviderOptions,
): MetaMaskInpageProvider;
/**
* Sets the given provider instance as window.ethereum and dispatches
* the 'ethereum#initialized' event on window.
*
* @param providerInstance - The provider instance.
*/
export function setGlobalProvider(providerInstance: MetaMaskInpageProvider): void;
/**
* If no existing window.web3 is found, this function injects a web3 "shim" to
* not break dapps that rely on window.web3.currentProvider.
*
* @param provider - The provider to set as window.web3.currentProvider.
* @param log - The logging API to use.
*/
export function shimWeb3(provider: MetaMaskInpageProvider, log: typeof console): void;
export interface RequestArguments {
/** The RPC method to request. */
method: string;
/** The params of the RPC method, if any. */
params?: unknown[] | Record<string, unknown>;
}
export interface SendSyncJsonRpcRequest extends JsonRpcRequest<unknown> {
method: 'eth_accounts' | 'eth_coinbase' | 'eth_uninstallFilter' | 'net_version';
}