Skip to content

Commit 6bd13c3

Browse files
committedJul 27, 2022
Updated EtherscanProvider for new CommunityResource API throttling.

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed
 

‎packages/providers/src.ts/etherscan-provider.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function getResult(result: { status?: number, message?: string, result?: any }):
4545
return result.result;
4646
}
4747

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

9595

96-
const defaultApiKey = "9D13ZE7XSBTJ94N9BNJ2MA33VMAY2YPIRB";
97-
9896
function checkError(method: string, error: any, transaction: any): any {
9997
// Undo the "convenience" some nodes are attempting to prevent backwards
10098
// incompatibility; maybe for v6 consider forwarding reverts as errors
@@ -160,13 +158,13 @@ function checkError(method: string, error: any, transaction: any): any {
160158

161159
export class EtherscanProvider extends BaseProvider{
162160
readonly baseUrl: string;
163-
readonly apiKey: string;
161+
readonly apiKey: string | null;
164162

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

168166
defineReadOnly(this, "baseUrl", this.getBaseUrl());
169-
defineReadOnly(this, "apiKey", apiKey || defaultApiKey);
167+
defineReadOnly(this, "apiKey", apiKey || null);
170168
}
171169

172170
getBaseUrl(): string {
@@ -447,6 +445,6 @@ export class EtherscanProvider extends BaseProvider{
447445
}
448446

449447
isCommunityResource(): boolean {
450-
return (this.apiKey === defaultApiKey);
448+
return (this.apiKey == null);
451449
}
452450
}

0 commit comments

Comments
 (0)
Please sign in to comment.