Skip to content

Commit

Permalink
feat: enable anvil in localhost
Browse files Browse the repository at this point in the history
  • Loading branch information
zugdev committed Dec 18, 2024
1 parent 6478209 commit 4605da3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
4 changes: 4 additions & 0 deletions cypress/scripts/anvil.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

# start anvil
anvil --block-time 5 --chain-id 31337 --rpc-url https://rpc.ankr.com/eth
16 changes: 12 additions & 4 deletions static/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createAppKit } from "@reown/appkit";
import { AppKit, createAppKit } from "@reown/appkit";
import { Ethers5Adapter } from "@reown/appkit-adapter-ethers5";
import { gnosis, mainnet, polygon, optimism, arbitrum, base, bsc, blast, zksync, avalanche, worldchain } from "@reown/appkit/networks";
import { anvil, gnosis, mainnet, polygon, optimism, arbitrum, base, bsc, blast, zksync, avalanche, worldchain, AppKitNetwork } from "@reown/appkit/networks";
import { ethers } from "ethers";
import { renderErrorInModal } from "./display-popup-modal";
import { updateTokens } from "./populate-dropdown";
Expand Down Expand Up @@ -30,6 +30,7 @@ const metadata = {
const alchemyKey = ALCHEMY_KEY || "";

const providersUrl: { [key: string]: string } = {
31337: `http://localhost:8545`,
100: alchemyKey ? `https://gnosis-mainnet.g.alchemy.com/v2/${alchemyKey}` : "https://rpc.gnosischain.com",
1: alchemyKey ? `https://eth-mainnet.alchemyapi.io/v2/${alchemyKey}` : "https://eth.llamarpc.com",
137: alchemyKey ? `https://polygon-mainnet.g.alchemy.com/v2/${alchemyKey}` : "https://polygon.llamarpc.com",
Expand All @@ -43,9 +44,17 @@ const providersUrl: { [key: string]: string } = {
480: alchemyKey ? `https://worldchain-mainnet.g.alchemy.com/v2/${alchemyKey}` : "https://rpc.worldchain.network"
};

let networks: [AppKitNetwork, ...AppKitNetwork[]];
if (window.location.hostname === "localhost" || window.location.hostname === "0.0.0.0") {
console.log("enabling anvil");
networks = [anvil, gnosis, mainnet, polygon, optimism, arbitrum, base, bsc, blast, zksync, avalanche, worldchain];
} else {
networks = [gnosis, mainnet, polygon, optimism, arbitrum, base, bsc, blast, zksync, avalanche, worldchain];
}

export const appState = createAppKit({
adapters: [new Ethers5Adapter()],
networks: [gnosis, mainnet, polygon, optimism, arbitrum, base, bsc, blast, zksync, avalanche, worldchain],
networks,
defaultNetwork: gnosis,
metadata,
projectId,
Expand All @@ -61,7 +70,6 @@ function getNetwork(): string {
}

// create provider & signer for gnosis
const caipNetwork = appState.getCaipNetwork();
export let provider = new ethers.providers.JsonRpcProvider(providersUrl[getNetwork()]);
export let userSigner: ethers.Signer;

Expand Down

0 comments on commit 4605da3

Please sign in to comment.