utils#INFURA_NETWORK_NAMES TypeScript Examples

The following examples show how to use utils#INFURA_NETWORK_NAMES. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InfuraService.ts    From dxvote with GNU Affero General Public License v3.0 6 votes vote down vote up
async isAuthenticated() {
    const infuraAPIKey = this.context.configStore.getLocalConfig().infura;
    const networkName = INFURA_NETWORK_NAMES[1];

    if (infuraAPIKey && infuraAPIKey.length > 0) {
      try {
        const auth = await axios({
          method: 'POST',
          url: `https://${networkName}.infura.io/v3/${infuraAPIKey}`,
          data: {
            jsonrpc: '2.0',
            method: 'eth_blockNumber',
            params: [],
            id: 1,
          },
        });
        this.auth = auth.status === 200;
      } catch (e) {
        this.auth = false;
      }
    } else {
      this.auth = false;
    }
  }
Example #2
Source File: InfuraService.ts    From dxvote with GNU Affero General Public License v3.0 6 votes vote down vote up
getRpcUrls() {
    const infuraAPIKey = this.context.configStore.getLocalConfig().infura;
    if (!infuraAPIKey) return null;

    return ETH_NETWORKS_IDS.reduce((prevUrls, chainId) => {
      const infuraNetworkName = INFURA_NETWORK_NAMES[chainId];

      let infuraUrl: string = null;
      if (infuraNetworkName) {
        infuraUrl = `https://${infuraNetworkName}.infura.io/v3/${infuraAPIKey}`;
      } else {
        infuraUrl = DEFAULT_RPC_URLS[chainId];
      }

      prevUrls[chainId] = infuraUrl;
      return prevUrls;
    }, {} as Record<number, string>);
  }