/////////////////////////////// // Bytes export type Arrayish = string | ArrayLike; /////////////////////////////// // BigNumber export interface BigNumber { fromTwos(value: number): BigNumber; toTwos(value: number): BigNumber; add(other: BigNumberish): BigNumber; sub(other: BigNumberish): BigNumber; div(other: BigNumberish): BigNumber; mul(other: BigNumberish): BigNumber; mod(other: BigNumberish): BigNumber; pow(other: BigNumberish): BigNumber; maskn(value: number): BigNumber; eq(other: BigNumberish): boolean; lt(other: BigNumberish): boolean; lte(other: BigNumberish): boolean; gt(other: BigNumberish): boolean; gte(other: BigNumberish): boolean; isZero(): boolean; toNumber(): number; toString(): string; toHexString(): string; }; export type BigNumberish = BigNumber | string | number | Arrayish; /////////////////////////////// // Connection export type ConnectionInfo = { url: string, user?: string, password?: string, allowInsecure?: boolean }; /////////////////////////////// // Crypto export type SupportedAlgorithms = 'sha256' | 'sha512'; export interface Signature { r: string; s: string; recoveryParam: number; v?: number; } /////////////////////////////// // Network export type Network = { name: string, chainId: number, ensAddress?: string, } export type Networkish = Network | string | number; /////////////////////////////// // ABI Coder export type CoerceFunc = (type: string, value: any) => any; export type ParamType = { name?: string, type: string, indexed?: boolean, components?: Array }; // @TODO: should this just be a combined Fragment? export type EventFragment = { type: string name: string, anonymous: boolean, inputs: Array, }; export type FunctionFragment = { type: string name: string, constant: boolean, inputs: Array, outputs: Array, payable: boolean, stateMutability: string, }; /////////////////////////////// // Transactions export type UnsignedTransaction = { to?: string; nonce?: number; gasLimit?: BigNumberish; gasPrice?: BigNumberish; data?: Arrayish; value?: BigNumberish; chainId?: number; } export interface Transaction { hash?: string; to?: string; from?: string; nonce: number; gasLimit: BigNumber; gasPrice: BigNumber; data: string; value: BigNumber; chainId: number; r?: string; s?: string; v?: number; } /////////////////////////////// // Blockchain export type BlockTag = string | number; export interface Block { hash: string; parentHash: string; number: number; timestamp: number; nonce: string; difficulty: number; gasLimit: BigNumber; gasUsed: BigNumber; miner: string; extraData: string; transactions: Array; } export type Filter = { fromBlock?: BlockTag, toBlock?: BlockTag, address?: string, topics?: Array>, } export interface Log { blockNumber?: number; blockHash?: string; transactionIndex?: number; removed?: boolean; transactionLogIndex?: number, address: string; data: string; topics: Array; transactionHash?: string; logIndex?: number; } export interface TransactionReceipt { contractAddress?: string, transactionIndex?: number, root?: string, gasUsed?: BigNumber, logsBloom?: string, blockHash?: string, transactionHash?: string, logs?: Array, blockNumber?: number, cumulativeGasUsed?: BigNumber, byzantium: boolean, status?: number }; export type TransactionRequest = { to?: string | Promise, from?: string | Promise, nonce?: number | string | Promise, gasLimit?: BigNumberish | Promise, gasPrice?: BigNumberish | Promise, data?: Arrayish | Promise, value?: BigNumberish | Promise, chainId?: number | Promise, } export interface TransactionResponse extends Transaction { // Only if a transaction has been mined blockNumber?: number, blockHash?: string, timestamp?: number, // Not optional (as it is in Transaction) from: string; // The raw transaction raw?: string, // This function waits until the transaction has been mined wait: (timeout?: number) => Promise }; /////////////////////////////// // Interface export class Indexed { hash: string; } export interface DeployDescription { type: "deploy"; inputs: Array; payable: boolean; encode(bytecode: string, params: Array): string; } export interface FunctionDescription { type: "call" | "transaction"; name: string; signature: string; sighash: string; inputs: Array; outputs: Array; payable: boolean; encode(params: Array): string; decode(data: string): any; } export interface EventDescription { type: "event"; name: string; signature: string; inputs: Array; anonymous: boolean; topic: string; encodeTopics(params: Array): Array; decode(data: string, topics?: Array): any; } /////////////////////////////// // Contract export type EventFilter = { address?: string; topics?: Array; // @TODO: Support OR-style topcis; backwards compatible to make this change //topics?: Array> }; // The (n + 1)th parameter passed to contract event callbacks export interface Event extends Log { args: Array; decode: (data: string, topics?: Array) => any; event: string; eventSignature: string; removeListener: () => void; getBlock: () => Promise; getTransaction: () => Promise; getTransactionReceipt: () => Promise; } /////////////////////////////// // Provider export type EventType = string | Array | Filter; export type Listener = (...args: Array) => void; /** * Provider * * Note: We use an abstract class so we can use instanceof to determine if an * object is a Provider. */ export abstract class MinimalProvider { abstract getNetwork(): Promise; abstract getBlockNumber(): Promise; abstract getGasPrice(): Promise; abstract getBalance(addressOrName: string | Promise, blockTag?: BlockTag | Promise): Promise; abstract getTransactionCount(addressOrName: string | Promise, blockTag?: BlockTag | Promise): Promise; abstract getCode(addressOrName: string | Promise, blockTag?: BlockTag | Promise): Promise ; abstract getStorageAt(addressOrName: string | Promise, position: BigNumberish | Promise, blockTag?: BlockTag | Promise): Promise; abstract sendTransaction(signedTransaction: string | Promise): Promise; abstract call(transaction: TransactionRequest): Promise; abstract estimateGas(transaction: TransactionRequest): Promise; abstract getBlock(blockHashOrBlockTag: BlockTag | string | Promise): Promise; abstract getTransaction(transactionHash: string): Promise; abstract getTransactionReceipt(transactionHash: string): Promise; abstract getLogs(filter: Filter): Promise>; abstract resolveName(name: string | Promise): Promise; abstract lookupAddress(address: string | Promise): Promise; abstract on(eventName: EventType, listener: Listener): MinimalProvider; abstract once(eventName: EventType, listener: Listener): MinimalProvider; abstract listenerCount(eventName?: EventType): number; abstract listeners(eventName: EventType): Array; abstract removeAllListeners(eventName: EventType): MinimalProvider; abstract removeListener(eventName: EventType, listener: Listener): MinimalProvider; // @TODO: This *could* be implemented here, but would pull in events... abstract waitForTransaction(transactionHash: string, timeout?: number): Promise; } /////////////////////////////// // Signer export type ProgressCallback = (percent: number) => void; export type EncryptOptions = { iv?: Arrayish; entropy?: Arrayish; mnemonic?: string; path?: string; client?: string; salt?: Arrayish; uuid?: string; scrypt?: { N?: number; r?: number; p?: number; } } /** * Signer * * Note: We use an abstract class so we can use instanceof to determine if an * object is a Signer. */ export abstract class Signer { provider?: MinimalProvider; abstract getAddress(): Promise abstract signMessage(transaction: Arrayish | string): Promise; abstract sendTransaction(transaction: TransactionRequest): Promise; }