Files
solace-bg-dubai/frontend/lib/web3/config.ts
defiQUG a03417be98
All checks were successful
CI / lint-and-test (push) Successful in 9m52s
chore: consolidate local WIP (repo cleanup 20260707)
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-07 09:41:38 -07:00

83 lines
2.0 KiB
TypeScript

import { createConfig, http, webSocket, type Config } from "wagmi";
import { mainnet, sepolia } from "wagmi/chains";
import { defineChain } from "viem";
import { walletConnect, injected, metaMask } from "wagmi/connectors";
import {
getWalletConnectProjectId,
isValidWalletConnectProjectId,
} from "./walletconnect";
import { CHAIN138_PUBLIC } from "./chain138-public";
function buildConnectors() {
const projectId = getWalletConnectProjectId();
if (isValidWalletConnectProjectId(projectId)) {
return [injected(), metaMask(), walletConnect({ projectId })];
}
return [injected(), metaMask()];
}
const chain138HttpRpc =
process.env.NEXT_PUBLIC_CHAIN138_RPC_URL?.trim() || CHAIN138_PUBLIC.httpRpc;
const chain138WsRpc = process.env.NEXT_PUBLIC_CHAIN138_WS_URL?.trim() || "";
const chain138Explorer =
process.env.NEXT_PUBLIC_CHAIN138_EXPLORER_URL?.trim() ||
CHAIN138_PUBLIC.explorer;
function chain138Transport() {
if (chain138WsRpc.startsWith("wss://")) {
return webSocket(chain138WsRpc);
}
return http(chain138HttpRpc);
}
const chain138 = defineChain({
id: 138,
name: "Solace Chain 138",
nativeCurrency: {
decimals: 18,
name: "Ether",
symbol: "ETH",
},
rpcUrls: {
default: {
http: [chain138HttpRpc],
...(chain138WsRpc.startsWith("wss://")
? { webSocket: [chain138WsRpc] }
: {}),
},
},
blockExplorers: {
default: {
name: "Chain 138 Explorer",
url: chain138Explorer,
},
},
testnet: false,
});
let wagmiConfig: Config | undefined;
export function getConfig(): Config {
if (!wagmiConfig) {
wagmiConfig = createConfig({
chains: [chain138, mainnet, sepolia],
connectors: buildConnectors(),
transports: {
[chain138.id]: chain138Transport(),
[mainnet.id]: http(),
[sepolia.id]: http(process.env.NEXT_PUBLIC_SEPOLIA_RPC_URL),
},
ssr: false,
});
}
return wagmiConfig;
}
declare module "wagmi" {
interface Register {
config: ReturnType<typeof getConfig>;
}
}