community.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /**
  2. * There are many awesome community services that provide Ethereum
  3. * nodes both for developers just starting out and for large-scale
  4. * communities.
  5. *
  6. * @_section: api/providers/thirdparty: Community Providers [thirdparty]
  7. */
  8. /**
  9. * Providers which offer community credentials should extend this
  10. * to notify any interested consumers whether community credentials
  11. * are in-use.
  12. */
  13. export interface CommunityResourcable {
  14. /**
  15. * Returns true of the instance is connected using the community
  16. * credentials.
  17. */
  18. isCommunityResource(): boolean;
  19. }
  20. // Show the throttle message only once per service
  21. const shown: Set<string> = new Set();
  22. /**
  23. * Displays a warning in tht console when the community resource is
  24. * being used too heavily by the app, recommending the developer
  25. * acquire their own credentials instead of using the community
  26. * credentials.
  27. *
  28. * The notification will only occur once per service.
  29. */
  30. export function showThrottleMessage(service: string): void {
  31. if (shown.has(service)) { return; }
  32. shown.add(service);
  33. console.log("========= NOTICE =========")
  34. console.log(`Request-Rate Exceeded for ${ service } (this message will not be repeated)`);
  35. console.log("");
  36. console.log("The default API keys for each service are provided as a highly-throttled,");
  37. console.log("community resource for low-traffic projects and early prototyping.");
  38. console.log("");
  39. console.log("While your application will continue to function, we highly recommended");
  40. console.log("signing up for your own API keys to improve performance, increase your");
  41. console.log("request rate/limit and enable other perks, such as metrics and advanced APIs.");
  42. console.log("");
  43. console.log("For more details: https:/\/docs.ethers.org/api-keys/");
  44. console.log("==========================");
  45. }