Skip to content

Commit

Permalink
Set up HARDHAT_RPC_URL constant
Browse files Browse the repository at this point in the history
  • Loading branch information
jinchung committed Dec 2, 2024
1 parent 3e97e65 commit c53d8a5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/chains/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ export const getChainDefaultRpc = (chainId: ChainId) => {
switch (chainId) {
case ChainId.mainnet:
return useConnectedToHardhatStore.getState().connectedToHardhat
? 'http://127.0.0.1:8545'
? chainHardhat.rpcUrls.default.http[0]
: defaultChains[ChainId.mainnet].rpcUrls.default.http[0];
default:
return defaultChains[chainId].rpcUrls.default.http[0];
Expand Down
9 changes: 5 additions & 4 deletions src/chains/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as chain from 'viem/chains';

const HARDHAT_CHAIN_ID = 1337;
const HARDHAT_OP_CHAIN_ID = 1338;
const HARDHAT_RPC_URL = 'http://127.0.0.1:8545/';

export enum Network {
apechain = 'apechain',
Expand Down Expand Up @@ -100,8 +101,8 @@ export const chainHardhat: chain.Chain = {
symbol: 'ETH',
},
rpcUrls: {
public: { http: ['http://127.0.0.1:8545'] },
default: { http: ['http://127.0.0.1:8545'] },
public: { http: [HARDHAT_RPC_URL] },
default: { http: [HARDHAT_RPC_URL] },
},
testnet: true,
};
Expand All @@ -115,8 +116,8 @@ export const chainHardhatOptimism: chain.Chain = {
symbol: 'ETH',
},
rpcUrls: {
public: { http: ['http://127.0.0.1:8545'] },
default: { http: ['http://127.0.0.1:8545'] },
public: { http: [HARDHAT_RPC_URL] },
default: { http: [HARDHAT_RPC_URL] },
},
testnet: true,
};
Expand Down
6 changes: 3 additions & 3 deletions src/handlers/web3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
import { ethereumUtils } from '@/utils';
import { logger, RainbowError } from '@/logger';
import { IS_IOS, RPC_PROXY_API_KEY, RPC_PROXY_BASE_URL } from '@/env';
import { ChainId } from '@/chains/types';
import { ChainId, chainHardhat } from '@/chains/types';
import { useConnectedToHardhatStore } from '@/state/connectedToHardhat';
import { defaultChains } from '@/chains';

Expand Down Expand Up @@ -111,7 +111,7 @@ export const getCachedProviderForNetwork = (chainId: ChainId = ChainId.mainnet):

export const getBatchedProvider = ({ chainId = ChainId.mainnet }: { chainId?: number }): JsonRpcBatchProvider => {
if (useConnectedToHardhatStore.getState().connectedToHardhat) {
const provider = new JsonRpcBatchProvider('http://127.0.0.1:8545/', ChainId.mainnet);
const provider = new JsonRpcBatchProvider(chainHardhat.rpcUrls.default.http[0], ChainId.mainnet);
chainsBatchProviders.set(chainId, provider);

return provider;
Expand All @@ -132,7 +132,7 @@ export const getBatchedProvider = ({ chainId = ChainId.mainnet }: { chainId?: nu

export const getProvider = ({ chainId = ChainId.mainnet }: { chainId?: number }): StaticJsonRpcProvider => {
if (useConnectedToHardhatStore.getState().connectedToHardhat) {
const provider = new StaticJsonRpcProvider('http://127.0.0.1:8545/', ChainId.mainnet);
const provider = new StaticJsonRpcProvider(chainHardhat.rpcUrls.default.http[0], ChainId.mainnet);
chainsProviders.set(chainId, provider);

return provider;
Expand Down

0 comments on commit c53d8a5

Please sign in to comment.