Skip to content

Commit

Permalink
simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
holic committed Jul 31, 2023
1 parent 960300d commit 363c885
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 24 deletions.
22 changes: 2 additions & 20 deletions templates/vanilla/packages/client/src/mud/getNetworkConfig.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
import { SetupContractConfig, getBurnerWallet } from "@latticexyz/std-client";
import { getBurnerWallet } from "@latticexyz/std-client";
import worldsJson from "contracts/worlds.json";
import { supportedChains } from "./supportedChains";
import type { Chain } from "viem/chains";

const worlds = worldsJson as Partial<Record<string, { address: string; blockNumber?: number }>>;

type NetworkConfig = SetupContractConfig & {
privateKey: string;
faucetServiceUrl?: string;
chain: Chain;
};

export async function getNetworkConfig(): Promise<NetworkConfig> {
export async function getNetworkConfig() {
const params = new URLSearchParams(window.location.search);
const chainId = Number(params.get("chainId") || params.get("chainid") || import.meta.env.VITE_CHAIN_ID || 31337);
const chainIndex = supportedChains.findIndex((c) => c.id === chainId);
Expand All @@ -31,22 +24,11 @@ export async function getNetworkConfig(): Promise<NetworkConfig> {
: world?.blockNumber ?? -1; // -1 will attempt to find the block number from RPC

return {
clock: {
period: 1000,
initialTime: 0,
syncInterval: 5000,
},
provider: {
chainId,
jsonRpcUrl: params.get("rpc") ?? chain.rpcUrls.default.http[0],
wsRpcUrl: params.get("wsRpc") ?? chain.rpcUrls.default.webSocket?.[0],
},
privateKey: getBurnerWallet().value,
chainId,
chain,
faucetServiceUrl: params.get("faucet") ?? chain.faucetUrl,
worldAddress,
initialBlockNumber,
disableCache: params.get("cache") === "false",
};
}
8 changes: 4 additions & 4 deletions templates/vanilla/packages/client/src/mud/setupNetwork.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { getBurnerWallet } from "@latticexyz/std-client";
import { createPublicClient, fallback, webSocket, http, createWalletClient, getContract, Hex, parseEther } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { createFaucetService } from "@latticexyz/network";
import { encodeEntity, syncToRecs } from "@latticexyz/store-sync/recs";
import { getNetworkConfig } from "./getNetworkConfig";
import { defineContractComponents } from "./contractComponents";
import { world } from "./world";
import { IWorld__factory } from "contracts/types/ethers-contracts/factories/IWorld__factory";
import storeConfig from "contracts/mud.config";
import { createPublicClient, fallback, webSocket, http, createWalletClient, getContract, Hex, parseEther } from "viem";
import { privateKeyToAccount } from "viem/accounts";

export type SetupNetworkResult = Awaited<ReturnType<typeof setupNetwork>>;

Expand All @@ -27,9 +26,10 @@ export async function setupNetwork() {
address: networkConfig.worldAddress as Hex,
publicClient,
components: contractComponents,
startBlock: BigInt(networkConfig.initialBlockNumber),
});

const burnerAccount = privateKeyToAccount(getBurnerWallet().value);
const burnerAccount = privateKeyToAccount(networkConfig.privateKey as Hex);
const burnerWalletClient = createWalletClient({
account: burnerAccount,
chain: networkConfig.chain,
Expand Down

0 comments on commit 363c885

Please sign in to comment.