alchemy-sdk
Version:
Extended Ethers.js SDK for Alchemy APIs
136 lines (135 loc) • 5.01 kB
TypeScript
import { Listener } from '@ethersproject/abstract-provider';
import { CommunityResourcable, WebSocketProvider } from '@ethersproject/providers';
import { EthersEvent } from '../internal/ethers-event';
import { AlchemyEventType } from '../types/types';
/**
* SDK's custom implementation fo the ethers.js's 'AlchemyWebSocketProvider'.
*
* Do not call this constructor directly. Instead, instantiate an instance of
* {@link Alchemy} and call {@link Alchemy.config.getWebSocketProvider()}.
*
* @public
*/
export declare class AlchemyWebSocketProvider extends WebSocketProvider implements CommunityResourcable {
_events: Array<EthersEvent>;
readonly apiKey: string;
/**
* Overridden implementation of ethers that includes Alchemy based subscriptions.
*
* @param eventName Event to subscribe to
* @param listener The listener function to call when the event is triggered.
* @override
* @public
*/
on(eventName: AlchemyEventType, listener: Listener): this;
/**
* Overridden implementation of ethers that includes Alchemy based
* subscriptions. Adds a listener to the triggered for only the next
* {@link eventName} event, after which it will be removed.
*
* @param eventName Event to subscribe to
* @param listener The listener function to call when the event is triggered.
* @override
* @public
*/
once(eventName: AlchemyEventType, listener: Listener): this;
/**
* Removes the provided {@link listener} for the {@link eventName} event. If no
* listener is provided, all listeners for the event will be removed.
*
* @param eventName Event to unlisten to.
* @param listener The listener function to remove.
* @override
* @public
*/
off(eventName: AlchemyEventType, listener?: Listener): this;
/**
* Remove all listeners for the provided {@link eventName} event. If no event
* is provided, all events and their listeners are removed.
*
* @param eventName The event to remove all listeners for.
* @override
* @public
*/
removeAllListeners(eventName?: AlchemyEventType): this;
/**
* Returns the number of listeners for the provided {@link eventName} event. If
* no event is provided, the total number of listeners for all events is returned.
*
* @param eventName The event to get the number of listeners for.
* @public
* @override
*/
listenerCount(eventName?: AlchemyEventType): number;
/**
* Returns an array of listeners for the provided {@link eventName} event. If
* no event is provided, all listeners will be included.
*
* @param eventName The event to get the listeners for.
* @public
* @override
*/
listeners(eventName?: AlchemyEventType): Array<Listener>;
/** @override */
destroy(): Promise<void>;
/**
* Overrides the ether's `isCommunityResource()` method. Returns true if the
* current api key is the default key.
*
* @override
*/
isCommunityResource(): boolean;
private emitEvent;
/**
* DO NOT MODIFY.
*
* Original code copied over from ether.js's `BaseProvider.off()`.
*
* This method is copied over directly in order to implement Alchemy's unique
* subscription types. The only difference is that this method calls
* {@link getAlchemyEventTag} instead of the original `getEventTag()` method in
* order to parse the Alchemy subscription event.
*
* @private
*/
private _off;
/**
* DO NOT MODIFY.
*
* Original code copied over from ether.js's `BaseProvider.removeAllListeners()`.
*
* This method is copied over directly in order to implement Alchemy's unique
* subscription types. The only difference is that this method calls
* {@link getAlchemyEventTag} instead of the original `getEventTag()` method in
* order to parse the Alchemy subscription event.
*
* @private
*/
private _removeAllListeners;
/**
* DO NOT MODIFY.
*
* Original code copied over from ether.js's `BaseProvider.listenerCount()`.
*
* This method is copied over directly in order to implement Alchemy's unique
* subscription types. The only difference is that this method calls
* {@link getAlchemyEventTag} instead of the original `getEventTag()` method in
* order to parse the Alchemy subscription event.
*
* @private
*/
private _listenerCount;
/**
* DO NOT MODIFY.
*
* Original code copied over from ether.js's `BaseProvider.listeners()`.
*
* This method is copied over directly in order to implement Alchemy's unique
* subscription types. The only difference is that this method calls
* {@link getAlchemyEventTag} instead of the original `getEventTag()` method in
* order to parse the Alchemy subscription event.
*
* @private
*/
private _listeners;
}