web3x
Version:
Typescript port of web3.js
63 lines (62 loc) • 2.56 kB
TypeScript
import { Address } from '../address';
import { Eth } from '../eth';
import { EventLog, LogRequest } from '../formatters';
import { Subscription } from '../subscriptions';
import { Data } from '../types';
import { ContractAbi } from './abi';
import { Tx } from './tx';
import { TxDeploy } from './tx-deploy';
export interface ContractOptions {
from?: Address;
gasPrice?: string | number;
gas?: number;
}
interface ContractDefinition {
methods: any;
events?: any;
eventLogs?: any;
}
export declare type EventSubscriptionFactory<Result = EventLog<any>> = (options?: object, callback?: (err: Error, result: Result, subscription: Subscription<Result>) => void) => Subscription<Result>;
declare type Events<T extends ContractDefinition | void> = T extends ContractDefinition ? Extract<keyof T['events'], string> : string;
declare type GetEventLog<T extends ContractDefinition | void, P extends Events<T>> = T extends ContractDefinition ? T['eventLogs'][P] : EventLog<any>;
declare type GetContractMethods<T> = T extends ContractDefinition ? T['methods'] : {
[key: string]: (...args: any[]) => Tx;
};
declare type GetContractEvents<T> = T extends ContractDefinition ? T['events'] & {
allEvents: EventSubscriptionFactory<T['eventLogs'][Events<T>]>;
} : {
[key: string]: EventSubscriptionFactory;
};
/**
* Should be called to create new contract instance
*
* @method Contract
* @constructor
* @param {Array} jsonInterface
* @param {String} address
* @param {Object} options
*/
export declare class Contract<T extends ContractDefinition | void = void> {
private eth;
private contractAbi;
address?: Address | undefined;
private defaultOptions;
readonly methods: GetContractMethods<T>;
readonly events: GetContractEvents<T>;
private linkTable;
constructor(eth: Eth, contractAbi: ContractAbi, address?: Address | undefined, defaultOptions?: ContractOptions);
link(name: string, address: Address): void;
deployBytecode(data: Data, ...args: any[]): TxDeploy;
once<Event extends Events<T>>(event: Event, options: {
filter?: object;
topics?: string[];
}, callback: (err: any, res: GetEventLog<T, Event>, sub: any) => void): any;
getPastEvents<Event extends Events<T>>(event: Event, options: LogRequest): Promise<GetEventLog<T, Event>[]>;
getPastEvents(event: 'allevents', options: LogRequest): Promise<EventLog<any>[]>;
private on;
private executorFactory;
private buildMethods;
private buildEvents;
private getLogOptions;
}
export {};