utils#ALCHEMY_NETWORK_URLS TypeScript Examples

The following examples show how to use utils#ALCHEMY_NETWORK_URLS. 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: AlchemyService.ts    From dxvote with GNU Affero General Public License v3.0 6 votes vote down vote up
async isAuthenticated() {
    const alchemyAPIKey = this.context.configStore.getLocalConfig().alchemy;
    const networkUrl = ALCHEMY_NETWORK_URLS[1];

    if (alchemyAPIKey && alchemyAPIKey.length > 0) {
      try {
        const auth = await axios({
          method: 'POST',
          url: `https://${networkUrl}/v2/${alchemyAPIKey}`,
          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: AlchemyService.ts    From dxvote with GNU Affero General Public License v3.0 6 votes vote down vote up
getRpcUrls() {
    const alchemyAPIKey = this.context.configStore.getLocalConfig().alchemy;
    if (!alchemyAPIKey) return null;

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

      let alchemyUrl: string = null;
      if (networkUrl) {
        alchemyUrl = `https://${networkUrl}/v2/${alchemyAPIKey}`;
      } else {
        alchemyUrl = DEFAULT_RPC_URLS[chainId];
      }

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