/*
This file is part of web3.js.
web3.js is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
web3.js is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with web3.js. If not, see .
*/
/**
* @file index.d.ts
* @author Josh Stevens
* @author Samuel Furter
* @author Prince Sinha
* @date 2018
*/
import * as net from 'net';
import {
BatchRequest,
Extension,
Log,
PromiEvent,
provider,
Providers,
RLPEncodedTransaction,
Transaction,
TransactionConfig,
TransactionReceipt,
Common,
hardfork,
chain,
BlockNumber,
LogsOptions,
PastLogsOptions
} from 'web3-core';
import { Subscription } from 'web3-core-subscriptions';
import { AbiCoder } from 'web3-eth-abi';
import { Accounts } from 'web3-eth-accounts';
import { Contract, ContractOptions } from 'web3-eth-contract';
import { Ens } from 'web3-eth-ens';
import { Iban } from 'web3-eth-iban';
import { Personal } from 'web3-eth-personal';
import { Network } from 'web3-net';
import { AbiItem } from 'web3-utils';
import { BigNumber } from 'bignumber.js';
import BN = require('bn.js');
export {
TransactionConfig,
RLPEncodedTransaction,
Transaction,
TransactionReceipt,
hardfork,
Common,
chain
} from 'web3-core';
export class Eth {
constructor();
constructor(provider: provider);
constructor(provider: provider, net: net.Socket);
Contract: new (
jsonInterface: AbiItem[] | AbiItem,
address?: string,
options?: ContractOptions
) => Contract;
Iban: new (iban: string) => Iban;
personal: Personal;
accounts: Accounts;
ens: Ens;
abi: AbiCoder;
net: Network;
readonly givenProvider: any;
static readonly givenProvider: any;
defaultAccount: string | null;
defaultBlock: string | number;
defaultCommon: Common;
defaultHardfork: hardfork;
defaultChain: chain;
transactionPollingTimeout: number;
transactionConfirmationBlocks: number;
transactionBlockTimeout: number;
readonly currentProvider: provider;
setProvider(provider: provider): boolean;
BatchRequest: new () => BatchRequest;
static readonly providers: Providers;
extend(extension: Extension): any;
clearSubscriptions(callback: (error: Error, result: boolean) => void): void;
subscribe(
type: 'logs',
options: LogsOptions,
callback?: (error: Error, log: Log) => void
): Subscription;
subscribe(
type: 'syncing',
callback?: (error: Error, result: Syncing) => void
): Subscription;
subscribe(
type: 'newBlockHeaders',
callback?: (error: Error, blockHeader: BlockHeader) => void
): Subscription;
subscribe(
type: 'pendingTransactions',
callback?: (error: Error, transactionHash: string) => void
): Subscription;
getProtocolVersion(
callback?: (error: Error, protocolVersion: string) => void
): Promise;
isSyncing(
callback?: (error: Error, syncing: Syncing) => void
): Promise;
getCoinbase(
callback?: (error: Error, coinbaseAddress: string) => void
): Promise;
isMining(
callback?: (error: Error, mining: boolean) => void
): Promise;
getHashrate(
callback?: (error: Error, hashes: number) => void
): Promise;
getNodeInfo(
callback?: (error: Error, version: string) => void
): Promise;
getChainId(
callback?: (error: Error, version: number) => void
): Promise;
getGasPrice(
callback?: (error: Error, gasPrice: string) => void
): Promise;
getAccounts(
callback?: (error: Error, accounts: string[]) => void
): Promise;
getBlockNumber(
callback?: (error: Error, blockNumber: number) => void
): Promise;
getBalance(
address: string
): Promise;
getBalance(
address: string,
defaultBlock: BlockNumber): Promise;
getBalance(
address: string,
callback?: (error: Error, balance: string) => void
): Promise;
getBalance(
address: string,
defaultBlock: BlockNumber,
callback?: (error: Error, balance: string) => void
): Promise;
getStorageAt(address: string, position: number | BigNumber | BN | string): Promise;
getStorageAt(
address: string,
position: number | BigNumber | BN | string,
defaultBlock: BlockNumber
): Promise;
getStorageAt(
address: string,
position: number | BigNumber | BN | string,
callback?: (error: Error, storageAt: string) => void
): Promise;
getStorageAt(
address: string,
position: number | BigNumber | BN | string,
defaultBlock: BlockNumber,
callback?: (error: Error, storageAt: string) => void
): Promise;
getCode(
address: string
): Promise;
getCode(
address: string,
defaultBlock: BlockNumber
): Promise;
getCode(
address: string,
callback?: (error: Error, code: string) => void
): Promise;
getCode(
address: string,
defaultBlock: BlockNumber,
callback?: (error: Error, code: string) => void
): Promise;
getBlock(blockHashOrBlockNumber: BlockNumber | string): Promise;
getBlock(
blockHashOrBlockNumber: BlockNumber | string,
returnTransactionObjects: true
): Promise;
getBlock(
blockHashOrBlockNumber: BlockNumber | string,
callback?: (error: Error, block: BlockTransactionString) => void
): Promise;
getBlock(
blockHashOrBlockNumber: BlockNumber | string,
returnTransactionObjects: true,
callback?: (error: Error, block: BlockTransactionObject) => void
): Promise;
getBlockTransactionCount(
blockHashOrBlockNumber: BlockNumber | string,
callback?: (error: Error, numberOfTransactions: number) => void
): Promise;
getBlockUncleCount(
blockHashOrBlockNumber: BlockNumber | string,
callback?: (error: Error, numberOfTransactions: number) => void
): Promise;
getUncle(
blockHashOrBlockNumber: BlockNumber | string,
uncleIndex: number | string | BN
): Promise;
getUncle(
blockHashOrBlockNumber: BlockNumber | string,
uncleIndex: number | string | BN,
returnTransactionObjects: true
): Promise;
getUncle(
blockHashOrBlockNumber: BlockNumber | string,
uncleIndex: number | string | BN,
callback?: (error: Error, uncle: any) => void
): Promise;
getUncle(
blockHashOrBlockNumber: BlockNumber | string,
uncleIndex: number | string | BN,
returnTransactionObjects: true,
callback?: (error: Error, uncle: any) => void
): Promise;
getTransaction(
transactionHash: string,
callback?: (error: Error, transaction: Transaction) => void
): Promise;
getPendingTransactions(
callback?: (error: Error, result: Transaction[]) => void
): Promise;
getTransactionFromBlock(
blockHashOrBlockNumber: BlockNumber | string,
indexNumber: number | string | BN,
callback?: (error: Error, transaction: Transaction) => void
): Promise;
getTransactionReceipt(
hash: string,
callback?: (
error: Error,
transactionReceipt: TransactionReceipt
) => void
): Promise;
getTransactionCount(address: string): Promise;
getTransactionCount(
address: string,
defaultBlock: BlockNumber
): Promise;
getTransactionCount(
address: string,
callback?: (error: Error, count: number) => void
): Promise;
getTransactionCount(
address: string,
defaultBlock: BlockNumber,
callback?: (error: Error, count: number) => void
): Promise;
sendTransaction(
transactionConfig: TransactionConfig,
callback?: (error: Error, hash: string) => void
): PromiEvent;
sendSignedTransaction(
signedTransactionData: string,
callback?: (error: Error, hash: string) => void
): PromiEvent;
sign(
dataToSign: string,
address: string | number,
callback?: (error: Error, signature: string) => void
): Promise;
signTransaction(
transactionConfig: TransactionConfig,
callback?: (
error: Error,
signedTransaction: RLPEncodedTransaction
) => void
): Promise;
signTransaction(
transactionConfig: TransactionConfig,
address: string
): Promise;
signTransaction(
transactionConfig: TransactionConfig,
address: string,
callback: (
error: Error,
signedTransaction: RLPEncodedTransaction
) => void
): Promise;
call(transactionConfig: TransactionConfig): Promise;
call(
transactionConfig: TransactionConfig,
defaultBlock?: BlockNumber
): Promise;
call(
transactionConfig: TransactionConfig,
callback?: (error: Error, data: string) => void
): Promise;
call(
transactionConfig: TransactionConfig,
defaultBlock: BlockNumber,
callback: (error: Error, data: string) => void
): Promise;
estimateGas(
transactionConfig: TransactionConfig,
callback?: (error: Error, gas: number) => void
): Promise;
getPastLogs(
options: PastLogsOptions,
callback?: (error: Error, logs: Log[]) => void
): Promise;
getWork(
callback?: (error: Error, result: string[]) => void
): Promise;
submitWork(
data: [string, string, string],
callback?: (error: Error, result: boolean) => void
): Promise;
getProof(
address: string,
storageKey: string[],
blockNumber: BlockNumber,
callback?: (error: Error, result: GetProof) => void
): Promise;
}
export interface Syncing {
StartingBlock: number;
CurrentBlock: number;
HighestBlock: number;
KnownStates: number;
PulledStates: number;
}
export interface BlockHeader {
number: number;
hash: string;
parentHash: string;
nonce: string;
sha3Uncles: string;
logsBloom: string;
transactionRoot: string;
stateRoot: string;
receiptRoot: string;
miner: string;
extraData: string;
gasLimit: number;
gasUsed: number;
timestamp: number | string;
}
// TODO: This interface does exist to provide backwards-compatibility and can get removed on a minor release
export interface Block extends BlockTransactionBase {
transactions: Transaction[] | string[];
}
export interface BlockTransactionBase extends BlockHeader {
size: number;
difficulty: number;
totalDifficulty: number;
uncles: string[];
}
export interface BlockTransactionObject extends BlockTransactionBase {
transactions: Transaction[];
}
export interface BlockTransactionString extends BlockTransactionBase {
transactions: string[];
}
export interface GetProof {
jsonrpc: string;
id: number;
result: {
address: string;
accountProof: string[];
balance: string;
codeHash: string;
nonce: string;
storageHash: string;
storageProof: StorageProof[];
};
}
export interface StorageProof {
key: string;
value: string;
proof: string[];
}