get alchemy provider api url from env and use it to get provider
Co-authored-by: brunoedcf <brest.dallacosta@outlook.com>
This commit is contained in:
parent
86131b5641
commit
f8e1b888ba
@ -1,3 +1,3 @@
|
||||
VITE_API_URL=http://localhost:8000/
|
||||
VITE_GOERLI_API_KEY={GOERLI_API_KEY_ALCHEMY}
|
||||
VITE_MUMBAI_API_KEY={MUMBAI_API_KEY_ALCHEMY}
|
||||
VITE_GOERLI_API_URL={GOERLI_API_URL_ALCHEMY}
|
||||
VITE_MUMBAI_API_URL={MUMBAI_API_URL_ALCHEMY}
|
@ -3,12 +3,24 @@ import { useEtherStore } from "@/store/ether";
|
||||
import { NetworkEnum } from "@/model/NetworkEnum";
|
||||
import { updateWalletStatus } from "./wallet";
|
||||
|
||||
const getProviderUrl = (): string => {
|
||||
const etherStore = useEtherStore();
|
||||
|
||||
const possibleProvidersUrls: {[key: string]: string} = {
|
||||
Ethereum: import.meta.env.VITE_GOERLI_API_URL,
|
||||
Polygon: import.meta.env.VITE_MUMBAI_API_URL,
|
||||
Localhost: import.meta.env.VITE_GOERLI_API_URL
|
||||
}
|
||||
|
||||
return possibleProvidersUrls[etherStore.networkName]
|
||||
}
|
||||
|
||||
const getProvider = (): ethers.providers.Web3Provider | ethers.providers.JsonRpcProvider => {
|
||||
const window_ = window as any;
|
||||
const connection = window_.ethereum;
|
||||
|
||||
if (!connection)
|
||||
return new ethers.providers.JsonRpcProvider("provider_url"); // alchemy provider
|
||||
if (!connection)
|
||||
return new ethers.providers.JsonRpcProvider(getProviderUrl()); // alchemy provider
|
||||
|
||||
return new ethers.providers.Web3Provider(connection); // metamask provider
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user