Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix test & add async chain retrieval methods
  • Loading branch information
jnsdls committed Oct 25, 2023
commit 91efe54a451b2a9a7111e8e33406be7e79896f1d
3 changes: 2 additions & 1 deletion packages/chains/chains/1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ export default {
"https://mainnet.gateway.tenderly.co",
"wss://mainnet.gateway.tenderly.co",
"https://rpc.blocknative.com/boost",
"https://rpc.flashbots.net/fast"
"https://rpc.flashbots.net/fast",
"https://rpc.mevblocker.io/fullprivacy"
],
"shortName": "eth",
"slip44": 60,
Expand Down
6 changes: 3 additions & 3 deletions packages/chains/chains/3068.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ export default {
],
"faucets": [],
"icon": {
"url": "ipfs://QmcHvn2Wq91ULyEH5s3uHjosX285hUgyJHwggFJUd3L5uh",
"width": 128,
"height": 128,
"url": "ipfs://QmYxniqbiFD7nXBNjN8boUhoXYEAW23YquArD2Rnkq8WHS",
"width": 480,
"height": 480,
"format": "png"
},
"infoURL": "https://thebifrost.io",
Expand Down
29 changes: 29 additions & 0 deletions packages/chains/chains/3639.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import type { Chain } from "../src/types";
export default {
"chain": "iChain",
"chainId": 3639,
"explorers": [
{
"name": "iChainscan",
"url": "https://ichainscan.com",
"standard": "EIP3091"
}
],
"faucets": [],
"infoURL": "https://islamicoin.finance",
"name": "iChain Network",
"nativeCurrency": {
"name": "ISLAMICOIN",
"symbol": "ISLAMI",
"decimals": 18
},
"networkId": 3639,
"rpc": [
"https://ichain-network.rpc.thirdweb.com/${THIRDWEB_API_KEY}",
"https://3639.rpc.thirdweb.com/${THIRDWEB_API_KEY}",
"https://rpc.ichainscan.com"
],
"shortName": "ISLAMI",
"slug": "ichain-network",
"testnet": false
} as const satisfies Chain;
6 changes: 3 additions & 3 deletions packages/chains/chains/49088.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ export default {
],
"faucets": [],
"icon": {
"url": "ipfs://QmcHvn2Wq91ULyEH5s3uHjosX285hUgyJHwggFJUd3L5uh",
"width": 128,
"height": 128,
"url": "ipfs://QmYxniqbiFD7nXBNjN8boUhoXYEAW23YquArD2Rnkq8WHS",
"width": 480,
"height": 480,
"format": "png"
},
"infoURL": "https://thebifrost.io",
Expand Down
33 changes: 33 additions & 0 deletions packages/chains/chains/68840142.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import type { Chain } from "../src/types";
export default {
"chain": "ETH",
"chainId": 68840142,
"explorers": [
{
"name": "Frame Testnet Explorer",
"url": "https://explorer.testnet.frame.xyz/",
"standard": "EIP3091"
}
],
"faucets": [
"https://faucet.triangleplatform.com/frame"
],
"features": [],
"infoURL": "https://frame.xyz",
"name": "Frame Testnet",
"nativeCurrency": {
"name": "Ether",
"symbol": "ETH",
"decimals": 18
},
"networkId": 68840142,
"redFlags": [],
"rpc": [
"https://frame-testnet.rpc.thirdweb.com/${THIRDWEB_API_KEY}",
"https://68840142.rpc.thirdweb.com/${THIRDWEB_API_KEY}",
"https://rpc.testnet.frame.xyz"
],
"shortName": "frame-test",
"slug": "frame-testnet",
"testnet": true
} as const satisfies Chain;
35 changes: 35 additions & 0 deletions packages/chains/chains/999999999.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import type { Chain } from "../src/types";
export default {
"chain": "ETH",
"chainId": 999999999,
"explorers": [
{
"name": "Zora Sepolia Testnet Network Explorer",
"url": "https://sepolia.explorer.zora.energy",
"standard": "EIP3091"
}
],
"faucets": [],
"icon": {
"url": "ipfs://bafkreifvrly5tgd34xqeo67s4etmiu52bkroml7uy7eosizf57htf5nrzq",
"width": 250,
"height": 250,
"format": "png"
},
"infoURL": "https://zora.energy",
"name": "Zora Sepolia Testnet",
"nativeCurrency": {
"name": "Sepolia Ether",
"symbol": "ETH",
"decimals": 18
},
"networkId": 999999999,
"rpc": [
"https://zora-sepolia-testnet.rpc.thirdweb.com/${THIRDWEB_API_KEY}",
"https://999999999.rpc.thirdweb.com/${THIRDWEB_API_KEY}",
"https://sepolia.rpc.zora.energy"
],
"shortName": "zsep",
"slug": "zora-sepolia-testnet",
"testnet": true
} as const satisfies Chain;
1 change: 1 addition & 0 deletions packages/chains/scripts/sync-db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ import type { Chain } from "./types";
${exports.join("\n")}
export * from "./types";
export * from "./utils";
export * from "./async";
export const defaultChains = [c1, c5, c8453, c84531, c137, c80001, c42161, c421613, c10, c420, c56, c97, c250, c4002, c43114, c43113, c1337];
// @ts-expect-error - TODO: fix this later
export const allChains: Chain[] = [${exportNames.join(", ")}];
Expand Down
61 changes: 61 additions & 0 deletions packages/chains/src/async.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import type { Chain } from "./types";

type FetchChainResponse = {
data: Chain;
error: unknown;
};

export async function fetchChain(chainIdOrSlug: number | string) {
const res = await fetch(
`https://api.thirdweb.com/v1/chains/${chainIdOrSlug}`,
);
if (!res.ok) {
console.debug("[chains] fetchChain() failed", res.status, res.statusText);
return null;
}
try {
const json = (await res.json()) as FetchChainResponse;
if (json.error) {
console.debug("[chains] fetchChain() error", json.error);
return null;
}
return json.data;
} catch (err) {
console.debug("[chains] fetchChain() failed", err);
return null;
}
}

type FetchChainsResponse = {
data: Chain[];
error: unknown;
};

export async function fetchChains(options?: {
limit?: number;
offset?: number;
}) {
const url = new URL(`https://api.thirdweb.com/v1/chains`);
if (options?.limit && options.limit >= 1) {
url.searchParams.append("limit", options.limit.toString());
}
if (options?.offset && options.offset >= 1) {
url.searchParams.append("offset", options.offset.toString());
}
const res = await fetch(url);
if (!res.ok) {
console.debug("[chains] fetchChain() failed", res.status, res.statusText);
return null;
}
try {
const json = (await res.json()) as FetchChainsResponse;
if (json.error) {
console.debug("[chains] fetchChain() error", json.error);
return null;
}
return json.data;
} catch (err) {
console.debug("[chains] fetchChain() failed", err);
return null;
}
}
15 changes: 14 additions & 1 deletion packages/chains/src/index.ts

Large diffs are not rendered by default.

Loading