Skip to content

Commit

Permalink
Merge pull request #371 from hyperlane-xyz/trevor/better-inj-fix
Browse files Browse the repository at this point in the history
fix: use browser env vars for Solana and Injective RPC URLs
  • Loading branch information
tkporter authored Jan 7, 2025
2 parents 16681db + 1b7814c commit 0053f12
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions src/consts/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ import {
import { ChainMap, ChainMetadata, ExplorerFamily } from '@hyperlane-xyz/sdk';
import { ProtocolType } from '@hyperlane-xyz/utils';

function getOverrideRpcUrls(chainName: string): { http: string }[] {
const envVar = process.env[`NEXT_PUBLIC_${chainName.toUpperCase()}_RPC_URL`];
return envVar ? [{ http: envVar }] : [];
}

// A map of chain names to ChainMetadata
// Chains can be defined here, in chains.json, or in chains.yaml
// Chains already in the SDK need not be included here unless you want to override some fields
Expand All @@ -23,20 +18,19 @@ export const chains: ChainMap<ChainMetadata & { mailbox?: Address }> = {
// SVM chains require mailbox addresses for the token adapters
mailbox: solanamainnetAddresses.mailbox,
// Including a convenient rpc override because the Solana public RPC does not allow browser requests from localhost
rpcUrls: [
// For backward compatibility
...getOverrideRpcUrls('solana'),
...getOverrideRpcUrls('solanamainnet'),
...solanamainnet.rpcUrls,
],
rpcUrls: process.env.NEXT_PUBLIC_SOLANA_RPC_URL
? [{ http: process.env.NEXT_PUBLIC_SOLANA_RPC_URL }, ...solanamainnet.rpcUrls]
: solanamainnet.rpcUrls,
},
eclipsemainnet: {
...eclipsemainnet,
mailbox: eclipsemainnetAddresses.mailbox,
},
injective: {
...injective,
rpcUrls: [...getOverrideRpcUrls('injective'), ...injective.rpcUrls],
rpcUrls: process.env.NEXT_PUBLIC_INJECTIVE_RPC_URL
? [{ http: process.env.NEXT_PUBLIC_INJECTIVE_RPC_URL }, ...injective.rpcUrls]
: injective.rpcUrls,
},
// mycustomchain: {
// protocol: ProtocolType.Ethereum,
Expand Down

0 comments on commit 0053f12

Please sign in to comment.