Skip to content

Commit

Permalink
fix(api): getting provider from config
Browse files Browse the repository at this point in the history
  • Loading branch information
gabaldon committed Mar 11, 2022
1 parent 670d069 commit 78cea10
Showing 1 changed file with 7 additions and 21 deletions.
28 changes: 7 additions & 21 deletions packages/api/src/web3Middleware/provider.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,11 @@
import { Network } from './../types'

export function getProvider (network: Network) {
const providers: Record<Network, string> = {
[Network.EthereumMainnet]: process.env.ETHEREUM_MAINNET_PROVIDER,
[Network.EthereumGoerli]: process.env.ETHEREUM_GOERLI_PROVIDER,
[Network.EthereumRinkeby]: process.env.ETHEREUM_RINKEBY_PROVIDER,
[Network.ConfluxTestnet]: process.env.CONFLUX_TESTNET_PROVIDER,
[Network.ConfluxTethys]: process.env.CONFLUX_TETHYS_PROVIDER,
[Network.BobaRinkeby]: process.env.BOBA_RINKEBY_PROVIDER,
[Network.BobaMainnet]: process.env.BOBA_MAINNET_PROVIDER,
[Network.CeloAlfajores]: process.env.CELO_ALFAJORES_PROVIDER,
[Network.CeloMainnet]: process.env.CELO_MAINNET_PROVIDER,
[Network.MetisMainnet]: process.env.METIS_MAINNET_PROVIDER,
[Network.MetisRinkeby]: process.env.METIS_RINKEBY_PROVIDER,
[Network.HarmonyTestnet]: process.env.HARMONY_TESTNET_PROVIDER,
[Network.KCCTestnet]: process.env.KCC_TESTNET_PROVIDER,
[Network.KCCMainnet]: process.env.KCC_MAINNET_PROVIDER,
[Network.MoonbeamMoonbase]: process.env.MOONBASE_ALPHA_PROVIDER,
[Network.PolygonMainnet]: process.env.POLYGON_MAINNET_PROVIDER,
[Network.PolygonGoerli]: process.env.POLYGON_GOERLI_PROVIDER,
[Network.AvalancheFuji]: process.env.AVALANCHE_FUJI_PROVIDER
}
return providers[network]
// The provider env variable name should be the network name specified in the config plus '_PROVIDER' ex.MOONBEAM_MOONBASE_PROVIDER
return process.env[
`${network
.split('-')
.map(network => network.toUpperCase())
.join('_')}_PROVIDER`
]
}

0 comments on commit 78cea10

Please sign in to comment.