Skip to content

Commit ec149f3

Browse files
authored
Read RPC on Viem chain adapter (#2946)
1 parent b64c8e7 commit ec149f3

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

.changeset/metal-toes-tickle.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"thirdweb": patch
3+
---
4+
5+
Read RPC url from viem chain in viem chain adapter
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { defineChain as viemChain } from "viem";
2+
import { describe, expect, it } from "vitest";
3+
import { defineChain } from "./utils.js";
4+
5+
describe("defineChain", () => {
6+
it("should convert viem chain to thirdweb chain", () => {
7+
const zoraViem = viemChain({
8+
id: 7777777,
9+
name: "Zora",
10+
nativeCurrency: {
11+
decimals: 18,
12+
name: "Ether",
13+
symbol: "ETH",
14+
},
15+
rpcUrls: {
16+
default: {
17+
http: ["https://rpc.zora.energy"],
18+
webSocket: ["wss://rpc.zora.energy"],
19+
},
20+
},
21+
blockExplorers: {
22+
default: { name: "Explorer", url: "https://explorer.zora.energy" },
23+
},
24+
});
25+
const thirdwebViem = defineChain(zoraViem);
26+
27+
expect(thirdwebViem.id).toEqual(zoraViem.id);
28+
expect(thirdwebViem.name).toEqual(zoraViem.name);
29+
expect(thirdwebViem.nativeCurrency).toEqual(zoraViem.nativeCurrency);
30+
expect(thirdwebViem.rpc).toEqual(zoraViem.rpcUrls.default.http[0]);
31+
});
32+
});

packages/thirdweb/src/chains/utils.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ function convertViemChain(viemChain: ViemChain): Chain {
9191
symbol: viemChain.nativeCurrency.symbol,
9292
decimals: viemChain.nativeCurrency.decimals,
9393
},
94+
rpc:
95+
viemChain.rpcUrls.default.http[0] ??
96+
`https://${viemChain.id}.rpc.thirdweb.com`,
9497
blockExplorers: viemChain?.blockExplorers
9598
? Object.values(viemChain?.blockExplorers).map((explorer) => {
9699
return {

0 commit comments

Comments
 (0)