Skip to content

Commit

Permalink
Updated EtherscanProvider for new CommunityResource API throttling.
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed Jul 27, 2022
1 parent ea2d245 commit 6bd13c3
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions packages/providers/src.ts/etherscan-provider.ts
Expand Up @@ -45,7 +45,7 @@ function getResult(result: { status?: number, message?: string, result?: any }):
return result.result;
}

if (result.status != 1 || result.message != "OK") {
if (result.status != 1 || typeof(result.message) !== "string" || !result.message.match(/^OK/)) {
const error: any = new Error("invalid response");
error.result = JSON.stringify(result);
if ((result.result || "").toLowerCase().indexOf("rate limit") >= 0) {
Expand Down Expand Up @@ -93,8 +93,6 @@ function checkLogTag(blockTag: string): number | "latest" {
}


const defaultApiKey = "9D13ZE7XSBTJ94N9BNJ2MA33VMAY2YPIRB";

function checkError(method: string, error: any, transaction: any): any {
// Undo the "convenience" some nodes are attempting to prevent backwards
// incompatibility; maybe for v6 consider forwarding reverts as errors
Expand Down Expand Up @@ -160,13 +158,13 @@ function checkError(method: string, error: any, transaction: any): any {

export class EtherscanProvider extends BaseProvider{
readonly baseUrl: string;
readonly apiKey: string;
readonly apiKey: string | null;

constructor(network?: Networkish, apiKey?: string) {
super(network);

defineReadOnly(this, "baseUrl", this.getBaseUrl());
defineReadOnly(this, "apiKey", apiKey || defaultApiKey);
defineReadOnly(this, "apiKey", apiKey || null);
}

getBaseUrl(): string {
Expand Down Expand Up @@ -447,6 +445,6 @@ export class EtherscanProvider extends BaseProvider{
}

isCommunityResource(): boolean {
return (this.apiKey === defaultApiKey);
return (this.apiKey == null);
}
}

0 comments on commit 6bd13c3

Please sign in to comment.