///
import { JsonRPCRequest, JsonRPCResponse } from './jsonrpc';
import { BigNumber } from 'bignumber.js';
/** Convert number or hex string to BigNumber */
export declare function toBN(value: number): BigNumber;
/**
* Strongly-types wrapper over web3.js with additional helper methods.
*/
export declare class W3 {
private static _counter;
private static _default;
private _globalWeb3;
private _netId;
private _netNode;
private _defaultAccount;
private _defaultTimeout;
/**
* Default W3 instance that is used as a fallback when such an instance is not provided to a constructor.
* You must set it explicitly via W3.default setter. Use an empty `new W3()` constructor to get an instance that
* automatically resolves to a global web3 instance `window['web3']` provided by e.g. MIST/Metamask or connects
* to the default 8545 port if no global instance is present.
*/
/**
* Set default W3 instance.
*/
static default: W3;
/** Get Global W3 incrementing counter. Starts with zero. */
static getNextCounter(): number;
/** Web3 providers. */
static providers: W3.Providers;
/** Current Web3 provider. */
readonly currentProvider: W3.Provider;
/** Convert number or hex string to BigNumber */
toBigNumber(value: number | string): BigNumber;
/** Converts a number or number string to its HEX representation. */
fromDecimal(value: number | string): string;
/**
* web3.js untyped instance created with a resolved or given in ctor provider, if any.
*/
web3: any;
/** Default account for sending transactions without explicit txParams. */
defaultAccount: string;
/** Default timeout in seconds. */
defaultTimeout: number;
/**
* Create a default Web3 instance - resolves to a global window['web3'] injected my MIST, MetaMask, etc
* or to `localhost:8545` if not running on https.
*/
constructor();
/**
* Create a W3 instance with a given provider.
* @param provider web3.js provider.
*/
constructor(provider?: W3.Provider);
/** Request netid string from ctor or after provider change */
private updateNetworkInfo;
/** Returns a list of accounts the node controlst */
readonly accounts: Promise;
/** Web3.js version API */
readonly web3API: string;
/** True if current web3.js version is 0.20.x. */
readonly isPre1API: boolean;
/** True if current node name contains TestRPC string */
readonly isTestRPC: Promise;
/** Get network ID. */
readonly networkId: Promise;
/** Set web3 provider and update network info asynchronously. */
setProvider(provider: W3.Provider): void;
/** Send raw JSON RPC request to the current provider. */
sendRPC(payload: JsonRPCRequest): Promise;
/** Returns the time of the last mined block in seconds. */
readonly latestTime: Promise;
/** Returns the current block number */
readonly blockNumber: Promise;
/** Async unlock while web3.js only has sync version. This function uses `personal_unlockAccount` RPC message that is not available in some web3 providers. */
unlockAccount(address: string, password: string, duration?: number): Promise;
/** Get account balance */
getBalance(address: string): Promise;
/** Sign using eth.sign but with prefix as personal_sign */
ethSignRaw(hex: string, account: string): Promise;
/** Sign a message */
sign(message: string, account: string, password?: string): Promise;
/** Message already as hex */
signRaw(message: any, account: string, password?: string): Promise;
/** True if current web3 provider is from MetaMask. */
readonly isMetaMask: boolean;
/**
* Get the numbers of transactions sent from this address.
* @param account The address to get the numbers of transactions from.
* @param defaultBlock (optional) If you pass this parameter it will not use the default block set with.
*/
getTransactionCount(account?: string, defaultBlock?: number | string): Promise;
/**
* Sends a raw signed transaction and returns tx hash. Use waitTransactionReceipt method on w3 or a contract to get a tx receipt.
* @param to Target contract address or zero address (W3.zeroAddress) to deploy a new contract.
* @param privateKey Private key hex string prefixed with 0x.
* @param data Payload data.
* @param txParams Tx parameters.
* @param nonce Nonce override if needed to replace a pending transaction.
*/
sendSignedTransaction(to: string, privateKey: string, data?: string, txParams?: W3.TX.TxParams, nonce?: number): Promise;
/**
* Returns the receipt of a transaction by transaction hash. Retries for up to 240 seconds.
* @param hashString The transaction hash.
* @param timeoutSeconds Timeout in seconds, must be above 240 or ignored.
*/
waitTransactionReceipt(hashString: string, timeoutSeconds?: number): Promise;
}
export declare namespace W3 {
/** Type alias for Ethereum address. */
type address = string;
/** Type alias for bytes string. */
type bytes = string;
/** Hex zero address. */
const zeroAddress: string;
/** Check if Ethereum address is in valid format. */
function isValidAddress(addr: address): boolean;
/** Utf8 package. */
let Utf8: any;
/**
* Convert value to hex with optional left padding. If a string is already a hex it will be converted to lower case.
* @param value Value to convert to hex
* @param size Size of number in bits (8 for int8, 16 for uint16, etc)
*/
function toHex(value: number | string | BigNumber, stripPrefix?: boolean, size?: number): string;
/** String left pad. Same as the notorious left-pad package as a single function. */
function leftPad(str: string, len: number, ch: any): string;
/** Utf8 to hex convertor. */
function utf8ToHex(str: string, stripPrefix?: boolean): string;
/** Ethereumjs-util package. */
let EthUtils: W3.EthUtils;
/** Creates SHA-3 hash of the input. */
function sha3(a: Buffer | Array | string | number, bits?: number): string;
/** Creates SHA256 hash of the input. */
function sha256(a: Buffer | Array | string | number): string;
/** ECDSA sign. */
function sign(message: any, privateKey: string): bytes;
/** ECDSA public key recovery from signature. */
function ecrecover(message: string, signature: string): address;
/**
* Get Keythereum instance. https://github.com/ethereumjs/keythereum
*/
function getKeythereum(): any;
/** Truffle Contract */
namespace TX {
/** Standard transaction parameters. */
interface TxParams {
from: address;
gas: number | BigNumber;
gasPrice: number | BigNumber;
value: number | BigNumber;
}
type ContractDataType = BigNumber | number | string | boolean | BigNumber[] | number[] | string[];
interface TransactionResult {
/** Transaction hash. */
tx: string;
receipt: TransactionReceipt;
/** This array has decoded events, while reseipt.logs has raw logs when returned from TC transaction */
logs: Log[];
}
/** 4500000 gas @ 2 Gwei */
function txParamsDefaultDeploy(from: address, gas?: number, gasPrice?: number): TxParams;
/** 50000 gas @ 2 Gwei */
function txParamsDefaultSend(from: address, gas?: number, gasPrice?: number): TxParams;
function getEthereumjsTx(): any;
}
interface Provider {
sendAsync(payload: JsonRPCRequest, callback: (err: Error, result: JsonRPCResponse) => void): void;
}
interface WebsocketProvider extends Provider {
}
interface HttpProvider extends Provider {
}
interface IpcProvider extends Provider {
}
interface Providers {
WebsocketProvider: new (host: string, timeout?: number) => WebsocketProvider;
HttpProvider: new (host: string, timeout?: number) => HttpProvider;
IpcProvider: new (path: string, net: any) => IpcProvider;
}
type Unit = 'kwei' | 'femtoether' | 'babbage' | 'mwei' | 'picoether' | 'lovelace' | 'qwei' | 'nanoether' | 'shannon' | 'microether' | 'szabo' | 'nano' | 'micro' | 'milliether' | 'finney' | 'milli' | 'ether' | 'kether' | 'grand' | 'mether' | 'gether' | 'tether';
type BlockType = 'latest' | 'pending' | 'genesis' | number;
interface BatchRequest {
add(request: Request): void;
execute(): void;
}
interface Iban {
}
interface Utils {
BN: BigNumber;
isBN(obj: any): boolean;
isBigNumber(obj: any): boolean;
isAddress(obj: any): boolean;
isHex(obj: any): boolean;
asciiToHex(val: string): string;
hexToAscii(val: string): string;
bytesToHex(val: number[]): string;
numberToHex(val: number | BigNumber): string;
checkAddressChecksum(address: string): boolean;
fromAscii(val: string): string;
fromDecimal(val: string | number | BigNumber): string;
fromUtf8(val: string): string;
fromWei(val: string | number | BigNumber, unit: Unit): string | BigNumber;
hexToBytes(val: string): number[];
hexToNumber(val: string | number | BigNumber): number;
hexToNumberString(val: string | number | BigNumber): string;
hexToString(val: string): string;
hexToUtf8(val: string): string;
keccak256(val: string): string;
leftPad(str: string, chars: number, sign: string): string;
padLeft(str: string, chars: number, sign: string): string;
rightPad(str: string, chars: number, sign: string): string;
padRight(str: string, chars: number, sign: string): string;
sha3(val: string, val2?: string, val3?: string, val4?: string, val5?: string): string;
soliditySha3(val: string): string;
randomHex(bytes: number): string;
stringToHex(val: string): string;
toAscii(hex: string): string;
toBN(obj: any): BigNumber;
toChecksumAddress(val: string): string;
toDecimal(val: any): number;
toHex(val: any): string;
toUtf8(val: any): string;
toWei(val: string | number | BigNumber, unit: Unit): string | BigNumber;
unitMap: any;
}
/**
* https://github.com/ethereumjs/ethereumjs-util/blob/master/docs/index.md
*/
interface EthUtils {
/** BN.js */
BN: BigNumber;
/** Adds "0x" to a given String if it does not already start with "0x". */
addHexPrefix(str: string): string;
/** Converts a Buffer or Array to JSON. */
baToJSON(ba: Buffer | Array): any;
bufferToHex(buf: Buffer): string;
bufferToInt(buf: Buffer): number;
ecrecover(msgHash: Buffer, v: number, r: Buffer, s: Buffer): Buffer;
ecsign(msgHash: Buffer, privateKey: Buffer): any;
fromRpcSig(sig: string): any;
fromSigned(num: Buffer): any;
generateAddress(from: Buffer, nonce: Buffer): Buffer;
hashPersonalMessage(message: Buffer): Buffer;
importPublic(publicKey: Buffer): Buffer;
isValidAddress(address: string): boolean;
isValidChecksumAddress(address: Buffer): boolean;
isValidPrivate(privateKey: Buffer): boolean;
isValidPublic(privateKey: Buffer, sanitize: boolean): any;
isValidSignature(v: number, r: Buffer, s: Buffer, homestead?: boolean): any;
privateToAddress(privateKey: Buffer): Buffer;
pubToAddress(privateKey: Buffer, sanitize?: boolean): Buffer;
sha256(a: Buffer | Array | string | number): Buffer;
/** Keccak[bits] */
sha3(a: Buffer | Array | string | number, bits?: number): Buffer;
SHA3_NULL: Buffer;
SHA3_NULL_S: string;
toBuffer(v: any): Buffer;
toChecksumAddress(address: string): string;
toRpcSig(v: number, r: Buffer, s: Buffer): string;
privateToPublic(privateKey: Buffer): Buffer;
zeros(bytes: number): Buffer;
}
type Callback = (error: Error, result: T) => void;
type ABIDataTypes = 'uint256' | 'boolean' | 'string' | 'bytes' | string;
interface ABIDefinition {
constant?: boolean;
payable?: boolean;
anonymous?: boolean;
inputs?: Array<{
name: string;
type: ABIDataTypes;
indexed?: boolean;
}>;
name?: string;
outputs?: Array<{
name: string;
type: ABIDataTypes;
}>;
type: 'function' | 'constructor' | 'event' | 'fallback';
}
interface CompileResult {
code: string;
info: {
source: string;
language: string;
languageVersion: string;
compilerVersion: string;
abiDefinition: Array;
};
userDoc: {
methods: object;
};
developerDoc: {
methods: object;
};
}
interface Transaction {
hash: string;
nonce: number;
blockHash: string;
blockNumber: number;
transactionIndex: number;
from: string;
to: string;
value: string;
gasPrice: string;
gas: number;
input: string;
v?: string;
r?: string;
s?: string;
}
interface TransactionReceipt {
transactionHash: string;
transactionIndex: number;
blockHash: string;
blockNumber: number;
from: string;
to: string;
contractAddress: string;
cumulativeGasUsed: number;
gasUsed: number;
logs?: Log[];
events?: {
[eventName: string]: EventLog;
};
}
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;
}
interface Block extends BlockHeader {
transactions: Array;
size: number;
difficulty: number;
totalDifficulty: number;
uncles: Array;
}
interface Logs {
fromBlock?: number;
address?: string;
topics?: Array;
}
/** Transaction log entry. */
interface Log {
address: string;
logIndex: number;
transactionIndex: number;
transactionHash: string;
blockHash: string;
blockNumber: number;
/** true when the log was removed, due to a chain reorganization. false if its a valid log. */
removed?: boolean;
data?: string;
topics?: Array;
/** Event name decoded by Truffle-contract */
event?: string;
/** Truffle-contract returns this as 'mined' */
type?: string;
/** Args passed to a Truffle-contract method */
args?: any;
}
interface EventLog extends Log {
event: string;
returnValues: any;
signature: string | null;
raw?: {
data: string;
topics: any[];
};
}
interface Subscribe {
subscription: {
id: string;
subscribe(callback?: Callback>): Subscribe;
unsubscribe(callback?: Callback): void | boolean;
arguments: object;
};
on(type: 'data', handler: (data: T) => void): void;
on(type: 'changed', handler: (data: T) => void): void;
on(type: 'error', handler: (data: Error) => void): void;
}
interface Account {
address: string;
privateKey: string;
publicKey: string;
}
interface PrivateKey {
address: string;
Crypto: {
cipher: string;
ciphertext: string;
cipherparams: {
iv: string;
};
kdf: string;
kdfparams: {
dklen: number;
n: number;
p: number;
r: number;
salt: string;
};
mac: string;
};
id: string;
version: number;
}
interface Signature {
message: string;
hash: string;
r: string;
s: string;
v: string;
}
interface Tx {
nonce?: string | number;
chainId?: string | number;
from?: string;
to?: string;
data?: string;
value?: string | number;
gas?: string | number;
gasPrice?: string | number;
}
interface ContractOptions {
address: string;
jsonInterface: ABIDefinition[];
from?: string;
gas?: string | number | BigNumber;
gasPrice?: number;
data?: string;
}
type PromiEventType = 'transactionHash' | 'receipt' | 'confirmation' | 'error';
interface PromiEvent extends Promise {
once(type: 'transactionHash', handler: (receipt: string) => void): PromiEvent;
once(type: 'receipt', handler: (receipt: TransactionReceipt) => void): PromiEvent;
once(type: 'confirmation', handler: (confNumber: number, receipt: TransactionReceipt) => void): PromiEvent;
once(type: 'error', handler: (error: Error) => void): PromiEvent;
once(type: 'error' | 'confirmation' | 'receipt' | 'transactionHash', handler: (error: Error | TransactionReceipt | string) => void): PromiEvent;
on(type: 'transactionHash', handler: (receipt: string) => void): PromiEvent;
on(type: 'receipt', handler: (receipt: TransactionReceipt) => void): PromiEvent;
on(type: 'confirmation', handler: (confNumber: number, receipt: TransactionReceipt) => void): PromiEvent;
on(type: 'error', handler: (error: Error) => void): PromiEvent;
on(type: 'error' | 'confirmation' | 'receipt' | 'transactionHash', handler: (error: Error | TransactionReceipt | string) => void): PromiEvent;
}
interface EventEmitter {
on(type: 'data', handler: (event: EventLog) => void): EventEmitter;
on(type: 'changed', handler: (receipt: EventLog) => void): EventEmitter;
on(type: 'error', handler: (error: Error) => void): EventEmitter;
on(type: 'error' | 'data' | 'changed', handler: (error: Error | TransactionReceipt | string) => void): EventEmitter;
}
interface TransactionObject {
arguments: any[];
call(tx?: Tx): Promise;
send(tx?: Tx): PromiEvent;
estimateGas(tx?: Tx): Promise;
encodeABI(): string;
}
interface Contract {
options: ContractOptions;
methods: {
[fnName: string]: (...args: any[]) => TransactionObject;
};
deploy(options: {
data: string;
arguments: any[];
}): TransactionObject;
events: {
[eventName: string]: (options?: {
filter?: object;
fromBlock?: BlockType;
topics?: any[];
}, cb?: Callback) => EventEmitter;
allEvents: (options?: {
filter?: object;
fromBlock?: BlockType;
topics?: any[];
}, cb?: Callback) => EventEmitter;
};
}
interface Eth {
readonly defaultAccount: string;
readonly defaultBlock: BlockType;
BatchRequest: new () => BatchRequest;
Iban: new (address: string) => Iban;
Contract: new (jsonInterface: any[], address?: string, options?: {
from?: string;
gas?: string | number | BigNumber;
gasPrice?: number;
data?: string;
}) => Contract;
abi: {
decodeLog(inputs: object, hexString: string, topics: string[]): object;
encodeParameter(type: string, parameter: any): string;
encodeParameters(types: string[], paramaters: any[]): string;
encodeEventSignature(name: string | object): string;
encodeFunctionCall(jsonInterface: object, parameters: any[]): string;
encodeFunctionSignature(name: string | object): string;
decodeParameter(type: string, hex: string): any;
decodeParameters(types: string[], hex: string): any;
};
accounts: {
'new'(entropy?: string): Account;
privateToAccount(privKey: string): Account;
publicToAddress(key: string): string;
signTransaction(tx: Tx, privateKey: string, returnSignature?: boolean, cb?: (err: Error, result: string | Signature) => void): Promise | Signature;
recoverTransaction(signature: string | Signature): string;
sign(data: string, privateKey: string, returnSignature?: boolean): string | Signature;
recover(signature: string | Signature): string;
encrypt(privateKey: string, password: string): PrivateKey;
decrypt(privateKey: PrivateKey, password: string): Account;
wallet: {
'new'(numberOfAccounts: number, entropy: string): Account[];
add(account: string | Account): any;
remove(account: string | number): any;
save(password: string, keyname?: string): string;
load(password: string, keyname: string): any;
clear(): any;
};
};
call(callObject: Tx, defaultBloc?: BlockType, callBack?: Callback): Promise;
clearSubscriptions(): boolean;
subscribe(type: 'logs', options?: Logs, callback?: Callback>): Promise>;
subscribe(type: 'syncing', callback?: Callback>): Promise>;
subscribe(type: 'newBlockHeaders', callback?: Callback>): Promise>;
subscribe(type: 'pendingTransactions', callback?: Callback>): Promise>;
subscribe(type: 'pendingTransactions' | 'newBlockHeaders' | 'syncing' | 'logs', options?: Logs, callback?: Callback>): Promise>;
unsubscribe(callBack: Callback): void | boolean;
compile: {
solidity(source: string, callback?: Callback): Promise;
lll(source: string, callback?: Callback): Promise;
serpent(source: string, callback?: Callback): Promise;
};
currentProvider: Provider;
estimateGas(tx: Tx, callback?: Callback): Promise;
getAccounts(cb?: Callback>): Promise>;
getBalance(address: string, defaultBlock?: BlockType, cb?: Callback): Promise;
getBlock(number: BlockType, returnTransactionObjects?: boolean, cb?: Callback): Promise;
getBlockNumber(callback?: Callback): Promise;
getBlockTransactionCount(number: BlockType | string, cb?: Callback): Promise;
getBlockUncleCount(number: BlockType | string, cb?: Callback): Promise;
getCode(address: string, defaultBlock?: BlockType, cb?: Callback): Promise;
getCoinbase(cb?: Callback): Promise;
getCompilers(cb?: Callback): Promise;
getGasPrice(cb?: Callback): Promise;
getHashrate(cb?: Callback): Promise;
getPastLogs(options: {
fromBlock?: BlockType;
toBlock?: BlockType;
address: string;
topics?: Array>;
}, cb?: Callback>): Promise>;
getProtocolVersion(cb?: Callback): Promise;
getStorageAt(address: string, defaultBlock?: BlockType, cb?: Callback): Promise;
getTransactionReceipt(hash: string, cb?: Callback): Promise;
getTransaction(hash: string, cb?: Callback): Promise;
getTransactionCount(address: string, defaultBlock?: BlockType, cb?: Callback): Promise;
getTransactionFromBlock(block: BlockType, index: number, cb?: Callback): Promise;
getUncle(blockHashOrBlockNumber: BlockType | string, uncleIndex: number, returnTransactionObjects?: boolean, cb?: Callback): Promise;
getWork(cb?: Callback>): Promise>;
givenProvider: Provider;
isMining(cb?: Callback): Promise;
isSyncing(cb?: Callback): Promise;
net: Net;
personal: Personal;
sendSignedTransaction(data: string, cb?: Callback): PromiEvent;
sendTransaction(tx: Tx, cb?: Callback): PromiEvent;
submitWork(nonce: string, powHash: string, digest: string, cb?: Callback): Promise;
sign(address: string, dataToSign: string, cb?: Callback): Promise;
}
interface SyncingState {
startingBlock: number;
currentBlock: number;
highestBlock: number;
}
type SyncingResult = false | SyncingState;
interface Version0 {
api: string;
network: string;
node: string;
ethereum: string;
whisper: string;
getNetwork(callback: (err: Error, networkId: string) => void): void;
getNode(callback: (err: Error, nodeVersion: string) => void): void;
getEthereum(callback: (err: Error, ethereum: string) => void): void;
getWhisper(callback: (err: Error, whisper: string) => void): void;
}
interface Net {
}
interface Personal {
newAccount(password: string, cb?: Callback): Promise;
getAccounts(cb?: Callback>): Promise>;
importRawKey(): any;
lockAccount(): any;
unlockAccount(): any;
sign(): any;
}
interface Shh {
}
interface Bzz {
}
const duration: {
seconds: (val: number) => number;
minutes: (val: number) => number;
hours: (val: number) => number;
days: (val: number) => number;
weeks: (val: number) => number;
years: (val: number) => number;
};
interface CancellationToken {
cancelled: boolean;
}
}