Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

web3-rpc-providers

Package Overview
Dependencies
Maintainers
4
Versions
81
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

web3-rpc-providers - npm Package Compare versions

Comparing version 1.0.0-dev.2706805.0 to 1.0.0-dev.3687070.0

6

lib/commonjs/errors.d.ts
import { BaseWeb3Error } from 'web3-errors';
export declare class QuickNodeRateLimitError extends BaseWeb3Error {
code: number;
constructor();
constructor(error?: Error);
}
export declare class ProviderConfigOptionsError extends BaseWeb3Error {
code: number;
constructor(msg: string);
}

@@ -19,8 +19,9 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.QuickNodeRateLimitError = void 0;
exports.ProviderConfigOptionsError = exports.QuickNodeRateLimitError = void 0;
/* eslint-disable max-classes-per-file */
const web3_errors_1 = require("web3-errors");
const ERR_QUICK_NODE_RATE_LIMIT = 1300;
class QuickNodeRateLimitError extends web3_errors_1.BaseWeb3Error {
constructor() {
super(`Too many requests, Quicknode has reached its rate limit.`);
constructor(error) {
super(`You've reach the rate limit of free RPC calls from our Partner Quick Nodes. There are two options you can either create a paid Quick Nodes account and get 20% off for 2 months using WEB3JS referral code, or use Free public RPC endpoint.`, error);
this.code = ERR_QUICK_NODE_RATE_LIMIT;

@@ -30,2 +31,11 @@ }

exports.QuickNodeRateLimitError = QuickNodeRateLimitError;
const ERR_PROVIDER_CONFIG_OPTIONS = 1301;
class ProviderConfigOptionsError extends web3_errors_1.BaseWeb3Error {
constructor(msg) {
super(`Invalid provider config options given for ${msg}`);
this.code = ERR_PROVIDER_CONFIG_OPTIONS;
}
}
exports.ProviderConfigOptionsError = ProviderConfigOptionsError;
/* eslint-enable max-classes-per-file */
//# sourceMappingURL=errors.js.map

3

lib/commonjs/index.d.ts

@@ -5,2 +5,3 @@ import { QuickNodeProvider } from './web3_provider_quicknode.js';

export * from './web3_provider.js';
export declare const mainnet: QuickNodeProvider;
export * from './errors.js';
export declare const mainnet: QuickNodeProvider<import("web3-types").EthExecutionAPI>;

@@ -38,4 +38,5 @@ "use strict";

__exportStar(require("./web3_provider.js"), exports);
__exportStar(require("./errors.js"), exports);
// default providers
exports.mainnet = new web3_provider_quicknode_js_1.QuickNodeProvider();
//# sourceMappingURL=index.js.map

@@ -0,1 +1,5 @@

/// <reference types="ws" />
/// <reference types="node" />
import { ClientOptions, ClientRequestArgs } from 'web3-providers-ws';
import { ReconnectOptions } from 'web3-utils';
export declare enum Transport {

@@ -22,1 +26,5 @@ HTTPS = "https",

}
export declare type SocketOptions = {
socketOptions?: ClientOptions | ClientRequestArgs;
reconnectOptions?: Partial<ReconnectOptions>;
};

@@ -25,3 +25,2 @@ "use strict";

})(Transport = exports.Transport || (exports.Transport = {}));
;
var Network;

@@ -45,3 +44,2 @@ (function (Network) {

})(Network = exports.Network || (exports.Network = {}));
;
//# sourceMappingURL=types.js.map

@@ -1,6 +0,9 @@

