Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export type NetworkConfigFormData = {
type: "testnet" | "mainnet";
icon: string;
slug: string;
stackType?: string;
};

// lowercase it, replace all spaces with hyphens, and then strip all non-alphanumeric characters
Expand Down Expand Up @@ -71,6 +72,7 @@ export const ConfigureNetworkForm: React.FC<NetworkConfigFormProps> = ({
type: editingChain?.testnet ? "testnet" : "mainnet",
icon: editingChain?.icon?.url || "",
slug: prefillSlug || editingChain?.slug || "",
stackType: "",
},
mode: "onChange",
});
Expand Down Expand Up @@ -146,6 +148,7 @@ export const ConfigureNetworkForm: React.FC<NetworkConfigFormProps> = ({
format: "",
},
testnet: data.type === "testnet",
stackType: data.stackType || "",
};
} else {
configuredNetwork = {
Expand All @@ -170,6 +173,7 @@ export const ConfigureNetworkForm: React.FC<NetworkConfigFormProps> = ({
format: "",
}
: undefined,
stackType: data.stackType || "",
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ export const EmbedSetup: React.FC<EmbedSetupProps> = ({
shortName: "unknown",
slug: "unknown",
testnet: false,
stackType: "",
};

const { register, watch } = useForm<{
Expand Down
1 change: 1 addition & 0 deletions packages/thirdweb/src/chains/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export type ChainMetadata = {
type: string;
bridges?: Readonly<Array<{ url: string }>>;
};
stackType: string;
};

/**
Expand Down
1 change: 1 addition & 0 deletions packages/thirdweb/src/chains/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,5 +365,6 @@ function createChainMetadata(
url: e.url,
standard: "EIP3091",
})) || data?.explorers,
stackType: data?.stackType || "",
};
}
30 changes: 7 additions & 23 deletions packages/thirdweb/src/utils/any-evm/zksync/isZkSyncChain.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Chain } from "../../../chains/types.js";
import { withCache } from "../../promise/withCache.js";
import { getChainMetadata } from "../../../chains/utils.js";

export async function isZkSyncChain(chain: Chain) {
if (chain.id === 1337 || chain.id === 31337) {
Expand All @@ -12,36 +12,20 @@ export async function isZkSyncChain(chain: Chain) {
chain.id === 300 ||
chain.id === 302 ||
chain.id === 11124 ||
chain.id === 282 || // cronos zkevm testnet
chain.id === 388 // cronos zkevm mainnet
chain.id === 282 ||
chain.id === 388 ||
chain.id === 4654 ||
chain.id === 333271
) {
return true;
}

// fallback to checking the stack on rpc
try {
const stack = await getChainStack(chain.id);
return stack === "zksync-stack";
const chainMetadata = await getChainMetadata(chain);
return chainMetadata.stackType === "zksync_stack";
} catch {
// If the network check fails, assume it's not a ZkSync chain
return false;
}
}

async function getChainStack(chainId: number): Promise<string> {
return withCache(
async () => {
const res = await fetch(`https://${chainId}.rpc.thirdweb.com/stack`);

if (!res.ok) {
res.body?.cancel();
throw new Error(`Error fetching stack for ${chainId}`);
}

const data = await res.json();

return data.stack;
},
{ cacheKey: `stack:${chainId}`, cacheTime: 24 * 60 * 60 * 1000 },
);
}
Loading