Skip to content

Commit 1736925

Browse files
authored
Merge pull request #1164 from makerdao/rpc-config-updates
Refactor RPC configuration
2 parents c7c9158 + 1a7af6c commit 1736925

File tree

8 files changed

+32
-42
lines changed

8 files changed

+32
-42
lines changed

.env.sample

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# see README for information on env variables
22

3-
INFURA_KEY=
4-
ALCHEMY_KEY=
3+
54
ETHERSCAN_V2_API_KEY=
65
GITHUB_TOKEN=
76
USE_CACHE=true
@@ -13,6 +12,10 @@ DASHBOARD_PASSWORD=
1312
NEXT_PUBLIC_TENDERLY_RPC_KEY=
1413
NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID=
1514
NEXT_PUBLIC_SUBGRAPH_API_KEY=
15+
NEXT_PUBLIC_RPC_MAINNET=
16+
NEXT_PUBLIC_RPC_ARBITRUM=
17+
NEXT_PUBLIC_RPC_ARBITRUM_TESTNET=
18+
1619

1720
# this is used to determine which database to fetch data from
1821
NEXT_PUBLIC_VERCEL_ENV=development

.github/workflows/e2e.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ jobs:
1818
- test: wallet.spec
1919
runs-on: ubuntu-latest
2020
env:
21-
INFURA_KEY: ${{ secrets.INFURA_KEY }}
2221
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
23-
ALCHEMY_KEY: ${{ secrets.ALCHEMY_KEY }}
2422
REDIS_URL: ${{ secrets.REDIS_URL }}
2523
USE_CACHE: true
2624
TENDERLY_API_KEY: ${{ secrets.TENDERLY_API_KEY }}

README.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ The portal seeks to rely on on-chain data as much as possible and to minimize re
6161

6262
#### Network providers
6363

