ethers.js/src.ts/providers/community.ts

50 lines
1.8 KiB
TypeScript
Raw Normal View History

2022-11-30 21:44:47 +03:00
/**
* There are many awesome community services that provide Ethereum
* nodes both for developers just starting out and for large-scale
* communities.
*
* @_section: api/providers/thirdparty: Community Providers [thirdparty]
*/
2022-12-03 05:23:13 +03:00
/**
* Providers which offer community credentials should extend this
* to notify any interested consumers whether community credentials
* are in-use.
*/
2022-09-05 23:14:43 +03:00
export interface CommunityResourcable {
2022-12-03 05:23:13 +03:00
/**
* Returns true of the instance is connected using the community
* credentials.
*/
2022-09-05 23:14:43 +03:00
isCommunityResource(): boolean;
}
2022-12-03 05:23:13 +03:00
// Show the throttle message only once per service
2022-09-05 23:14:43 +03:00
const shown: Set<string> = new Set();
2022-12-03 05:23:13 +03:00
/**
* Displays a warning in tht console when the community resource is
* being used too heavily by the app, recommending the developer
* acquire their own credentials instead of using the community
* credentials.
*
* The notification will only occur once per service.
*/
2022-11-28 05:58:07 +03:00
export function showThrottleMessage(service: string): void {
2022-09-05 23:14:43 +03:00
if (shown.has(service)) { return; }
shown.add(service);
console.log("========= NOTICE =========")
console.log(`Request-Rate Exceeded for ${ service } (this message will not be repeated)`);
console.log("");
console.log("The default API keys for each service are provided as a highly-throttled,");
console.log("community resource for low-traffic projects and early prototyping.");
console.log("");
console.log("While your application will continue to function, we highly recommended");
console.log("signing up for your own API keys to improve performance, increase your");
console.log("request rate/limit and enable other perks, such as metrics and advanced APIs.");
console.log("");
console.log("For more details: https:/\/docs.ethers.org/api-keys/");
2022-09-05 23:14:43 +03:00
console.log("==========================");
}