import { http, type PublicClient, createPublicClient, defineChain } from "viem" import * as allChains from "viem/chains" export const CustomChains = [ defineChain({ id: 720380884, name: "MagicNewton", network: "magic-newton", nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 }, rpcUrls: { default: { http: ["https://newton-sepolia-rpc.eu-north-2.gateway.fm"] } }, blockExplorers: { default: { name: "MagicNewton", url: "https://explorer.testnet.magicnewton.com/" } }, testnet: true }) ] export const getChain = (chainId: number) => { const chain = [...Object.values(allChains), ...CustomChains].find( (chain) => chain.id === chainId ) if (!chain) { throw new Error(`Chain with id ${chainId} not found`) } return chain } export const getPublicClient = (chainId: number): PublicClient => { const chain = getChain(chainId) return createPublicClient({ chain: chain, transport: http() }) as PublicClient }