import { Transport, Network } from "./types.js";
import { Web3ExternalProvider } from "./web3_provider.js";
export declare class QuickNodeProvider extends Web3ExternalProvider {
constructor(network?: Network, transport?: Transport, token?: string, host?: string);
import { EthExecutionAPI, JsonRpcResponseWithResult, Web3APIMethod, Web3APIPayload, Web3APIReturnType, Web3APISpec } from 'web3-types';
import { HttpProviderOptions } from 'web3-providers-http';
import { Transport, Network, SocketOptions } from './types.js';
import { Web3ExternalProvider } from './web3_provider.js';
export declare class QuickNodeProvider<API extends Web3APISpec = EthExecutionAPI> extends Web3ExternalProvider {
constructor(network?: Network, transport?: Transport, token?: string, host?: string, providerConfigOptions?: HttpProviderOptions | SocketOptions);
request<Method extends Web3APIMethod<API>, ResultType = Web3APIReturnType<API, Method>>(payload: Web3APIPayload<EthExecutionAPI, Method>, requestOptions?: RequestInit): Promise<JsonRpcResponseWithResult<ResultType>>;
getRPCURL(network: Network, transport: Transport, _token: string, _host: string): string;
}

@@ -18,54 +18,86 @@ "use strict";

*/
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.QuickNodeProvider = void 0;
const web3_errors_1 = require("web3-errors");
const types_js_1 = require("./types.js");
const web3_provider_js_1 = require("./web3_provider.js");
const errors_js_1 = require("./errors.js");
const isValid = (str) => str !== undefined && str.trim().length > 0;
class QuickNodeProvider extends web3_provider_js_1.Web3ExternalProvider {
constructor(network = types_js_1.Network.ETH_MAINNET, transport = types_js_1.Transport.HTTPS, token = "", host = "") {
super(network, transport, token, host);
// eslint-disable-next-line default-param-last
constructor(network = types_js_1.Network.ETH_MAINNET, transport = types_js_1.Transport.HTTPS, token = '', host = '', providerConfigOptions) {
super(network, transport, token, host, providerConfigOptions);
}
request(payload, requestOptions) {
const _super = Object.create(null, {
request: { get: () => super.request }
});
return __awaiter(this, void 0, void 0, function* () {
try {
return yield _super.request.call(this, payload, requestOptions);
}
catch (error) {
if (error instanceof web3_errors_1.ResponseError && error.statusCode === 429) {
throw new errors_js_1.QuickNodeRateLimitError(error);
}
throw error;
}
});
}
// eslint-disable-next-line class-methods-use-this
getRPCURL(network, transport, _token, _host) {
let host = "";
let token = "";
let host = '';
let token = '';
switch (network) {
case types_js_1.Network.ETH_MAINNET:
host = isValid(_host) ? _host : "powerful-holy-bush.quiknode.pro";
token = isValid(_token) ? _token : "3240624a343867035925ff7561eb60dfdba2a668";
host = isValid(_host) ? _host : 'powerful-holy-bush.quiknode.pro';
token = isValid(_token) ? _token : '3240624a343867035925ff7561eb60dfdba2a668';
break;
case types_js_1.Network.ETH_SEPOLIA:
host = isValid(_host) ? _host : "dimensional-fabled-glitter.ethereum-sepolia.quiknode.pro";
token = isValid(_token) ? _token : "382a3b5a4b938f2d6e8686c19af4b22921fde2cd";
host = isValid(_host)
? _host
: 'dimensional-fabled-glitter.ethereum-sepolia.quiknode.pro';
token = isValid(_token) ? _token : '382a3b5a4b938f2d6e8686c19af4b22921fde2cd';
break;
case types_js_1.Network.ETH_HOLESKY:
host = isValid(_host) ? _host : "yolo-morning-card.ethereum-holesky.quiknode.pro";
token = isValid(_token) ? _token : "481ebe70638c4dcf176af617a16d02ab866b9af9";
host = isValid(_host) ? _host : 'yolo-morning-card.ethereum-holesky.quiknode.pro';
token = isValid(_token) ? _token : '481ebe70638c4dcf176af617a16d02ab866b9af9';
break;
case types_js_1.Network.ARBITRUM_MAINNET:
host = isValid(_host) ? _host : "autumn-divine-dinghy.arbitrum-mainnet.quiknode.pro";
token = isValid(_token) ? _token : "a5d7bfbf60b5ae9ce3628e53d69ef50d529e9a8c";
host = isValid(_host)
? _host
: 'autumn-divine-dinghy.arbitrum-mainnet.quiknode.pro';
token = isValid(_token) ? _token : 'a5d7bfbf60b5ae9ce3628e53d69ef50d529e9a8c';
break;
case types_js_1.Network.ARBITRUM_SEPOLIA:
host = isValid(_host) ? _host : "few-patient-pond.arbitrum-sepolia.quiknode.pro";
token = isValid(_token) ? _token : "3be985450970628c860b959c65cd2642dcafe53c";
host = isValid(_host) ? _host : 'few-patient-pond.arbitrum-sepolia.quiknode.pro';
token = isValid(_token) ? _token : '3be985450970628c860b959c65cd2642dcafe53c';
break;
case types_js_1.Network.BNB_MAINNET:
host = isValid(_host) ? _host : "purple-empty-reel.bsc.quiknode.pro";
token = isValid(_token) ? _token : "ebf6c532961e21f092ff2facce1ec4c89c540158";
host = isValid(_host) ? _host : 'purple-empty-reel.bsc.quiknode.pro';
token = isValid(_token) ? _token : 'ebf6c532961e21f092ff2facce1ec4c89c540158';
break;
case types_js_1.Network.BNB_TESTNET:
host = isValid(_host) ? _host : "floral-rough-scion.bsc-testnet.quiknode.pro";
token = isValid(_token) ? _token : "5b297e5acff5f81f4c37ebf6f235f7299b6f9d28";
host = isValid(_host) ? _host : 'floral-rough-scion.bsc-testnet.quiknode.pro';
token = isValid(_token) ? _token : '5b297e5acff5f81f4c37ebf6f235f7299b6f9d28';
break;
case types_js_1.Network.POLYGON_MAINNET:
host = isValid(_host) ? _host : "small-chaotic-moon.matic.quiknode.pro";
token = isValid(_token) ? _token : "847569f8a017e84d985e10d0f44365d965a951f1";
host = isValid(_host) ? _host : 'small-chaotic-moon.matic.quiknode.pro';
token = isValid(_token) ? _token : '847569f8a017e84d985e10d0f44365d965a951f1';
break;
case types_js_1.Network.POLYGON_AMONY:
host = isValid(_host) ? _host : "prettiest-side-shape.matic-amoy.quiknode.pro";
token = isValid(_token) ? _token : "79a9476eea661d4f82de614db1d8a895b14b881c";
host = isValid(_host) ? _host : 'prettiest-side-shape.matic-amoy.quiknode.pro';
token = isValid(_token) ? _token : '79a9476eea661d4f82de614db1d8a895b14b881c';
break;
default:
throw new Error("Network info not avalible.");
throw new Error('Network info not avalible.');
}

@@ -72,0 +104,0 @@ return `${transport}://${host}/${token}`;

@@ -1,4 +0,5 @@

import { EthExecutionAPI, JsonRpcResult, ProviderConnectInfo, ProviderMessage, ProviderRpcError, Web3APIMethod, Web3APIPayload, Web3APIReturnType, Web3APISpec, Web3BaseProvider, Web3Eip1193ProviderEventCallback, Web3ProviderEventCallback, Web3ProviderMessageEventCallback, Web3ProviderStatus, JsonRpcResponseWithResult } from "web3-types";
import { Eip1193Provider } from "web3-utils";
import { Transport, Network } from "./types.js";
import { HttpProviderOptions } from 'web3-providers-http';
import { EthExecutionAPI, JsonRpcResult, ProviderConnectInfo, ProviderMessage, ProviderRpcError, Web3APIMethod, Web3APIPayload, Web3APIReturnType, Web3APISpec, Web3BaseProvider, Web3Eip1193ProviderEventCallback, Web3ProviderEventCallback, Web3ProviderMessageEventCallback, Web3ProviderStatus, JsonRpcResponseWithResult } from 'web3-types';
import { Eip1193Provider } from 'web3-utils';
import { Transport, Network, SocketOptions } from './types.js';
export declare abstract class Web3ExternalProvider<API extends Web3APISpec = EthExecutionAPI> extends Eip1193Provider {

@@ -8,11 +9,11 @@ provider: Web3BaseProvider;

abstract getRPCURL(network: Network, transport: Transport, token: string, host: string): string;
constructor(network: Network, transport: Transport, token: string, host: string);
constructor(network: Network, transport: Transport, token: string, host: string, providerConfigOptions?: HttpProviderOptions | SocketOptions);
request<Method extends Web3APIMethod<API>, ResultType = Web3APIReturnType<API, Method>>(payload: Web3APIPayload<EthExecutionAPI, Method>, requestOptions?: RequestInit): Promise<JsonRpcResponseWithResult<ResultType>>;
getStatus(): Web3ProviderStatus;
supportsSubscriptions(): boolean;
once(type: "disconnect", listener: Web3Eip1193ProviderEventCallback<ProviderRpcError>): void;
once(type: 'disconnect', listener: Web3Eip1193ProviderEventCallback<ProviderRpcError>): void;
once<T = JsonRpcResult>(type: string, listener: Web3Eip1193ProviderEventCallback<ProviderMessage> | Web3ProviderEventCallback<T>): void;
once(type: "connect", listener: Web3Eip1193ProviderEventCallback<ProviderConnectInfo>): void;
once(type: "chainChanged", listener: Web3Eip1193ProviderEventCallback<string>): void;
once(type: "accountsChanged", listener: Web3Eip1193ProviderEventCallback<string[]>): void;
once(type: 'connect', listener: Web3Eip1193ProviderEventCallback<ProviderConnectInfo>): void;
once(type: 'chainChanged', listener: Web3Eip1193ProviderEventCallback<string>): void;
once(type: 'accountsChanged', listener: Web3Eip1193ProviderEventCallback<string[]>): void;
removeAllListeners?(_type: string): void;

@@ -22,13 +23,13 @@ connect(): void;

reset(): void;
on(type: "disconnect", listener: Web3Eip1193ProviderEventCallback<ProviderRpcError>): void;
on(type: 'disconnect', listener: Web3Eip1193ProviderEventCallback<ProviderRpcError>): void;
on<T = JsonRpcResult>(type: string, listener: Web3Eip1193ProviderEventCallback<ProviderMessage> | Web3ProviderMessageEventCallback<T>): void;
on<T = JsonRpcResult>(type: string, listener: Web3Eip1193ProviderEventCallback<ProviderMessage> | Web3ProviderMessageEventCallback<T>): void;
on(type: "connect", listener: Web3Eip1193ProviderEventCallback<ProviderConnectInfo>): void;
on(type: "chainChanged", listener: Web3Eip1193ProviderEventCallback<string>): void;
on(type: "accountsChanged", listener: Web3Eip1193ProviderEventCallback<string[]>): void;
removeListener(type: "disconnect", listener: Web3Eip1193ProviderEventCallback<ProviderRpcError>): void;
on(type: 'connect', listener: Web3Eip1193ProviderEventCallback<ProviderConnectInfo>): void;
on(type: 'chainChanged', listener: Web3Eip1193ProviderEventCallback<string>): void;
on(type: 'accountsChanged', listener: Web3Eip1193ProviderEventCallback<string[]>): void;
removeListener(type: 'disconnect', listener: Web3Eip1193ProviderEventCallback<ProviderRpcError>): void;
removeListener<T = JsonRpcResult>(type: string, listener: Web3Eip1193ProviderEventCallback<ProviderMessage> | Web3ProviderEventCallback<T>): void;
removeListener(type: "connect", listener: Web3Eip1193ProviderEventCallback<ProviderConnectInfo>): void;
removeListener(type: "chainChanged", listener: Web3Eip1193ProviderEventCallback<string>): void;
removeListener(type: "accountsChanged", listener: Web3Eip1193ProviderEventCallback<string[]>): void;
removeListener(type: 'connect', listener: Web3Eip1193ProviderEventCallback<ProviderConnectInfo>): void;
removeListener(type: 'chainChanged', listener: Web3Eip1193ProviderEventCallback<string>): void;
removeListener(type: 'accountsChanged', listener: Web3Eip1193ProviderEventCallback<string[]>): void;
}

@@ -34,3 +34,2 @@ "use strict";

const web3_providers_ws_1 = __importDefault(require("web3-providers-ws"));
const web3_validator_1 = require("web3-validator");
const web3_utils_1 = require("web3-utils");

@@ -47,10 +46,21 @@ const types_js_1 = require("./types.js");

class Web3ExternalProvider extends web3_utils_1.Eip1193Provider {
constructor(network, transport, token, host) {
constructor(network, transport, token, host, providerConfigOptions) {
super();
if (providerConfigOptions !== undefined &&
transport === types_js_1.Transport.HTTPS &&
!('providerOptions' in providerConfigOptions)) {
throw new errors_js_1.ProviderConfigOptionsError('HTTP Provider');
}
else if (providerConfigOptions !== undefined &&
transport === types_js_1.Transport.WebSocket &&
!('socketOptions' in providerConfigOptions ||
'reconnectOptions' in providerConfigOptions)) {
throw new errors_js_1.ProviderConfigOptionsError('Websocket Provider');
}
this.transport = transport;
if (transport === types_js_1.Transport.HTTPS) {
this.provider = new web3_providers_http_1.default(this.getRPCURL(network, transport, token, host));
this.provider = new web3_providers_http_1.default(this.getRPCURL(network, transport, token, host), providerConfigOptions);
}
else if (transport === types_js_1.Transport.WebSocket) {
this.provider = new web3_providers_ws_1.default(this.getRPCURL(network, transport, token, host));
this.provider = new web3_providers_ws_1.default(this.getRPCURL(network, transport, token, host), providerConfigOptions === null || providerConfigOptions === void 0 ? void 0 : providerConfigOptions.socketOptions, providerConfigOptions === null || providerConfigOptions === void 0 ? void 0 : providerConfigOptions.reconnectOptions);
}

@@ -61,8 +71,3 @@ }

if (this.transport === types_js_1.Transport.HTTPS) {
const res = yield (this.provider.request(payload, requestOptions));
if (typeof res === 'object' && !(0, web3_validator_1.isNullish)(res) && 'error' in res && !(0, web3_validator_1.isNullish)(res.error) && 'code' in res.error && res.error.code === 429) {
// rate limiting error by quicknode;
throw new errors_js_1.QuickNodeRateLimitError();
}
return res;
return (yield this.provider.request(payload, requestOptions));
}

@@ -69,0 +74,0 @@ return this.provider.request(payload);

@@ -17,10 +17,19 @@ /*

*/
/* eslint-disable max-classes-per-file */
import { BaseWeb3Error } from 'web3-errors';
const ERR_QUICK_NODE_RATE_LIMIT = 1300;
export class QuickNodeRateLimitError extends BaseWeb3Error {
constructor() {
super(`Too many requests, Quicknode has reached its rate limit.`);
constructor(error) {
super(`You've reach the rate limit of free RPC calls from our Partner Quick Nodes. There are two options you can either create a paid Quick Nodes account and get 20% off for 2 months using WEB3JS referral code, or use Free public RPC endpoint.`, error);
this.code = ERR_QUICK_NODE_RATE_LIMIT;
}
}
const ERR_PROVIDER_CONFIG_OPTIONS = 1301;
export class ProviderConfigOptionsError extends BaseWeb3Error {
constructor(msg) {
super(`Invalid provider config options given for ${msg}`);
this.code = ERR_PROVIDER_CONFIG_OPTIONS;
}
}
/* eslint-enable max-classes-per-file */
//# sourceMappingURL=errors.js.map

@@ -21,4 +21,5 @@ /*

export * from './web3_provider.js';
export * from './errors.js';
// default providers
export const mainnet = new QuickNodeProvider();
//# sourceMappingURL=index.js.map

@@ -22,3 +22,2 @@ /*

})(Transport || (Transport = {}));
;
export var Network;

@@ -42,3 +41,2 @@ (function (Network) {

})(Network || (Network = {}));
;
//# sourceMappingURL=types.js.map

@@ -17,52 +17,84 @@ /*

*/
import { Transport, Network } from "./types.js";
import { Web3ExternalProvider } from "./web3_provider.js";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import { ResponseError } from 'web3-errors';
import { Transport, Network } from './types.js';
import { Web3ExternalProvider } from './web3_provider.js';
import { QuickNodeRateLimitError } from './errors.js';
const isValid = (str) => str !== undefined && str.trim().length > 0;
export class QuickNodeProvider extends Web3ExternalProvider {
constructor(network = Network.ETH_MAINNET, transport = Transport.HTTPS, token = "", host = "") {
super(network, transport, token, host);
// eslint-disable-next-line default-param-last
constructor(network = Network.ETH_MAINNET, transport = Transport.HTTPS, token = '', host = '', providerConfigOptions) {
super(network, transport, token, host, providerConfigOptions);
}
request(payload, requestOptions) {
const _super = Object.create(null, {
request: { get: () => super.request }
});
return __awaiter(this, void 0, void 0, function* () {
try {
return yield _super.request.call(this, payload, requestOptions);
}
catch (error) {
if (error instanceof ResponseError && error.statusCode === 429) {
throw new QuickNodeRateLimitError(error);
}
throw error;
}
});
}
// eslint-disable-next-line class-methods-use-this
getRPCURL(network, transport, _token, _host) {
let host = "";
let token = "";
let host = '';
let token = '';
switch (network) {
case Network.ETH_MAINNET:
host = isValid(_host) ? _host : "powerful-holy-bush.quiknode.pro";
token = isValid(_token) ? _token : "3240624a343867035925ff7561eb60dfdba2a668";
host = isValid(_host) ? _host : 'powerful-holy-bush.quiknode.pro';
token = isValid(_token) ? _token : '3240624a343867035925ff7561eb60dfdba2a668';
break;
case Network.ETH_SEPOLIA:
host = isValid(_host) ? _host : "dimensional-fabled-glitter.ethereum-sepolia.quiknode.pro";
token = isValid(_token) ? _token : "382a3b5a4b938f2d6e8686c19af4b22921fde2cd";
host = isValid(_host)
? _host
: 'dimensional-fabled-glitter.ethereum-sepolia.quiknode.pro';
token = isValid(_token) ? _token : '382a3b5a4b938f2d6e8686c19af4b22921fde2cd';
break;
case Network.ETH_HOLESKY:
host = isValid(_host) ? _host : "yolo-morning-card.ethereum-holesky.quiknode.pro";
token = isValid(_token) ? _token : "481ebe70638c4dcf176af617a16d02ab866b9af9";
host = isValid(_host) ? _host : 'yolo-morning-card.ethereum-holesky.quiknode.pro';
token = isValid(_token) ? _token : '481ebe70638c4dcf176af617a16d02ab866b9af9';
break;
case Network.ARBITRUM_MAINNET:
host = isValid(_host) ? _host : "autumn-divine-dinghy.arbitrum-mainnet.quiknode.pro";
token = isValid(_token) ? _token : "a5d7bfbf60b5ae9ce3628e53d69ef50d529e9a8c";
host = isValid(_host)
? _host
: 'autumn-divine-dinghy.arbitrum-mainnet.quiknode.pro';
token = isValid(_token) ? _token : 'a5d7bfbf60b5ae9ce3628e53d69ef50d529e9a8c';
break;
case Network.ARBITRUM_SEPOLIA:
host = isValid(_host) ? _host : "few-patient-pond.arbitrum-sepolia.quiknode.pro";
token = isValid(_token) ? _token : "3be985450970628c860b959c65cd2642dcafe53c";
host = isValid(_host) ? _host : 'few-patient-pond.arbitrum-sepolia.quiknode.pro';
token = isValid(_token) ? _token : '3be985450970628c860b959c65cd2642dcafe53c';
break;
case Network.BNB_MAINNET:
host = isValid(_host) ? _host : "purple-empty-reel.bsc.quiknode.pro";
token = isValid(_token) ? _token : "ebf6c532961e21f092ff2facce1ec4c89c540158";
host = isValid(_host) ? _host : 'purple-empty-reel.bsc.quiknode.pro';
token = isValid(_token) ? _token : 'ebf6c532961e21f092ff2facce1ec4c89c540158';
break;
case Network.BNB_TESTNET:
host = isValid(_host) ? _host : "floral-rough-scion.bsc-testnet.quiknode.pro";
token = isValid(_token) ? _token : "5b297e5acff5f81f4c37ebf6f235f7299b6f9d28";
host = isValid(_host) ? _host : 'floral-rough-scion.bsc-testnet.quiknode.pro';
token = isValid(_token) ? _token : '5b297e5acff5f81f4c37ebf6f235f7299b6f9d28';
break;
case Network.POLYGON_MAINNET:
host = isValid(_host) ? _host : "small-chaotic-moon.matic.quiknode.pro";
token = isValid(_token) ? _token : "847569f8a017e84d985e10d0f44365d965a951f1";
host = isValid(_host) ? _host : 'small-chaotic-moon.matic.quiknode.pro';
token = isValid(_token) ? _token : '847569f8a017e84d985e10d0f44365d965a951f1';
break;
case Network.POLYGON_AMONY:
host = isValid(_host) ? _host : "prettiest-side-shape.matic-amoy.quiknode.pro";
token = isValid(_token) ? _token : "79a9476eea661d4f82de614db1d8a895b14b881c";
host = isValid(_host) ? _host : 'prettiest-side-shape.matic-amoy.quiknode.pro';
token = isValid(_token) ? _token : '79a9476eea661d4f82de614db1d8a895b14b881c';
break;
default:
throw new Error("Network info not avalible.");
throw new Error('Network info not avalible.');
}

@@ -69,0 +101,0 @@ return `${transport}://${host}/${token}`;

@@ -26,8 +26,7 @@ /*

};
import HttpProvider from "web3-providers-http";
import WebSocketProvider from "web3-providers-ws";
import { isNullish } from "web3-validator";
import { Eip1193Provider } from "web3-utils";
import { Transport } from "./types.js";
import { QuickNodeRateLimitError } from './errors.js';
import HttpProvider from 'web3-providers-http';
import WebSocketProvider from 'web3-providers-ws';
import { Eip1193Provider } from 'web3-utils';
import { Transport } from './types.js';
import { ProviderConfigOptionsError } from './errors.js';
/*

@@ -41,10 +40,21 @@ This class can be used to create new providers only when there is custom logic required in each Request method like

export class Web3ExternalProvider extends Eip1193Provider {
constructor(network, transport, token, host) {
constructor(network, transport, token, host, providerConfigOptions) {
super();
if (providerConfigOptions !== undefined &&
transport === Transport.HTTPS &&
!('providerOptions' in providerConfigOptions)) {
throw new ProviderConfigOptionsError('HTTP Provider');
}
else if (providerConfigOptions !== undefined &&
transport === Transport.WebSocket &&
!('socketOptions' in providerConfigOptions ||
'reconnectOptions' in providerConfigOptions)) {
throw new ProviderConfigOptionsError('Websocket Provider');
}
this.transport = transport;
if (transport === Transport.HTTPS) {
this.provider = new HttpProvider(this.getRPCURL(network, transport, token, host));
this.provider = new HttpProvider(this.getRPCURL(network, transport, token, host), providerConfigOptions);
}
else if (transport === Transport.WebSocket) {
this.provider = new WebSocketProvider(this.getRPCURL(network, transport, token, host));
this.provider = new WebSocketProvider(this.getRPCURL(network, transport, token, host), providerConfigOptions === null || providerConfigOptions === void 0 ? void 0 : providerConfigOptions.socketOptions, providerConfigOptions === null || providerConfigOptions === void 0 ? void 0 : providerConfigOptions.reconnectOptions);
}

@@ -55,8 +65,3 @@ }

if (this.transport === Transport.HTTPS) {
const res = yield (this.provider.request(payload, requestOptions));
if (typeof res === 'object' && !isNullish(res) && 'error' in res && !isNullish(res.error) && 'code' in res.error && res.error.code === 429) {
// rate limiting error by quicknode;
throw new QuickNodeRateLimitError();
}
return res;
return (yield this.provider.request(payload, requestOptions));
}

@@ -63,0 +68,0 @@ return this.provider.request(payload);

import { BaseWeb3Error } from 'web3-errors';
export declare class QuickNodeRateLimitError extends BaseWeb3Error {
code: number;
constructor();
constructor(error?: Error);
}
export declare class ProviderConfigOptionsError extends BaseWeb3Error {
code: number;
constructor(msg: string);
}
//# sourceMappingURL=errors.d.ts.map

@@ -5,3 +5,4 @@ import { QuickNodeProvider } from './web3_provider_quicknode.js';

export * from './web3_provider.js';
export declare const mainnet: QuickNodeProvider;
export * from './errors.js';
export declare const mainnet: QuickNodeProvider<import("web3-types").EthExecutionAPI>;
//# sourceMappingURL=index.d.ts.map

@@ -0,1 +1,5 @@

/// <reference types="ws" />
/// <reference types="node" />
import { ClientOptions, ClientRequestArgs } from 'web3-providers-ws';
import { ReconnectOptions } from 'web3-utils';
export declare enum Transport {

@@ -22,2 +26,6 @@ HTTPS = "https",

}
export declare type SocketOptions = {
socketOptions?: ClientOptions | ClientRequestArgs;
reconnectOptions?: Partial<ReconnectOptions>;
};
//# sourceMappingURL=types.d.ts.map

@@ -1,7 +0,10 @@

import { Transport, Network } from "./types.js";
import { Web3ExternalProvider } from "./web3_provider.js";
export declare class QuickNodeProvider extends Web3ExternalProvider {
constructor(network?: Network, transport?: Transport, token?: string, host?: string);
import { EthExecutionAPI, JsonRpcResponseWithResult, Web3APIMethod, Web3APIPayload, Web3APIReturnType, Web3APISpec } from 'web3-types';
import { HttpProviderOptions } from 'web3-providers-http';
import { Transport, Network, SocketOptions } from './types.js';
import { Web3ExternalProvider } from './web3_provider.js';
export declare class QuickNodeProvider<API extends Web3APISpec = EthExecutionAPI> extends Web3ExternalProvider {
constructor(network?: Network, transport?: Transport, token?: string, host?: string, providerConfigOptions?: HttpProviderOptions | SocketOptions);
request<Method extends Web3APIMethod<API>, ResultType = Web3APIReturnType<API, Method>>(payload: Web3APIPayload<EthExecutionAPI, Method>, requestOptions?: RequestInit): Promise<JsonRpcResponseWithResult<ResultType>>;
getRPCURL(network: Network, transport: Transport, _token: string, _host: string): string;
}
//# sourceMappingURL=web3_provider_quicknode.d.ts.map

@@ -1,4 +0,5 @@

import { EthExecutionAPI, JsonRpcResult, ProviderConnectInfo, ProviderMessage, ProviderRpcError, Web3APIMethod, Web3APIPayload, Web3APIReturnType, Web3APISpec, Web3BaseProvider, Web3Eip1193ProviderEventCallback, Web3ProviderEventCallback, Web3ProviderMessageEventCallback, Web3ProviderStatus, JsonRpcResponseWithResult } from "web3-types";
import { Eip1193Provider } from "web3-utils";
import { Transport, Network } from "./types.js";
import { HttpProviderOptions } from 'web3-providers-http';
import { EthExecutionAPI, JsonRpcResult, ProviderConnectInfo, ProviderMessage, ProviderRpcError, Web3APIMethod, Web3APIPayload, Web3APIReturnType, Web3APISpec, Web3BaseProvider, Web3Eip1193ProviderEventCallback, Web3ProviderEventCallback, Web3ProviderMessageEventCallback, Web3ProviderStatus, JsonRpcResponseWithResult } from 'web3-types';
import { Eip1193Provider } from 'web3-utils';
import { Transport, Network, SocketOptions } from './types.js';
export declare abstract class Web3ExternalProvider<API extends Web3APISpec = EthExecutionAPI> extends Eip1193Provider {

@@ -8,11 +9,11 @@ provider: Web3BaseProvider;

abstract getRPCURL(network: Network, transport: Transport, token: string, host: string): string;
constructor(network: Network, transport: Transport, token: string, host: string);
constructor(network: Network, transport: Transport, token: string, host: string, providerConfigOptions?: HttpProviderOptions | SocketOptions);
request<Method extends Web3APIMethod<API>, ResultType = Web3APIReturnType<API, Method>>(payload: Web3APIPayload<EthExecutionAPI, Method>, requestOptions?: RequestInit): Promise<JsonRpcResponseWithResult<ResultType>>;
getStatus(): Web3ProviderStatus;
supportsSubscriptions(): boolean;
once(type: "disconnect", listener: Web3Eip1193ProviderEventCallback<ProviderRpcError>): void;
once(type: 'disconnect', listener: Web3Eip1193ProviderEventCallback<ProviderRpcError>): void;
once<T = JsonRpcResult>(type: string, listener: Web3Eip1193ProviderEventCallback<ProviderMessage> | Web3ProviderEventCallback<T>): void;
once(type: "connect", listener: Web3Eip1193ProviderEventCallback<ProviderConnectInfo>): void;
once(type: "chainChanged", listener: Web3Eip1193ProviderEventCallback<string>): void;
once(type: "accountsChanged", listener: Web3Eip1193ProviderEventCallback<string[]>): void;
once(type: 'connect', listener: Web3Eip1193ProviderEventCallback<ProviderConnectInfo>): void;
once(type: 'chainChanged', listener: Web3Eip1193ProviderEventCallback<string>): void;
once(type: 'accountsChanged', listener: Web3Eip1193ProviderEventCallback<string[]>): void;
removeAllListeners?(_type: string): void;

@@ -22,14 +23,14 @@ connect(): void;

reset(): void;
on(type: "disconnect", listener: Web3Eip1193ProviderEventCallback<ProviderRpcError>): void;
on(type: 'disconnect', listener: Web3Eip1193ProviderEventCallback<ProviderRpcError>): void;
on<T = JsonRpcResult>(type: string, listener: Web3Eip1193ProviderEventCallback<ProviderMessage> | Web3ProviderMessageEventCallback<T>): void;
on<T = JsonRpcResult>(type: string, listener: Web3Eip1193ProviderEventCallback<ProviderMessage> | Web3ProviderMessageEventCallback<T>): void;
on(type: "connect", listener: Web3Eip1193ProviderEventCallback<ProviderConnectInfo>): void;
on(type: "chainChanged", listener: Web3Eip1193ProviderEventCallback<string>): void;
on(type: "accountsChanged", listener: Web3Eip1193ProviderEventCallback<string[]>): void;
removeListener(type: "disconnect", listener: Web3Eip1193ProviderEventCallback<ProviderRpcError>): void;
on(type: 'connect', listener: Web3Eip1193ProviderEventCallback<ProviderConnectInfo>): void;
on(type: 'chainChanged', listener: Web3Eip1193ProviderEventCallback<string>): void;
on(type: 'accountsChanged', listener: Web3Eip1193ProviderEventCallback<string[]>): void;
removeListener(type: 'disconnect', listener: Web3Eip1193ProviderEventCallback<ProviderRpcError>): void;
removeListener<T = JsonRpcResult>(type: string, listener: Web3Eip1193ProviderEventCallback<ProviderMessage> | Web3ProviderEventCallback<T>): void;
removeListener(type: "connect", listener: Web3Eip1193ProviderEventCallback<ProviderConnectInfo>): void;
removeListener(type: "chainChanged", listener: Web3Eip1193ProviderEventCallback<string>): void;
removeListener(type: "accountsChanged", listener: Web3Eip1193ProviderEventCallback<string[]>): void;
removeListener(type: 'connect', listener: Web3Eip1193ProviderEventCallback<ProviderConnectInfo>): void;
removeListener(type: 'chainChanged', listener: Web3Eip1193ProviderEventCallback<string>): void;
removeListener(type: 'accountsChanged', listener: Web3Eip1193ProviderEventCallback<string[]>): void;
}
//# sourceMappingURL=web3_provider.d.ts.map
{
"name": "web3-rpc-providers",
"version": "1.0.0-dev.2706805.0+2706805",
"version": "1.0.0-dev.3687070.0+3687070",
"description": "Web3 Providers package",

@@ -52,2 +52,3 @@ "main": "./lib/commonjs/index.js",

"eslint-plugin-import": "^2.26.0",
"isomorphic-ws": "^5.0.0",
"jest": "^29.7.0",

@@ -60,10 +61,10 @@ "jest-extended": "^3.0.1",

"dependencies": {
"web3-errors": "1.2.2-dev.2706805.0+2706805",
"web3-providers-http": "4.1.1-dev.2706805.0+2706805",
"web3-providers-ws": "4.0.9-dev.2706805.0+2706805",
"web3-types": "1.7.1-dev.2706805.0+2706805",
"web3-utils": "4.3.2-dev.2706805.0+2706805",
"web3-validator": "2.0.7-dev.2706805.0+2706805"
"web3-errors": "1.3.1-dev.3687070.0+3687070",
"web3-providers-http": "4.2.1-dev.3687070.0+3687070",
"web3-providers-ws": "4.0.9-dev.3687070.0+3687070",
"web3-types": "1.8.2-dev.3687070.0+3687070",
"web3-utils": "4.3.3-dev.3687070.0+3687070",
"web3-validator": "2.0.7-dev.3687070.0+3687070"
},
"gitHead": "270680596db7e8c2e0ee09148a042233a415c106"
"gitHead": "3687070dc165d414a0e7f2cbed91cd448b8da13a"
}

@@ -14,3 +14,2 @@ <p align="center">

## Installation

@@ -17,0 +16,0 @@

@@ -18,4 +18,5 @@ /*

/* eslint-disable max-classes-per-file */
import { BaseWeb3Error } from 'web3-errors';
import { } from 'web3-types';

@@ -26,5 +27,18 @@ const ERR_QUICK_NODE_RATE_LIMIT = 1300;

public constructor() {
super(`Too many requests, Quicknode has reached its rate limit.`);
public constructor(error?: Error) {
super(
`You've reach the rate limit of free RPC calls from our Partner Quick Nodes. There are two options you can either create a paid Quick Nodes account and get 20% off for 2 months using WEB3JS referral code, or use Free public RPC endpoint.`,
error,
);
}
}
}
const ERR_PROVIDER_CONFIG_OPTIONS = 1301;
export class ProviderConfigOptionsError extends BaseWeb3Error {
public code = ERR_PROVIDER_CONFIG_OPTIONS;
public constructor(msg: string) {
super(`Invalid provider config options given for ${msg}`);
}
}
/* eslint-enable max-classes-per-file */

@@ -23,4 +23,5 @@ /*

export * from './web3_provider.js';
export * from './errors.js';
// default providers
export const mainnet = new QuickNodeProvider();
export const mainnet = new QuickNodeProvider();

@@ -18,28 +18,37 @@ /*

import { ClientOptions, ClientRequestArgs } from 'web3-providers-ws';
import { ReconnectOptions } from 'web3-utils';
export enum Transport {
HTTPS = "https",
WebSocket = "wss"
};
HTTPS = 'https',
WebSocket = 'wss',
}
export enum Network {
ETH_MAINNET = "eth_mainnet",
ETH_GOERLI = "eth_goerli",
ETH_SEPOLIA = "eth_sepolia",
ETH_HOLESKY = "eth_holesky",
ETH_MAINNET = 'eth_mainnet',
ETH_GOERLI = 'eth_goerli',
ETH_SEPOLIA = 'eth_sepolia',
ETH_HOLESKY = 'eth_holesky',
POLYGON_MAINNET= "polygon_mainnet",
POLYGON_MUMBAI= "polygon_mumbai",
POLYGON_AMONY= "polygon_amony",
POLYGON_MAINNET = 'polygon_mainnet',
POLYGON_MUMBAI = 'polygon_mumbai',
POLYGON_AMONY = 'polygon_amony',
ARBITRUM_MAINNET = "arbitrum_mainnet",
ARBITRUM_SEPOLIA = "arbitrum_sepolia",
ARBITRUM_MAINNET = 'arbitrum_mainnet',
ARBITRUM_SEPOLIA = 'arbitrum_sepolia',
BASE_MAINNET = "base_mainnet",
BASE_SEPOLIA = "base_sepolia",
BASE_MAINNET = 'base_mainnet',
BASE_SEPOLIA = 'base_sepolia',
OPTIMISM_MAINNET = "optimism_mainnet",
OPTIMISM_SEPOLIA = "optimism_sepolia",
OPTIMISM_MAINNET = 'optimism_mainnet',
OPTIMISM_SEPOLIA = 'optimism_sepolia',
BNB_MAINNET = "bnb_mainnet",
BNB_TESTNET = "bnb_testnet"
};
BNB_MAINNET = 'bnb_mainnet',
BNB_TESTNET = 'bnb_testnet',
}
// Combining the ws types
export type SocketOptions = {
socketOptions?: ClientOptions | ClientRequestArgs;
reconnectOptions?: Partial<ReconnectOptions>;
};

@@ -18,75 +18,104 @@ /*

import { Transport, Network } from "./types.js";
import { Web3ExternalProvider } from "./web3_provider.js";
import {
EthExecutionAPI,
JsonRpcResponseWithResult,
Web3APIMethod,
Web3APIPayload,
Web3APIReturnType,
Web3APISpec,
} from 'web3-types';
import { ResponseError } from 'web3-errors';
import { HttpProviderOptions } from 'web3-providers-http';
import { Transport, Network, SocketOptions } from './types.js';
import { Web3ExternalProvider } from './web3_provider.js';
import { QuickNodeRateLimitError } from './errors.js';
const isValid = (str: string) => str !== undefined && str.trim().length > 0;
export class QuickNodeProvider extends Web3ExternalProvider {
export class QuickNodeProvider<
API extends Web3APISpec = EthExecutionAPI,
> extends Web3ExternalProvider {
// eslint-disable-next-line default-param-last
public constructor(
network: Network = Network.ETH_MAINNET,
transport: Transport = Transport.HTTPS,
token = '',
host = '',
providerConfigOptions?: HttpProviderOptions | SocketOptions,
) {
super(network, transport, token, host, providerConfigOptions);
}
public constructor(
network: Network = Network.ETH_MAINNET,
transport: Transport = Transport.HTTPS,
token = "",
host = "") {
public async request<
Method extends Web3APIMethod<API>,
ResultType = Web3APIReturnType<API, Method>,
>(
payload: Web3APIPayload<EthExecutionAPI, Method>,
requestOptions?: RequestInit,
): Promise<JsonRpcResponseWithResult<ResultType>> {
try {
return await super.request(payload, requestOptions);
} catch (error) {
if (error instanceof ResponseError && error.statusCode === 429) {
throw new QuickNodeRateLimitError(error);
}
throw error;
}
}
super(network, transport, token, host);
// eslint-disable-next-line class-methods-use-this
public getRPCURL(network: Network, transport: Transport, _token: string, _host: string) {
let host = '';
let token = '';
}
switch (network) {
case Network.ETH_MAINNET:
host = isValid(_host) ? _host : 'powerful-holy-bush.quiknode.pro';
token = isValid(_token) ? _token : '3240624a343867035925ff7561eb60dfdba2a668';
break;
case Network.ETH_SEPOLIA:
host = isValid(_host)
? _host
: 'dimensional-fabled-glitter.ethereum-sepolia.quiknode.pro';
token = isValid(_token) ? _token : '382a3b5a4b938f2d6e8686c19af4b22921fde2cd';
break;
case Network.ETH_HOLESKY:
host = isValid(_host) ? _host : 'yolo-morning-card.ethereum-holesky.quiknode.pro';
token = isValid(_token) ? _token : '481ebe70638c4dcf176af617a16d02ab866b9af9';
break;
// eslint-disable-next-line class-methods-use-this
public getRPCURL(network: Network,
transport: Transport,
_token: string,
_host: string) {
let host = "";
let token = "";
case Network.ARBITRUM_MAINNET:
host = isValid(_host)
? _host
: 'autumn-divine-dinghy.arbitrum-mainnet.quiknode.pro';
token = isValid(_token) ? _token : 'a5d7bfbf60b5ae9ce3628e53d69ef50d529e9a8c';
break;
case Network.ARBITRUM_SEPOLIA:
host = isValid(_host) ? _host : 'few-patient-pond.arbitrum-sepolia.quiknode.pro';
token = isValid(_token) ? _token : '3be985450970628c860b959c65cd2642dcafe53c';
break;
switch (network) {
case Network.ETH_MAINNET:
host = isValid(_host) ? _host : "powerful-holy-bush.quiknode.pro";
token = isValid(_token) ? _token : "3240624a343867035925ff7561eb60dfdba2a668";
break;
case Network.ETH_SEPOLIA:
host = isValid(_host) ? _host : "dimensional-fabled-glitter.ethereum-sepolia.quiknode.pro";
token = isValid(_token) ? _token : "382a3b5a4b938f2d6e8686c19af4b22921fde2cd";
break
case Network.ETH_HOLESKY:
host = isValid(_host) ? _host : "yolo-morning-card.ethereum-holesky.quiknode.pro";
token = isValid(_token) ? _token : "481ebe70638c4dcf176af617a16d02ab866b9af9";
break;
case Network.BNB_MAINNET:
host = isValid(_host) ? _host : 'purple-empty-reel.bsc.quiknode.pro';
token = isValid(_token) ? _token : 'ebf6c532961e21f092ff2facce1ec4c89c540158';
break;
case Network.BNB_TESTNET:
host = isValid(_host) ? _host : 'floral-rough-scion.bsc-testnet.quiknode.pro';
token = isValid(_token) ? _token : '5b297e5acff5f81f4c37ebf6f235f7299b6f9d28';
break;
case Network.ARBITRUM_MAINNET:
host = isValid(_host) ? _host : "autumn-divine-dinghy.arbitrum-mainnet.quiknode.pro";
token = isValid(_token) ? _token : "a5d7bfbf60b5ae9ce3628e53d69ef50d529e9a8c";
break;
case Network.ARBITRUM_SEPOLIA:
host = isValid(_host) ? _host : "few-patient-pond.arbitrum-sepolia.quiknode.pro";
token = isValid(_token) ? _token : "3be985450970628c860b959c65cd2642dcafe53c";
break;
case Network.POLYGON_MAINNET:
host = isValid(_host) ? _host : 'small-chaotic-moon.matic.quiknode.pro';
token = isValid(_token) ? _token : '847569f8a017e84d985e10d0f44365d965a951f1';
break;
case Network.POLYGON_AMONY:
host = isValid(_host) ? _host : 'prettiest-side-shape.matic-amoy.quiknode.pro';
token = isValid(_token) ? _token : '79a9476eea661d4f82de614db1d8a895b14b881c';
break;
default:
throw new Error('Network info not avalible.');
}
case Network.BNB_MAINNET:
host = isValid(_host) ? _host : "purple-empty-reel.bsc.quiknode.pro";
token = isValid(_token) ? _token : "ebf6c532961e21f092ff2facce1ec4c89c540158";
break;
case Network.BNB_TESTNET:
host = isValid(_host) ? _host : "floral-rough-scion.bsc-testnet.quiknode.pro";
token = isValid(_token) ? _token : "5b297e5acff5f81f4c37ebf6f235f7299b6f9d28";
break;
case Network.POLYGON_MAINNET:
host = isValid(_host) ? _host : "small-chaotic-moon.matic.quiknode.pro";
token = isValid(_token) ? _token : "847569f8a017e84d985e10d0f44365d965a951f1";
break;
case Network.POLYGON_AMONY:
host = isValid(_host) ? _host : "prettiest-side-shape.matic-amoy.quiknode.pro";
token = isValid(_token) ? _token : "79a9476eea661d4f82de614db1d8a895b14b881c";
break;
default:
throw new Error("Network info not avalible.");
}
return `${transport}://${host}/${token}`;
}
return `${transport}://${host}/${token}`;
}
}

@@ -18,17 +18,24 @@ /*

import HttpProvider from "web3-providers-http";
import WebSocketProvider from "web3-providers-ws";
import { isNullish } from "web3-validator";
import HttpProvider, { HttpProviderOptions } from 'web3-providers-http';
import WebSocketProvider from 'web3-providers-ws';
import {
EthExecutionAPI, JsonRpcResult, ProviderConnectInfo, ProviderMessage,
ProviderRpcError, Web3APIMethod, Web3APIPayload, Web3APIReturnType, Web3APISpec, Web3BaseProvider,
Web3Eip1193ProviderEventCallback,
Web3ProviderEventCallback,
Web3ProviderMessageEventCallback,
Web3ProviderStatus,
JsonRpcResponseWithResult,
} from "web3-types";
import { Eip1193Provider } from "web3-utils";
import { Transport, Network } from "./types.js";
import { QuickNodeRateLimitError } from './errors.js';
EthExecutionAPI,
JsonRpcResult,
ProviderConnectInfo,
ProviderMessage,
ProviderRpcError,
Web3APIMethod,
Web3APIPayload,
Web3APIReturnType,
Web3APISpec,
Web3BaseProvider,
Web3Eip1193ProviderEventCallback,
Web3ProviderEventCallback,
Web3ProviderMessageEventCallback,
Web3ProviderStatus,
JsonRpcResponseWithResult,
} from 'web3-types';
import { Eip1193Provider } from 'web3-utils';
import { Transport, Network, SocketOptions } from './types.js';
import { ProviderConfigOptionsError } from './errors.js';

@@ -43,105 +50,166 @@ /*

export abstract class Web3ExternalProvider <
API extends Web3APISpec = EthExecutionAPI,
export abstract class Web3ExternalProvider<
API extends Web3APISpec = EthExecutionAPI,
> extends Eip1193Provider {
public provider!: Web3BaseProvider;
public readonly transport: Transport;
public provider!: Web3BaseProvider;
public readonly transport: Transport;
public abstract getRPCURL(
network: Network,
transport: Transport,
token: string,
host: string,
): string;
public abstract getRPCURL(network: Network,transport: Transport,token: string, host: string): string;
public constructor(
network: Network,
transport: Transport,
token: string,
host: string,
providerConfigOptions?: HttpProviderOptions | SocketOptions,
) {
super();
public constructor(
network: Network,
transport: Transport,
token: string,
host: string) {
super();
if (
providerConfigOptions !== undefined &&
transport === Transport.HTTPS &&
!('providerOptions' in providerConfigOptions)
) {
throw new ProviderConfigOptionsError('HTTP Provider');
} else if (
providerConfigOptions !== undefined &&
transport === Transport.WebSocket &&
!(
'socketOptions' in providerConfigOptions ||
'reconnectOptions' in providerConfigOptions
)
) {
throw new ProviderConfigOptionsError('Websocket Provider');
}
this.transport = transport;
if (transport === Transport.HTTPS) {
this.provider = new HttpProvider(this.getRPCURL(network, transport, token, host));
}
else if (transport === Transport.WebSocket) {
this.provider = new WebSocketProvider(this.getRPCURL(network, transport, token, host));
}
}
this.transport = transport;
if (transport === Transport.HTTPS) {
this.provider = new HttpProvider(
this.getRPCURL(network, transport, token, host),
providerConfigOptions as HttpProviderOptions,
);
} else if (transport === Transport.WebSocket) {
this.provider = new WebSocketProvider(
this.getRPCURL(network, transport, token, host),
(providerConfigOptions as SocketOptions)?.socketOptions,
(providerConfigOptions as SocketOptions)?.reconnectOptions,
);
}
}
public async request<
Method extends Web3APIMethod<API>,
ResultType = Web3APIReturnType<API, Method>,
>(
payload: Web3APIPayload<EthExecutionAPI, Method>,
requestOptions?: RequestInit,
): Promise<JsonRpcResponseWithResult<ResultType>> {
public async request<
Method extends Web3APIMethod<API>,
ResultType = Web3APIReturnType<API, Method>,
>(
payload: Web3APIPayload<EthExecutionAPI, Method>,
requestOptions?: RequestInit,
): Promise<JsonRpcResponseWithResult<ResultType>> {
if (this.transport === Transport.HTTPS) {
return (await (this.provider as HttpProvider).request(
payload,
requestOptions,
)) as unknown as JsonRpcResponseWithResult<ResultType>;
}
if (this.transport === Transport.HTTPS) {
const res = await ( (this.provider as HttpProvider).request(payload, requestOptions)) as unknown as JsonRpcResponseWithResult<ResultType>;
if (typeof res === 'object' && !isNullish(res) && 'error' in res && !isNullish(res.error) && 'code' in res.error && (res.error as { code: number }).code === 429){
// rate limiting error by quicknode;
throw new QuickNodeRateLimitError();
}
return res;
}
return (this.provider as WebSocketProvider).request(payload);
}
return (this.provider as WebSocketProvider).request(payload);
}
public getStatus(): Web3ProviderStatus {
return this.provider.getStatus();
}
public supportsSubscriptions(): boolean {
return this.provider.supportsSubscriptions();
}
public once(type: "disconnect", listener: Web3Eip1193ProviderEventCallback<ProviderRpcError>): void;
public once<T = JsonRpcResult>(type: string, listener: Web3Eip1193ProviderEventCallback<ProviderMessage> | Web3ProviderEventCallback<T>): void;
public once(type: "connect", listener: Web3Eip1193ProviderEventCallback<ProviderConnectInfo>): void;
public once(type: "chainChanged", listener: Web3Eip1193ProviderEventCallback<string>): void;
public once(type: "accountsChanged", listener: Web3Eip1193ProviderEventCallback<string[]>): void;
public once(_type: string, _listener: unknown): void {
if (this.provider?.once)
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
this.provider.once(_type, _listener as any);
}
public removeAllListeners?(_type: string): void {
if (this.provider?.removeAllListeners)
this.provider.removeAllListeners(_type);
}
public connect(): void {
if (this.provider?.connect)
this.provider.connect();
}
public disconnect(_code?: number | undefined, _data?: string | undefined): void {
if (this.provider?.disconnect)
this.provider.disconnect(_code, _data);
}
public reset(): void {
if (this.provider?.reset)
this.provider.reset();
}
public getStatus(): Web3ProviderStatus {
return this.provider.getStatus();
}
public supportsSubscriptions(): boolean {
return this.provider.supportsSubscriptions();
}
public once(
type: 'disconnect',
listener: Web3Eip1193ProviderEventCallback<ProviderRpcError>,
): void;
public once<T = JsonRpcResult>(
type: string,
listener: Web3Eip1193ProviderEventCallback<ProviderMessage> | Web3ProviderEventCallback<T>,
): void;
public once(
type: 'connect',
listener: Web3Eip1193ProviderEventCallback<ProviderConnectInfo>,
): void;
public once(type: 'chainChanged', listener: Web3Eip1193ProviderEventCallback<string>): void;
public once(
type: 'accountsChanged',
listener: Web3Eip1193ProviderEventCallback<string[]>,
): void;
public once(_type: string, _listener: unknown): void {
if (this.provider?.once)
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
this.provider.once(_type, _listener as any);
}
public removeAllListeners?(_type: string): void {
if (this.provider?.removeAllListeners) this.provider.removeAllListeners(_type);
}
public connect(): void {
if (this.provider?.connect) this.provider.connect();
}
public disconnect(_code?: number | undefined, _data?: string | undefined): void {
if (this.provider?.disconnect) this.provider.disconnect(_code, _data);
}
public reset(): void {
if (this.provider?.reset) this.provider.reset();
}
public on(type: "disconnect", listener: Web3Eip1193ProviderEventCallback<ProviderRpcError>): void;
public on<T = JsonRpcResult>(type: string, listener: Web3Eip1193ProviderEventCallback<ProviderMessage> | Web3ProviderMessageEventCallback<T>): void;
public on<T = JsonRpcResult>(type: string, listener: Web3Eip1193ProviderEventCallback<ProviderMessage> | Web3ProviderMessageEventCallback<T>): void;
public on(type: "connect", listener: Web3Eip1193ProviderEventCallback<ProviderConnectInfo>): void;
public on(type: "chainChanged", listener: Web3Eip1193ProviderEventCallback<string>): void;
public on(type: "accountsChanged", listener: Web3Eip1193ProviderEventCallback<string[]>): void;
public on(_type: unknown, _listener: unknown): void {
if (this.provider)
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
this.provider.on(_type as any, _listener as any);
}
public removeListener(type: "disconnect", listener: Web3Eip1193ProviderEventCallback<ProviderRpcError>): void;
public removeListener<T = JsonRpcResult>(type: string, listener: Web3Eip1193ProviderEventCallback<ProviderMessage> | Web3ProviderEventCallback<T>): void;
public removeListener(type: "connect", listener: Web3Eip1193ProviderEventCallback<ProviderConnectInfo>): void;
public removeListener(type: "chainChanged", listener: Web3Eip1193ProviderEventCallback<string>): void;
public removeListener(type: "accountsChanged", listener: Web3Eip1193ProviderEventCallback<string[]>): void;
public removeListener(_type: unknown, _listener: unknown): void {
if (this.provider)
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
this.provider.removeListener(_type as any, _listener as any);
}
}
public on(
type: 'disconnect',
listener: Web3Eip1193ProviderEventCallback<ProviderRpcError>,
): void;
public on<T = JsonRpcResult>(
type: string,
listener:
| Web3Eip1193ProviderEventCallback<ProviderMessage>
| Web3ProviderMessageEventCallback<T>,
): void;
public on<T = JsonRpcResult>(
type: string,
listener:
| Web3Eip1193ProviderEventCallback<ProviderMessage>
| Web3ProviderMessageEventCallback<T>,
): void;
public on(
type: 'connect',
listener: Web3Eip1193ProviderEventCallback<ProviderConnectInfo>,
): void;
public on(type: 'chainChanged', listener: Web3Eip1193ProviderEventCallback<string>): void;
public on(type: 'accountsChanged', listener: Web3Eip1193ProviderEventCallback<string[]>): void;
public on(_type: unknown, _listener: unknown): void {
if (this.provider)
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
this.provider.on(_type as any, _listener as any);
}
public removeListener(
type: 'disconnect',
listener: Web3Eip1193ProviderEventCallback<ProviderRpcError>,
): void;
public removeListener<T = JsonRpcResult>(
type: string,
listener: Web3Eip1193ProviderEventCallback<ProviderMessage> | Web3ProviderEventCallback<T>,
): void;
public removeListener(
type: 'connect',
listener: Web3Eip1193ProviderEventCallback<ProviderConnectInfo>,
): void;
public removeListener(
type: 'chainChanged',
listener: Web3Eip1193ProviderEventCallback<string>,
): void;
public removeListener(
type: 'accountsChanged',
listener: Web3Eip1193ProviderEventCallback<string[]>,
): void;
public removeListener(_type: unknown, _listener: unknown): void {
if (this.provider)
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
this.provider.removeListener(_type as any, _listener as any);
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc