necjs
Version:
NECJS SDK for NCOG Earth Chain RPC
102 lines (101 loc) • 4.15 kB
TypeScript
import { Interface } from 'ethers';
import { Provider } from './provider';
import { TxParams } from './extension';
export interface ISigner {
sendTransaction(tx: TxParams): Promise<string>;
getAddress?(): Promise<string>;
}
export declare function mergeArrayAndKeys(decoded: any, outputs: ReadonlyArray<any>): any;
/**
* Recursively convert ethers.js Result/Proxy (including nested arrays/structs) to plain objects using ABI outputs.
* If outputs are provided, use them to map arrays/tuples to named objects.
*/
export declare function toPlainObject(result: any, outputs?: any): any;
/**
* Represents a smart contract on the blockchain, providing methods to call and send transactions.
* Now supports web3.js-style dynamic method calls: contract.methods.myMethod(...args).call(), .send(), .estimateGas()
*/
export declare class Contract {
provider: Provider;
private signer?;
readonly address: string;
readonly abiInterface: Interface;
readonly methods: Record<string, (...args: any[]) => {
call: (options?: Record<string, any>) => Promise<any>;
send: (options: Record<string, any>) => Promise<string>;
estimateGas: (options?: Record<string, any>) => Promise<number>;
nativeSend: (options?: Record<string, any>) => Promise<TxParams>;
}>;
readonly events: Record<string, (options?: {
fromBlock?: string | number;
toBlock?: string | number;
filter?: Record<string, any>;
}) => EventStream>;
constructor(address: string, abi: any[], provider: Provider, signer?: ISigner);
call(method: string, params?: any[], options?: Record<string, any>): Promise<any>;
send(method: string, params: any[], options: Record<string, any>): Promise<string>;
estimateGas(method: string, params?: any[], options?: Record<string, any>): Promise<number>;
nativeSend(method: string, params: any[], options: Record<string, any>): Promise<TxParams>;
/**
* Deploy a new contract to the blockchain.
* @param abi The contract ABI
* @param bytecode The contract bytecode (0x...)
* @param provider The Provider instance
* @param deployer The address or signer sending the deployment
* @param constructorArgs Arguments for the contract constructor
* @param options Additional tx options (gas, gasPrice, value, nonce, etc.)
* @returns The transaction hash of the deployment
*/
static deploy({ abi, bytecode, provider, deployer, constructorArgs, options }: {
abi: any[];
bytecode: string;
provider: Provider;
deployer: string | ISigner;
constructorArgs?: any[];
options?: Record<string, any>;
}): Promise<{
contractAddress: string;
txHash: string;
receipt: any;
}>;
/**
* Verify a contract on a block explorer (e.g., Etherscan-compatible API).
* @param params Verification parameters (API URL, API key, contract address, source, etc.)
* @returns The verification result from the explorer
*/
static verify(params: {
apiUrl: string;
apiKey: string;
contractAddress: string;
sourceCode: string;
contractName: string;
compilerVersion: string;
constructorArguments?: string;
optimizationUsed?: boolean;
runs?: number;
licenseType?: string;
[key: string]: any;
}): Promise<any>;
}
/**
* EventStream provides a web3.js-compatible event stream for contract events.
* Usage: contract.events.MyEvent({ fromBlock, toBlock, filter }).on('data', handler)
*/
export declare class EventStream {
private contract;
private eventName;
private options;
private subscription?;
private listeners;
private active;
constructor(contract: Contract, eventName: string, options: {
fromBlock?: string | number;
toBlock?: string | number;
filter?: Record<string, any>;
});
on(event: 'data' | 'changed' | 'error', handler: Function): this;
off(event: 'data' | 'changed' | 'error', handler: Function): this;
private emit;
private start;
stop(): Promise<void>;
}