necjs
Version:
NECJS SDK for NCOG Earth Chain RPC
66 lines (65 loc) • 2.21 kB
TypeScript
import { Provider } from './provider';
/**
* Defines the parameters for a transaction to be sent via an extension.
*/
export interface TxParams {
from: string;
nonce: any;
gasPrice: string;
gasLimit?: string;
gas?: string;
to: string;
value?: string;
data?: string;
chainId?: number;
}
/**
* Describes the interface for an injected NCOG wallet provider (e.g., from a browser extension).
*/
export interface InjectedProvider {
/**
* Sends a request to the wallet.
* @param args The request arguments, including method and parameters.
*/
request(args: {
method: string;
params?: any[];
}): Promise<any>;
/**
* Subscribes to events emitted by the wallet.
* @param event The event name (e.g., 'accountsChanged').
* @param listener The callback function.
*/
on?(event: string, listener: (...args: any[]) => void): void;
}
/**
* A Signer implementation that wraps an injected browser extension wallet.
*/
export declare class ExtensionSigner {
private injected;
private provider;
/**
* @param injected The injected provider object from the browser (e.g., `window.ncogWallet`).
* @param provider A read-only `Provider` instance for querying blockchain data.
*/
constructor(injected: InjectedProvider, provider: Provider);
/**
* Retrieves the currently selected address from the extension wallet.
* @returns A promise that resolves to the user's account address.
* @throws {Error} if no account is selected or available.
*/
getAddress(): Promise<string>;
/**
* Registers a listener for an event from the wallet (e.g., 'accountsChanged', 'chainChanged').
* @param event The name of the event.
* @param listener The callback function to execute when the event fires.
*/
on(event: string, listener: (...args: any[]) => void): void;
/**
* Signs and sends a transaction through the extension wallet.
* The wallet will prompt the user for confirmation.
* @param tx The transaction parameters.
* @returns A promise that resolves to the transaction hash.
*/
sendTransaction(tx: TxParams): Promise<string>;
}