Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding private RPC on transport for all supported chains #4863

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/lib/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,25 @@ export const getChainName = (chainId?: number, chainType?: ChainType) => {
]?.name || unknown
);
};

// Network mapping for DRPC
export const getDrpcNetwork = (chainId: number): string | null => {
const networkMap: { [key: number]: string } = {
1: 'ethereum',
137: 'polygon',
10: 'optimism',
42161: 'arbitrum',
8453: 'base',
42220: 'celo',
100: 'gnosis',
1101: 'polygon-zkevm',
11155111: 'sepolia',
11155420: 'optimism-sepolia',
421614: 'arbitrum-sepolia',
84532: 'base-sepolia',
44787: 'celo-alfajores',
1442: 'polygon-zkevm-cardona',
};

return networkMap[chainId] || null;
};
Comment on lines +24 to +43
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Based on the search results, I can now generate the final response:

DRPC key implementation needs error handling improvements

The current implementation in wagmiConfigs.ts uses DRPC key from environment variables but lacks:

  • Error handling for invalid or missing DRPC keys
  • Rate limit handling mechanisms
  • Fallback strategy when DRPC requests fail

Specific locations that need attention:

  • src/wagmiConfigs.ts: The transport configuration simply falls back to default HTTP transport without any error handling when DRPC key is missing
  • Consider adding validation similar to the projectId check that's already implemented (if (!projectId) throw new Error('Project ID is not defined'))
🔗 Analysis chain

Verify DRPC key handling

The PR objectives mention a rate-limited key requirement for production. While this function handles network mapping, ensure that:

  1. The DRPC key is properly validated in the transport configuration
  2. Rate limiting is properly implemented
  3. Error handling exists for cases when the key is invalid or rate limit is exceeded

Let's check how the DRPC key is handled:


Let me gather more context about the transport configuration and error handling:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check DRPC key usage and validation
# Look for DRPC key handling in the codebase
rg -g '!node_modules' -g '*.ts' -g '*.js' -A 5 'drpcKey|DRPC_KEY'

Length of output: 458


Script:

#!/bin/bash
# Check the complete transport configuration and error handling
rg -g '*.ts' -g '*.js' -A 10 'createConfig|http\(' 

# Look for any error handling related to RPC
rg -g '*.ts' -g '*.js' -A 5 'RpcError|rpcError|transport.*error'

Length of output: 3142

14 changes: 13 additions & 1 deletion src/wagmiConfigs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { cookieStorage, createConfig, createStorage } from 'wagmi';
import { walletConnect, coinbaseWallet, safe } from '@wagmi/connectors';

import { createClient, http } from 'viem';
import { getDrpcNetwork } from './lib/network';
import configuration from './configuration';

// Get projectId at https://cloud.walletconnect.com
Expand All @@ -19,6 +20,14 @@ const metadata = {

const chains = configuration.EVM_CHAINS;

const createDrpcTransport = (chainId: number) => {
const network = getDrpcNetwork(chainId);
const drpcKey = process.env.NEXT_PUBLIC_DRPC_KEY;
return network && drpcKey
? http(`https://lb.drpc.org/ogrpc?network=${network}&dkey=${drpcKey}`)
: http();
};

// Create wagmiConfig
export const wagmiConfig = createConfig({
chains: chains, // required
Expand All @@ -37,6 +46,9 @@ export const wagmiConfig = createConfig({
storage: cookieStorage,
}),
client({ chain }) {
return createClient({ chain, transport: http() });
return createClient({
chain,
transport: createDrpcTransport(chain.id),
});
},
});
Loading