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

67.34% Statements 33/49
100% Branches 0/0
0% Functions 0/1
67.34% Lines 33/49

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 501x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x                                  
/**
 *  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]
 */
 
/**
 *  Providers which offer community credentials should extend this
 *  to notify any interested consumers whether community credentials
 *  are in-use.
 */
export interface CommunityResourcable {
    /**
     *  Returns true if the instance is connected using the community
     *  credentials.
     */
    isCommunityResource(): boolean;
}
 
// Show the throttle message only once per service
const shown: Set<string> = new Set();
 
/**
 *  Displays a warning in the 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.
 */
export function showThrottleMessage(service: string): void {
    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/");
    console.log("==========================");
}