Skip to content

Commit 1bf30d1

Browse files
committed
feat: add Avalanche Local chain support
🔺 Generated by DevRel swarm Add support for local Avalanche network (chain ID 43112) to enable local development and testing with avalanche-cli or similar local networks.
1 parent 8db0e36 commit 1bf30d1

File tree

5 files changed

+37
-3
lines changed

5 files changed

+37
-3
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { defineChain } from "viem";
2+
3+
export const avalancheLocal = /*#__PURE__*/ defineChain({
4+
id: 43_112,
5+
name: "Avalanche Local",
6+
nativeCurrency: {
7+
decimals: 18,
8+
name: "Avalanche",
9+
symbol: "AVAX",
10+
},
11+
rpcUrls: {
12+
default: { http: ["http://127.0.0.1:9650/ext/bc/C/rpc"] },
13+
},
14+
testnet: true,
15+
});

client/src/chains/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ export type {
174174
} from "viem/chains";
175175
export { avalanche } from "./avalanche.js";
176176
export { avalancheFuji } from "./avalancheFuji.js";
177+
export { avalancheLocal } from "./avalancheLocal.js";
177178
/** @deprecated Use `sonicTestnet` instead. */
178179
export {
179180
fantomSonicTestnet,

client/src/clients/createAvalancheClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ export function createAvalancheClient<
120120
});
121121
const extendedClient = client.extend(avalanchePublicActions) as any;
122122

123-
if (chainConfig?.id !== 43_113 && chainConfig?.id !== 43_114) {
123+
if (chainConfig?.id !== 43_112 && chainConfig?.id !== 43_113 && chainConfig?.id !== 43_114) {
124124
return {
125125
...extendedClient,
126126
};

client/src/clients/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ function getClientURL(
9494
clientType: ClientType = "public",
9595
transportType: "http" | "webSocket" = "http"
9696
): string | undefined {
97-
if (chain?.id !== 43_113 && chain?.id !== 43_114) {
97+
if (chain?.id !== 43_112 && chain?.id !== 43_113 && chain?.id !== 43_114) {
9898
return url ?? chain?.rpcUrls.default[transportType]?.[0];
9999
}
100100

client/src/methods/consts.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,32 @@
1+
// Chain IDs for easy reference
2+
export const AVALANCHE_CHAIN_IDS = {
3+
MAINNET: 43114,
4+
FUJI: 43113,
5+
LOCAL: 43112,
6+
} as const;
7+
8+
// Network IDs (different from chain IDs)
9+
export const AVALANCHE_NETWORK_IDS = {
10+
MAINNET: 1,
11+
FUJI: 5,
12+
LOCAL: 1337,
13+
} as const;
14+
115
export const P_CHAIN_MAINNET_ID = '11111111111111111111111111111111LpoYY';
216
export const P_CHAIN_FUJI_ID = '11111111111111111111111111111111LpoYY';
17+
export const P_CHAIN_LOCAL_ID = '11111111111111111111111111111111LpoYY';
318
export const P_CHAIN_ALIAS = 'P';
419

520
export const X_CHAIN_MAINNET_ID = '2oYMBNV4eNHyqk2fjjV5nVQLDbtmNJzq5s3qs3Lo6ftnC6FByM';
621
export const X_CHAIN_FUJI_ID = '2JVSBoinj9C2J33VntvzYtVJNZdN2NKiwwKjcumHUWEb5DbBrm';
22+
export const X_CHAIN_LOCAL_ID = '2eNy1mUFdmaxXNj1eQHUe7Np4gju9sJsEtWQ4MX3ToiNKuADed';
723
export const X_CHAIN_ALIAS = 'X';
824

925
export const C_CHAIN_MAINNET_ID = '2q9e4r6Mu3U68nU1fYjgbR6JvwrRx36CohpAX5UQxse55x1Q5';
1026
export const C_CHAIN_FUJI_ID = 'yH8D7ThNJkxmtkuv2jgBa4P1Rn3Qpr4pPr7QYNfcdoS6k6HWp';
27+
export const C_CHAIN_LOCAL_ID = '2CA6j5zYzasynPsFeNoqWkmTCt3VScMvXUZHbfDJ8k3oGzAPtU';
1128
export const C_CHAIN_ALIAS = 'C';
1229

1330
export const MAINNET_NETWORK_ID = 1;
14-
export const TESTNET_NETWORK_ID = 5;
31+
export const TESTNET_NETWORK_ID = 5;
32+
export const LOCAL_NETWORK_ID = 1337;

0 commit comments

Comments
 (0)