1 | declare module 'web3' {
|
2 | import * as BigNumber from 'bignumber.js';
|
3 |
|
4 | type MixedData = string | number | object | any[] | BigNumber.BigNumber;
|
5 |
|
6 | class Web3 {
|
7 | public static providers: typeof providers;
|
8 | public currentProvider: Web3.Provider;
|
9 |
|
10 | public eth: Web3.EthApi;
|
11 | public personal: Web3.PersonalApi | undefined;
|
12 | public version: Web3.VersionApi;
|
13 | public net: Web3.NetApi;
|
14 |
|
15 | public constructor(provider?: Web3.Provider);
|
16 |
|
17 | public isConnected(): boolean;
|
18 | public setProvider(provider: Web3.Provider): void;
|
19 | public reset(keepIsSyncing: boolean): void;
|
20 | public toHex(data: MixedData): string;
|
21 | public toAscii(hex: string): string;
|
22 | public fromAscii(ascii: string, padding?: number): string;
|
23 | public toDecimal(hex: string): number;
|
24 | public fromDecimal(value: number | string): string;
|
25 | public fromWei(value: number | string, unit: Web3.Unit): string;
|
26 | public fromWei(value: BigNumber.BigNumber, unit: Web3.Unit): BigNumber.BigNumber;
|
27 | public toWei(amount: number | string, unit: Web3.Unit): string;
|
28 | public toWei(amount: BigNumber.BigNumber, unit: Web3.Unit): BigNumber.BigNumber;
|
29 | public toBigNumber(value: number | string): BigNumber.BigNumber;
|
30 | public isAddress(address: string): boolean;
|
31 | public isChecksumAddress(address: string): boolean;
|
32 | public sha3(value: string, options?: Web3.Sha3Options): string;
|
33 | }
|
34 |
|
35 | namespace providers {
|
36 | class HttpProvider implements Web3.Provider {
|
37 | constructor(url?: string, timeout?: number, username?: string, password?: string);
|
38 | public sendAsync(
|
39 | payload: Web3.JSONRPCRequestPayload,
|
40 | callback: (err: Error, result: Web3.JSONRPCResponsePayload) => void,
|
41 | ): void;
|
42 | }
|
43 | }
|
44 |
|
45 | namespace Web3 {
|
46 | type ContractAbi = AbiDefinition[];
|
47 |
|
48 | type AbiDefinition = FunctionAbi | EventAbi;
|
49 |
|
50 | type FunctionAbi = MethodAbi | ConstructorAbi | FallbackAbi;
|
51 |
|
52 | enum AbiType {
|
53 | Function = 'function',
|
54 | Constructor = 'constructor',
|
55 | Event = 'event',
|
56 | Fallback = 'fallback',
|
57 | }
|
58 |
|
59 | type ConstructorStateMutability = 'nonpayable' | 'payable';
|
60 | type StateMutability = 'pure' | 'view' | ConstructorStateMutability;
|
61 |
|
62 | interface MethodAbi {
|
63 | type: AbiType.Function;
|
64 | name: string;
|
65 | inputs: DataItem[];
|
66 | outputs: DataItem[];
|
67 | constant: boolean;
|
68 | stateMutability: StateMutability;
|
69 | payable: boolean;
|
70 | }
|
71 |
|
72 | interface ConstructorAbi {
|
73 | type: AbiType.Constructor;
|
74 | inputs: DataItem[];
|
75 | payable: boolean;
|
76 | stateMutability: ConstructorStateMutability;
|
77 | }
|
78 |
|
79 | interface FallbackAbi {
|
80 | type: AbiType.Fallback;
|
81 | payable: boolean;
|
82 | }
|
83 |
|
84 | interface EventParameter extends DataItem {
|
85 | indexed: boolean;
|
86 | }
|
87 |
|
88 | interface EventAbi {
|
89 | type: AbiType.Event;
|
90 | name: string;
|
91 | inputs: EventParameter[];
|
92 | anonymous: boolean;
|
93 | }
|
94 |
|
95 | interface DataItem {
|
96 | name: string;
|
97 | type: string;
|
98 | components: DataItem[];
|
99 | }
|
100 |
|
101 | interface ContractInstance {
|
102 | address: string;
|
103 | abi: Web3.ContractAbi;
|
104 | [name: string]: any;
|
105 | }
|
106 |
|
107 | interface Contract<A extends ContractInstance> {
|
108 | at(address: string): A;
|
109 | getData(...args: any[]): string;
|
110 | 'new'(...args: any[]): A;
|
111 | }
|
112 |
|
113 | interface FilterObject {
|
114 | fromBlock?: number | string;
|
115 | toBlock?: number | string;
|
116 | address?: string;
|
117 | topics?: LogTopic[];
|
118 | }
|
119 |
|
120 | type LogTopic = null | string | string[];
|
121 |
|
122 | interface DecodedLogEntry<A> extends LogEntry {
|
123 | event: string;
|
124 | args: A;
|
125 | }
|
126 |
|
127 | interface DecodedLogEntryEvent<A> extends DecodedLogEntry<A> {
|
128 | removed: boolean;
|
129 | }
|
130 |
|
131 | interface LogEntryEvent extends LogEntry {
|
132 | removed: boolean;
|
133 | }
|
134 |
|
135 | interface FilterResult {
|
136 | get(callback: () => void): void;
|
137 | watch(callback: (err: Error, result: LogEntryEvent) => void): void;
|
138 | stopWatching(callback?: () => void): void;
|
139 | }
|
140 |
|
141 | export interface JSONRPCRequestPayload {
|
142 | params: any[];
|
143 | method: string;
|
144 | id: number;
|
145 | jsonrpc: string;
|
146 | }
|
147 |
|
148 | export interface JSONRPCResponsePayload {
|
149 | result: any;
|
150 | id: number;
|
151 | jsonrpc: string;
|
152 | }
|
153 |
|
154 | export type OpCode = string;
|
155 |
|
156 | export interface StructLog {
|
157 | depth: number;
|
158 | error: string;
|
159 | gas: number;
|
160 | gasCost: number;
|
161 | memory: string[];
|
162 | op: OpCode;
|
163 | pc: number;
|
164 | stack: string[];
|
165 | storage: { [location: string]: string };
|
166 | }
|
167 | export interface TransactionTrace {
|
168 | gas: number;
|
169 | returnValue: any;
|
170 | structLogs: StructLog[];
|
171 | }
|
172 |
|
173 | interface Provider {
|
174 | sendAsync(
|
175 | payload: JSONRPCRequestPayload,
|
176 | callback: (err: Error, result: JSONRPCResponsePayload) => void,
|
177 | ): void;
|
178 | }
|
179 |
|
180 | interface Sha3Options {
|
181 | encoding: 'hex';
|
182 | }
|
183 |
|
184 | interface EthApi {
|
185 | coinbase: string;
|
186 | mining: boolean;
|
187 | hashrate: number;
|
188 | gasPrice: BigNumber.BigNumber;
|
189 | accounts: string[];
|
190 | blockNumber: number;
|
191 | defaultAccount?: string;
|
192 | defaultBlock: Web3.BlockParam;
|
193 | syncing: Web3.SyncingResult;
|
194 | compile: {
|
195 | solidity(sourceString: string, cb?: (err: Error, result: any) => void): object;
|
196 | };
|
197 | getMining(cd: (err: Error, mining: boolean) => void): void;
|
198 | getHashrate(cd: (err: Error, hashrate: number) => void): void;
|
199 | getGasPrice(cd: (err: Error, gasPrice: BigNumber.BigNumber) => void): void;
|
200 | getAccounts(cd: (err: Error, accounts: string[]) => void): void;
|
201 | getBlockNumber(callback: (err: Error, blockNumber: number) => void): void;
|
202 | getSyncing(cd: (err: Error, syncing: Web3.SyncingResult) => void): void;
|
203 | isSyncing(cb: (err: Error, isSyncing: boolean, syncingState: Web3.SyncingState) => void): Web3.IsSyncing;
|
204 |
|
205 | getBlock(hashStringOrBlockNumber: string | Web3.BlockParam): Web3.BlockWithoutTransactionData;
|
206 | getBlock(
|
207 | hashStringOrBlockNumber: string | Web3.BlockParam,
|
208 | callback: (err: Error, blockObj: Web3.BlockWithoutTransactionData) => void,
|
209 | ): void;
|
210 | getBlock(
|
211 | hashStringOrBlockNumber: string | Web3.BlockParam,
|
212 | returnTransactionObjects: true,
|
213 | ): Web3.BlockWithTransactionData;
|
214 | getBlock(
|
215 | hashStringOrBlockNumber: string | Web3.BlockParam,
|
216 | returnTransactionObjects: true,
|
217 | callback: (err: Error, blockObj: Web3.BlockWithTransactionData) => void,
|
218 | ): void;
|
219 |
|
220 | getBlockTransactionCount(hashStringOrBlockNumber: string | Web3.BlockParam): number;
|
221 | getBlockTransactionCount(
|
222 | hashStringOrBlockNumber: string | Web3.BlockParam,
|
223 | callback: (err: Error, blockTransactionCount: number) => void,
|
224 | ): void;
|
225 |
|
226 |
|
227 | getUncle(
|
228 | hashStringOrBlockNumber: string | Web3.BlockParam,
|
229 | uncleNumber: number,
|
230 | ): Web3.BlockWithoutTransactionData;
|
231 | getUncle(
|
232 | hashStringOrBlockNumber: string | Web3.BlockParam,
|
233 | uncleNumber: number,
|
234 | callback: (err: Error, uncle: Web3.BlockWithoutTransactionData) => void,
|
235 | ): void;
|
236 |
|
237 | getTransaction(transactionHash: string): Web3.Transaction;
|
238 | getTransaction(
|
239 | transactionHash: string,
|
240 | callback: (err: Error, transaction: Web3.Transaction) => void,
|
241 | ): void;
|
242 |
|
243 | getTransactionFromBlock(
|
244 | hashStringOrBlockNumber: string | Web3.BlockParam,
|
245 | indexNumber: number,
|
246 | ): Web3.Transaction;
|
247 | getTransactionFromBlock(
|
248 | hashStringOrBlockNumber: string | Web3.BlockParam,
|
249 | indexNumber: number,
|
250 | callback: (err: Error, transaction: Web3.Transaction) => void,
|
251 | ): void;
|
252 |
|
253 | contract(abi: Web3.AbiDefinition[]): Web3.Contract<any>;
|
254 |
|
255 |
|
256 | getBalance(addressHexString: string): BigNumber.BigNumber;
|
257 | getBalance(addressHexString: string, callback: (err: Error, result: BigNumber.BigNumber) => void): void;
|
258 |
|
259 |
|
260 | getStorageAt(address: string, position: number): string;
|
261 | getStorageAt(address: string, position: number, callback: (err: Error, storage: string) => void): void;
|
262 |
|
263 |
|
264 | getCode(addressHexString: string): string;
|
265 | getCode(addressHexString: string, callback: (err: Error, code: string) => void): void;
|
266 |
|
267 | filter(value: string | Web3.FilterObject): Web3.FilterResult;
|
268 |
|
269 | sendTransaction(txData: Web3.TxData): string;
|
270 | sendTransaction(txData: Web3.TxData, callback: (err: Error, value: string) => void): void;
|
271 |
|
272 | sendRawTransaction(rawTxData: string): string;
|
273 | sendRawTransaction(rawTxData: string, callback: (err: Error, value: string) => void): void;
|
274 |
|
275 | sign(address: string, data: string): string;
|
276 | sign(address: string, data: string, callback: (err: Error, signature: string) => void): void;
|
277 |
|
278 | getTransactionReceipt(txHash: string): Web3.TransactionReceipt | null;
|
279 | getTransactionReceipt(
|
280 | txHash: string,
|
281 | callback: (err: Error, receipt: Web3.TransactionReceipt | null) => void,
|
282 | ): void;
|
283 |
|
284 |
|
285 | call(callData: Web3.CallData): string;
|
286 | call(callData: Web3.CallData, callback: (err: Error, result: string) => void): void;
|
287 |
|
288 | estimateGas(callData: Web3.CallData): number;
|
289 | estimateGas(callData: Web3.CallData, callback: (err: Error, gas: number) => void): void;
|
290 |
|
291 |
|
292 | getTransactionCount(address: string): number;
|
293 | getTransactionCount(address: string, callback: (err: Error, count: number) => void): void;
|
294 | }
|
295 |
|
296 | interface VersionApi {
|
297 | api: string;
|
298 | network: string;
|
299 | node: string;
|
300 | ethereum: string;
|
301 | whisper: string;
|
302 | getNetwork(cd: (err: Error, networkId: string) => void): void;
|
303 | getNode(cd: (err: Error, nodeVersion: string) => void): void;
|
304 | getEthereum(cd: (err: Error, ethereum: string) => void): void;
|
305 | getWhisper(cd: (err: Error, whisper: string) => void): void;
|
306 | }
|
307 |
|
308 | interface PersonalApi {
|
309 | listAccounts: string[] | undefined;
|
310 | newAccount(password?: string): string;
|
311 | unlockAccount(address: string, password?: string, duration?: number): boolean;
|
312 | lockAccount(address: string): boolean;
|
313 | sign(message: string, account: string, password: string): string;
|
314 | sign(hexMessage: string, account: string, callback: (error: Error, signature: string) => void): void;
|
315 | }
|
316 |
|
317 | interface NetApi {
|
318 | listening: boolean;
|
319 | peerCount: number;
|
320 | getListening(cd: (err: Error, listening: boolean) => void): void;
|
321 | getPeerCount(cd: (err: Error, peerCount: number) => void): void;
|
322 | }
|
323 |
|
324 | type BlockParam = number | 'earliest' | 'latest' | 'pending';
|
325 |
|
326 | type Unit =
|
327 | | 'kwei'
|
328 | | 'ada'
|
329 | | 'mwei'
|
330 | | 'babbage'
|
331 | | 'gwei'
|
332 | | 'shannon'
|
333 | | 'szabo'
|
334 | | 'finney'
|
335 | | 'ether'
|
336 | | 'kether'
|
337 | | 'grand'
|
338 | | 'einstein'
|
339 | | 'mether'
|
340 | | 'gether'
|
341 | | 'tether';
|
342 |
|
343 | interface SyncingState {
|
344 | startingBlock: number;
|
345 | currentBlock: number;
|
346 | highestBlock: number;
|
347 | }
|
348 | type SyncingResult = false | SyncingState;
|
349 |
|
350 | interface IsSyncing {
|
351 | addCallback(cb: (err: Error, isSyncing: boolean, syncingState: SyncingState) => void): void;
|
352 | stopWatching(): void;
|
353 | }
|
354 |
|
355 | interface AbstractBlock {
|
356 | number: number | null;
|
357 | hash: string | null;
|
358 | parentHash: string;
|
359 | nonce: string | null;
|
360 | sha3Uncles: string;
|
361 | logsBloom: string | null;
|
362 | transactionsRoot: string;
|
363 | stateRoot: string;
|
364 | miner: string;
|
365 | difficulty: BigNumber.BigNumber;
|
366 | totalDifficulty: BigNumber.BigNumber;
|
367 | extraData: string;
|
368 | size: number;
|
369 | gasLimit: number;
|
370 | gasUsed: number;
|
371 | timestamp: number;
|
372 | uncles: string[];
|
373 | }
|
374 | interface BlockWithoutTransactionData extends AbstractBlock {
|
375 | transactions: string[];
|
376 | }
|
377 | interface BlockWithTransactionData extends AbstractBlock {
|
378 | transactions: Transaction[];
|
379 | }
|
380 |
|
381 | interface Transaction {
|
382 | hash: string;
|
383 | nonce: number;
|
384 | blockHash: string | null;
|
385 | blockNumber: number | null;
|
386 | transactionIndex: number | null;
|
387 | from: string;
|
388 | to: string | null;
|
389 | value: BigNumber.BigNumber;
|
390 | gasPrice: BigNumber.BigNumber;
|
391 | gas: number;
|
392 | input: string;
|
393 | }
|
394 |
|
395 | interface CallTxDataBase {
|
396 | to?: string;
|
397 | value?: number | string | BigNumber.BigNumber;
|
398 | gas?: number | string | BigNumber.BigNumber;
|
399 | gasPrice?: number | string | BigNumber.BigNumber;
|
400 | data?: string;
|
401 | nonce?: number;
|
402 | }
|
403 |
|
404 | interface TxData extends CallTxDataBase {
|
405 | from: string;
|
406 | }
|
407 |
|
408 | interface CallData extends CallTxDataBase {
|
409 | from?: string;
|
410 | }
|
411 |
|
412 | interface TransactionReceipt {
|
413 | blockHash: string;
|
414 | blockNumber: number;
|
415 | transactionHash: string;
|
416 | transactionIndex: number;
|
417 | from: string;
|
418 | to: string;
|
419 | status: null | string | 0 | 1;
|
420 | cumulativeGasUsed: number;
|
421 | gasUsed: number;
|
422 | contractAddress: string | null;
|
423 | logs: LogEntry[];
|
424 | }
|
425 |
|
426 | interface LogEntry {
|
427 | logIndex: number | null;
|
428 | transactionIndex: number | null;
|
429 | transactionHash: string;
|
430 | blockHash: string | null;
|
431 | blockNumber: number | null;
|
432 | address: string;
|
433 | data: string;
|
434 | topics: string[];
|
435 | }
|
436 | }
|
437 |
|
438 | export = Web3;
|
439 |
|
440 | }
|