64-
The portal uses the [Wagmi](https://wagmi.sh/react/getting-started) library in order to communicate with the Ethereum network through its React hooks, and [Viem](https://viem.sh/docs/getting-started) in order to do so through its public client as well as provide Web3 utilities. Both Wagmi and Viem work by connecting to JSON-RPC APIs via HTTP in order to provide on-chain data to web applications. By default, they provide default RPC URLs that can be used to get started. However, these RPCs keys can quickly become rate-limited when too many requests are made. In order to prevent this, it is recommended that you sign up and add your own API keys to the configuration for [Alchemy](https://docs.alchemy.com/reference/ethereum-api-quickstart) and [Infura](https://docs.infura.io/infura/networks/ethereum/how-to/secure-a-project/project-id).
64+
The portal uses the [Wagmi](https://wagmi.sh/react/getting-started) library in order to communicate with the Ethereum network through its React hooks, and [Viem](https://viem.sh/docs/getting-started) in order to do so through its public client as well as provide Web3 utilities. Both Wagmi and Viem work by connecting to JSON-RPC APIs via HTTP in order to provide on-chain data to web applications. By default, they provide default RPC URLs that can be used to get started. However, these RPCs keys can quickly become rate-limited when too many requests are made. In order to prevent this, it is recommended that you sign up and add your own API keys to the configuration.
6565

6666
Due to the large volume of data that is constantly being fetched and displayed in the portal, we use caching in order to cache various network responses for a limited amount of time. This helps to reduce the load of networking calls to various APIs. This feature can be configured to be on or off.
6767

@@ -73,9 +73,9 @@ The following configuration values can be added to the `.env` file:
7373

7474
#### Recommended for improved performance:
7575

76-
- Set `INFURA_KEY` to a valid [Infura](https://docs.infura.io/infura/networks/ethereum/how-to/secure-a-project/project-id) API key for Wagmi and Viem to use
77-
78-
- Set `ALCHEMY_KEY` to a valid [Alchemy](https://docs.alchemy.com/reference/ethereum-api-quickstart) API key for Wagmi and Viem to use
76+
- Set `NEXT_PUBLIC_RPC_MAINNET` to a valid Ethereum mainnet RPC URL (e.g. from Alchemy, Infura, Tenderly, etc)
77+
- Set `NEXT_PUBLIC_RPC_ARBITRUM` to a valid Arbitrum mainnet RPC URL
78+
- Set `NEXT_PUBLIC_RPC_ARBITRUM_TESTNET` to a valid Arbitrum testnet RPC URL
7979

8080
- Set `ETHERSCAN_V2_API_KEY` to a valid [Etherscan V2](https://docs.etherscan.io/etherscan-v2#why-v2) API key for Wagmi to be able to generate the contract ABIs
8181

@@ -95,8 +95,6 @@ The following configuration values can be added to the `.env` file:
9595

9696
**Optional** Set `DEFENDER_API_KEY_MAINNET` and/or `DEFENDER_API_KEY_TESTNET` to a valid OpenZeppelin Defender Relay key (used for gasless poll voting)
9797
**Optional** Set `DEFENDER_API_SECRET_MAINNET` and/or`DEFENDER_API_SECRET_TESTNET` to a valid OpenZeppelin Defender Relay secret
98-
**Optional** Set `ALCHEMY_ARBITRUM_KEY` to a valid Alchemy API key for the arbitrum network
99-
**Optional** Set `ALCHEMY_ARBITRUM_TESTNET_KEY` to a valid Alchemy API key for the arbitrum test network
10098
**Optional** Set `GASLESS_BACKDOOR_SECRET` to allow for bypassing the gasless voting eligibility checks by anyone with the password
10199

102100
- Set `DASHBOARD_PASSWORD` for adding protection to the `/dashboard` route

lib/config.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ SPDX-License-Identifier: AGPL-3.0-or-later
88

99
type SystemConfig = {
1010
USE_CACHE: string;
11-
ALCHEMY_KEY: string;
12-
INFURA_KEY: string;
1311
TRACING_RPC_NODE: string;
1412
NODE_ENV: 'development' | 'production' | 'test';
13+
RPC_MAINNET: string;
14+
RPC_ARBITRUM: string;
15+
RPC_ARBITRUM_TESTNET: string;
1516
GITHUB_TOKEN: string;
1617
GITHUB_TOKEN_2: string;
1718
GITHUB_TOKEN_3: string;
@@ -20,8 +21,6 @@ type SystemConfig = {
2021
DEFENDER_API_SECRET_TESTNET: string;
2122
DEFENDER_API_KEY_MAINNET: string;
2223
DEFENDER_API_SECRET_MAINNET: string;
23-
ALCHEMY_ARBITRUM_KEY: string;
24-
ALCHEMY_ARBITRUM_TESTNET_KEY: string;
2524
WALLETCONNECT_PROJECT_ID: string;
2625
MIGRATION_WEBHOOK_URL: string;
2726
GASLESS_WEBHOOK_URL: string;
@@ -36,10 +35,11 @@ type SystemConfig = {
3635

3736
export const config: SystemConfig = {
3837
USE_CACHE: process.env.USE_CACHE || '',
39-
ALCHEMY_KEY: process.env.ALCHEMY_KEY || '',
40-
INFURA_KEY: process.env.INFURA_KEY || '',
4138
TRACING_RPC_NODE: process.env.TRACING_RPC_NODE || '',
4239
NODE_ENV: process.env.NODE_ENV || 'development',
40+
RPC_MAINNET: process.env.NEXT_PUBLIC_RPC_MAINNET || '',
41+
RPC_ARBITRUM: process.env.NEXT_PUBLIC_RPC_ARBITRUM || '',
42+
RPC_ARBITRUM_TESTNET: process.env.NEXT_PUBLIC_RPC_ARBITRUM_TESTNET || '',
4343
GITHUB_TOKEN: process.env.GITHUB_TOKEN || '',
4444
GITHUB_TOKEN_2: process.env.GITHUB_TOKEN_2 || '',
4545
GITHUB_TOKEN_3: process.env.GITHUB_TOKEN_3 || '',
@@ -48,8 +48,6 @@ export const config: SystemConfig = {
4848
DEFENDER_API_SECRET_TESTNET: process.env.DEFENDER_API_SECRET_TESTNET || '',
4949
DEFENDER_API_KEY_MAINNET: process.env.DEFENDER_API_KEY_MAINNET || '',
5050
DEFENDER_API_SECRET_MAINNET: process.env.DEFENDER_API_SECRET_MAINNET || '',
51-
ALCHEMY_ARBITRUM_KEY: process.env.NEXT_PUBLIC_ALCHEMY_ARBITRUM_KEY || '',
52-
ALCHEMY_ARBITRUM_TESTNET_KEY: process.env.NEXT_PUBLIC_ALCHEMY_ARBITRUM_TESTNET_KEY || '',
5351
WALLETCONNECT_PROJECT_ID: process.env.NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID || '',
5452
MIGRATION_WEBHOOK_URL: process.env.MIGRATION_WEBHOOK_URL || '',
5553
GASLESS_WEBHOOK_URL: process.env.GASLESS_WEBHOOK_URL || '',

modules/wagmi/config/config.default.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ import { SupportedChainId } from 'modules/web3/constants/chainID';
44
import { coinbaseWallet, metaMask, safe, walletConnect, injected } from 'wagmi/connectors';
55
import { createPublicClient } from 'viem';
66

7-
const tenderlyRpcUrl = `https://virtual.mainnet.rpc.tenderly.co/${process.env.NEXT_PUBLIC_TENDERLY_RPC_KEY}`;
7+
const RPC_TENDERLY = `https://virtual.mainnet.rpc.tenderly.co/${process.env.NEXT_PUBLIC_TENDERLY_RPC_KEY}`;
8+
const RPC_MAINNET = process.env.NEXT_PUBLIC_RPC_MAINNET || '';
9+
const RPC_ARBITRUM = process.env.NEXT_PUBLIC_RPC_ARBITRUM || '';
10+
const RPC_ARBITRUM_TESTNET = process.env.NEXT_PUBLIC_RPC_ARBITRUM_TESTNET || '';
811

912
export const tenderly = {
1013
id: SupportedChainId.TENDERLY as const,
@@ -17,8 +20,8 @@ export const tenderly = {
1720
symbol: 'ETH'
1821
},
1922
rpcUrls: {
20-
public: { http: [tenderlyRpcUrl] },
21-
default: { http: [tenderlyRpcUrl] }
23+
public: { http: [RPC_TENDERLY] },
24+
default: { http: [RPC_TENDERLY] }
2225
},
2326
blockExplorers: {
2427
default: { name: '', url: '' }
@@ -32,14 +35,10 @@ const httpBatchTransport = (url: string) =>
3235
});
3336

3437
const transports = {
35-
[mainnet.id]: httpBatchTransport(`https://eth-mainnet.g.alchemy.com/v2/${process.env.ALCHEMY_KEY}`),
36-
[tenderly.id]: httpBatchTransport(tenderlyRpcUrl),
37-
[arbitrum.id]: httpBatchTransport(
38-
`https://arb-mainnet.g.alchemy.com/v2/${process.env.NEXT_PUBLIC_ALCHEMY_ARBITRUM_KEY}`
39-
),
40-
[arbitrumSepolia.id]: httpBatchTransport(
41-
`https://arb-sepolia.g.alchemy.com/v2/${process.env.NEXT_PUBLIC_ALCHEMY_ARBITRUM_TESTNET_KEY}`
42-
)
38+
[mainnet.id]: httpBatchTransport(RPC_MAINNET),
39+
[tenderly.id]: httpBatchTransport(RPC_TENDERLY),
40+
[arbitrum.id]: httpBatchTransport(RPC_ARBITRUM),
41+
[arbitrumSepolia.id]: httpBatchTransport(RPC_ARBITRUM_TESTNET)
4342
};
4443

4544
const connectors = [

modules/web3/constants/networks.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,15 @@ export const CHAIN_INFO: ChainInfo = {
5959
label: 'Mainnet',
6060
type: 'normal',
6161
network: SupportedNetworks.MAINNET,
62-
defaultRpc: NodeProviders.ALCHEMY,
62+
defaultRpc: NodeProviders.TENDERLY,
6363
spockUrl:
6464
process.env.NEXT_PUBLIC_VERCEL_ENV === 'development' ? STAGING_MAINNET_SPOCK_URL : MAINNET_SPOCK_URL,
6565
subgraphUrl:
6666
process.env.NEXT_PUBLIC_VERCEL_ENV === 'development'
6767
? MAINNET_STAGING_SUBGRAPH_URL
6868
: MAINNET_PROD_SUBGRAPH_URL,
6969
rpcs: {
70-
[NodeProviders.INFURA]: `https://mainnet.infura.io/v3/${config.INFURA_KEY}`,
71-
[NodeProviders.ALCHEMY]: `https://eth-mainnet.g.alchemy.com/v2/${config.ALCHEMY_KEY}`
70+
[NodeProviders.TENDERLY]: process.env.NEXT_PUBLIC_RPC_MAINNET || ''
7271
},
7372
showInProduction: true
7473
},
@@ -79,9 +78,9 @@ export const CHAIN_INFO: ChainInfo = {
7978
label: 'ArbitrumTestnet',
8079
type: 'gasless',
8180
network: SupportedNetworks.ARBITRUMTESTNET,
82-
defaultRpc: NodeProviders.ALCHEMY,
81+
defaultRpc: NodeProviders.TENDERLY,
8382
rpcs: {
84-
[NodeProviders.ALCHEMY]: `https://arb-sepolia.g.alchemy.com/v2/${config.ALCHEMY_ARBITRUM_TESTNET_KEY}`
83+
[NodeProviders.TENDERLY]: process.env.NEXT_PUBLIC_RPC_ARBITRUM_TESTNET || ''
8584
},
8685
showInProduction: false
8786
},
@@ -92,9 +91,9 @@ export const CHAIN_INFO: ChainInfo = {
9291
label: 'Arbitrum',
9392
type: 'gasless',
9493
network: SupportedNetworks.ARBITRUM,
95-
defaultRpc: NodeProviders.ALCHEMY,
94+
defaultRpc: NodeProviders.TENDERLY,
9695
rpcs: {
97-
[NodeProviders.ALCHEMY]: `https://arb-mainnet.g.alchemy.com/v2/${config.ALCHEMY_ARBITRUM_KEY}`
96+
[NodeProviders.TENDERLY]: process.env.NEXT_PUBLIC_RPC_ARBITRUM || ''
9897
},
9998
showInProduction: false
10099
},

next.config.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ const moduleExports = {
5151
// everything in here gets exposed to the frontend.
5252
// prefer NEXT_PUBLIC_* instead, which makes this behavior more explicit
5353
env: {
54-
INFURA_KEY: process.env.INFURA_KEY || '84842078b09946638c03157f83405213', // ethers default infura key
55-
ALCHEMY_KEY: process.env.ALCHEMY_KEY || '_gg7wSSi0KMBsdKnGVfHDueq6xMB9EkC', // ethers default alchemy key
5654
GITHUB_TOKEN: process.env.GITHUB_TOKEN,
5755
READ_ONLY: process.env.READ_ONLY
5856
},

pages/api/generate-test-signature.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,7 @@ export default withApiHandler(async (req: NextApiRequest, res: NextApiResponse)
3838
chain,
3939
transport: isTestnet
4040
? http(`https://virtual.mainnet.rpc.tenderly.co/${process.env.NEXT_PUBLIC_TENDERLY_RPC_KEY}`)
41-
: fallback([
42-
http(`https://mainnet.infura.io/v3/${process.env.INFURA_KEY}`),
43-
http(`https://eth-mainnet.g.alchemy.com/v2/${process.env.ALCHEMY_KEY}`)
44-
])
41+
: fallback([http(process.env.NEXT_PUBLIC_RPC_MAINNET || '')])
4542
});
4643

4744
const voter = account.address;

0 commit comments

Comments
 (0)