Skip to content

Commit

Permalink
Added initial AnkrProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed Mar 19, 2022
1 parent b1c7f5c commit 96de581
Show file tree
Hide file tree
Showing 6 changed files with 191 additions and 6 deletions.
77 changes: 77 additions & 0 deletions .github/ISSUE_TEMPLATE/test-bug-report.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: Bug Report Test Form
description: Bug Report Test Form
title: "Bug Report"
labels: ["investigate"]
assignees:
- ricmoo
body:
- type: markdown
attributes:
value: |
Thank you for taking the time to report an issue. But please **read this first**.
- type: markdown
attributes:
value: |
This issue template is for reporting **bugs within ethers**. If you are new to ethers or uncertain whether this is a bug in ethers, a bug in another framework or a bug in your own code, please start a [discussion first](https://github.com/ethers-io/ethers.js/discussions) first.
- type: input
id: version
attributes:
label: Ethers Version
description: What version of ethers are you using? Before opening an issue, please make sure you are up to date.
placeholder: x.y.z
validations:
required: true
- type: checkboxes
id: search-check
attributes:
label: Have you searched existing issues?
description: Have you searched for answers [in the documentation](https://docs.ethers.io), [through the issues](https://github.com/ethers-io/ethers.js/issues) and [on the discusions](https://github.com/ethers-io/ethers.js/discussions)?
options:
- label: I have searched the existing issues
required: true
- type: input
id: search-terms
attributes:
label: Search Terms
description: Please include the search terms you have tried. This helps us add more keywords where needed.
placeholder: e.g. abi, network, utf8
- type: textarea
id: about-the-bug
attributes:
label: Describe the bug. What did you expect to happen vs what did happen?
placeholder: What happened?
validations:
required: true
- type: textarea
id: code-snippet
attributes:
label: Code Snippet
description: Please include any **short and concise** code snippets that can reproduce this issue. Ideally code that can be pasted into the [Ethers Playground](https://playground.ethers.org).
placeholder: provider.getBlockNumber()
render: shell
- type: textarea
id: contract-abi
attributes:
label: Contract ABI
description: If this involves a contract, please include any **concise and relevant** ABI fragments.
placeholder: contract ABI
render: shell
- type: checkboxes
id: environment
attributes:
label: Environment
decsription: What environment or frameworks are you using?
options:
- label: node.js (v12 or newer)
- label: node.js (older than v12)
- label: Browser (Chrome, Safari, etc)
- label: React Native/Expo/JavaScriptCore
- label: Hardhat
- label: Geth
- label: Parity
- label: Ganache
- type: input
id: other-envrionment
attributes:
label: Other Environment
placeholder: anything else?
41 changes: 35 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ A complete Ethereum wallet implementation and utilities in JavaScript (and TypeS
Keep Updated
------------

For the latest news and advisories, please follow the [@ethersproject](https://twitter.com/ethersproject)
on Twitter (low-traffic, non-marketing, important information only) as well as watch this GitHub project.
For the latest news and advisories, please follow the
[@ethersproject](https://twitter.com/ethersproject) on Twitter (low-traffic,
non-marketing, important information only) as well as watch this GitHub project.

For the latest changes, see the [CHANGELOG](https://github.com/ethers-io/ethers.js/blob/master/CHANGELOG.md).
For the latest changes, see the
[CHANGELOG](https://github.com/ethers-io/ethers.js/blob/master/CHANGELOG.md).


Installing
Expand All @@ -44,15 +46,15 @@ Installing
**browser (UMD)**

```
<script src="https://cdn.ethers.io/lib/ethers-5.1.umd.min.js" type="text/javascript">
<script src="https://cdn.ethers.io/lib/ethers-5.6.umd.min.js" type="text/javascript">
</script>
```

**browser (ESM)**

```
<script type="module">
import { ethers } from "https://cdn.ethers.io/lib/ethers-5.1.esm.min.js";
import { ethers } from "https://cdn.ethers.io/lib/ethers-5.6.esm.min.js";
</script>
```

Expand All @@ -66,7 +68,34 @@ Browse the [documentation](https://docs.ethers.io/v5/) online:
- [Full API Documentation](https://docs.ethers.io/v5/api/)
- [Various Ethereum Articles](https://blog.ricmoo.com/)

Or browse the entire documentation as a [single page](https://docs.ethers.io/v5/single-page/) to make searching easier.

Providers
---------

Ethers works closely with an ever-growing list of third-party providers
to ensure getting started is quick and easy, by providing default keys
to each service.

These built-in keys mean you can use `ethers.getDefaultProvider()` and
start developing right away.

However, the API keys provided to ethers are also shared and are
intentionally throttled to encourage developers to eventually get
their own keys, which unlock many other features, such as faster
responses, more capacity, analytics and other features like archival
data.

When you are ready to sign up and start using for your own keys, please
check out the [Provider API Keys](https://docs.ethers.io/v5/api-keys/) in
the documentation.

A special thanks to these services for providing community resources:

- [Etherscan](https://etherscan.io/)
- [INFURA](https://infura.io/)
- [Alchemy](https://dashboard.alchemyapi.io/signup?referral=55a35117-028e-4b7c-9e47-e275ad0acc6d)
- [Pocket](https://pokt.network/pocket-gateway-ethereum-mainnet/)
- [Ankr](https://www.ankr.com/)


Ancillary Packages
Expand Down
6 changes: 6 additions & 0 deletions packages/networks/src.ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ function ethDefaultProvider(network: string | Network): Renetworkable {
} catch(error) { }
}

if (providers.AnkrProvider && options.ankr !== "-") {
try {
providerList.push(new providers.AnkrProvider(network, options.ankr));
} catch(error) { }
}

if (providerList.length === 0) { return null; }

if (providers.FallbackProvider) {
Expand Down
60 changes: 60 additions & 0 deletions packages/providers/src.ts/ankr-provider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@

import { Network } from "@ethersproject/networks";

import { showThrottleMessage } from "./formatter";
import { UrlJsonRpcProvider } from "./url-json-rpc-provider";

import type { ConnectionInfo } from "@ethersproject/web";

import { Logger } from "@ethersproject/logger";
import { version } from "./_version";
const logger = new Logger(version);


const defaultApiKey = "9f7d929b018cdffb338517efa06f58359e86ff1ffd350bc889738523659e7972";

function getHost(name: string): string {
switch (name) {
case "homestead":
return "rpc.ankr.com/eth/";
case "matic":
return "rpc.ankr.com/polygon/";
case "arbitrum":
return "rpc.ankr.com/arbitrum/";
}
return logger.throwArgumentError("unsupported network", "name", name);
}

export class AnkrProvider extends UrlJsonRpcProvider {
readonly apiKey: string;

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

static getApiKey(apiKey: any): any {
if (apiKey == null) { return defaultApiKey; }
return apiKey;
}

static getUrl(network: Network, apiKey: any): ConnectionInfo {
if (apiKey == null) { apiKey = defaultApiKey; }
const connection: ConnectionInfo = {
allowGzip: true,
url: ("https:/\/" + getHost(network.name) + apiKey),
throttleCallback: (attempt: number, url: string) => {
if (apiKey.apiKey === defaultApiKey) {
showThrottleMessage();
}
return Promise.resolve(true);
}
};

if (apiKey.projectSecret != null) {
connection.user = "";
connection.password = apiKey.projectSecret
}

return connection;
}
}
3 changes: 3 additions & 0 deletions packages/providers/src.ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { Network, Networkish } from "@ethersproject/networks";
import { BaseProvider, EnsProvider, EnsResolver, Resolver } from "./base-provider";

import { AlchemyProvider, AlchemyWebSocketProvider } from "./alchemy-provider";
import { AnkrProvider } from "./ankr-provider";
import { CloudflareProvider } from "./cloudflare-provider";
import { EtherscanProvider } from "./etherscan-provider";
import { FallbackProvider, FallbackProviderConfig } from "./fallback-provider";
Expand Down Expand Up @@ -76,6 +77,7 @@ function getDefaultProvider(network?: Networkish, options?: any): BaseProvider {
FallbackProvider,

AlchemyProvider,
AnkrProvider,
CloudflareProvider,
EtherscanProvider,
InfuraProvider,
Expand Down Expand Up @@ -108,6 +110,7 @@ export {

AlchemyProvider,
AlchemyWebSocketProvider,
AnkrProvider,
CloudflareProvider,
EtherscanProvider,
InfuraProvider,
Expand Down
10 changes: 10 additions & 0 deletions packages/tests/src.ts/test-providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,16 @@ const providerFunctions: Array<ProviderDescription> = [
return new ethers.providers.AlchemyProvider(network, getApiKeys(network).alchemy);
}
},
{
name: "AnkrProvider",
networks: [ "default", "homestead" ],
create: (network: string) => {
if (network == "default") {
return new ethers.providers.AnkrProvider(null);
}
return new ethers.providers.AnkrProvider(network);
}
},
/*
{
name: "CloudflareProvider",
Expand Down

0 comments on commit 96de581

Please sign in to comment.