File tree Expand file tree Collapse file tree 7 files changed +50
-3
lines changed
Expand file tree Collapse file tree 7 files changed +50
-3
lines changed Original file line number Diff line number Diff line change 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+ } ) ;
Original file line number Diff line number Diff line change @@ -171,6 +171,7 @@ test("exports", () => {
171171 "fantom",
172172 "avalanche",
173173 "avalancheFuji",
174+ "avalancheLocal",
174175 "fantomSonicTestnet",
175176 "fantomTestnet",
176177 "fibo",
Original file line number Diff line number Diff line change @@ -174,6 +174,7 @@ export type {
174174} from "viem/chains" ;
175175export { avalanche } from "./avalanche.js" ;
176176export { avalancheFuji } from "./avalancheFuji.js" ;
177+ export { avalancheLocal } from "./avalancheLocal.js" ;
177178/** @deprecated Use `sonicTestnet` instead. */
178179export {
179180 fantomSonicTestnet ,
Original file line number Diff line number Diff line change 88 RpcSchema ,
99 Transport ,
1010} from "viem" ;
11+ import { AVALANCHE_CHAIN_IDS } from "../methods/consts.js" ;
1112import { AvalanchePublicRpcSchema } from "../methods/public/avalanchePublicRpcSchema.js" ;
1213import { createAdminApiClient } from "./createAdminApiClient.js" ;
1314import { createCChainClient } from "./createCChainClient.js" ;
@@ -23,6 +24,8 @@ import {
2324 AvalancheClientConfig ,
2425} from "./types/createAvalancheClient.js" ;
2526import { createAvalancheTransportClient } from "./utils.js" ;
27+
28+ const AVALANCHE_CHAIN_ID_VALUES = Object . values ( AVALANCHE_CHAIN_IDS ) as number [ ] ;
2629/**
2730 * Creates an Avalanche Client with a given transport configured for a Chain.
2831 *
@@ -120,7 +123,7 @@ export function createAvalancheClient<
120123 } ) ;
121124 const extendedClient = client . extend ( avalanchePublicActions ) as any ;
122125
123- if ( chainConfig ?. id !== 43_113 && chainConfig ? .id !== 43_114 ) {
126+ if ( ! chainConfig ?. id || ! AVALANCHE_CHAIN_ID_VALUES . includes ( chainConfig . id ) ) {
124127 return {
125128 ...extendedClient ,
126129 } ;
Original file line number Diff line number Diff line change 99} from "viem" ;
1010import { commonHeaders } from "./common.js" ;
1111import { AvalancheTransportConfig , ClientType } from "./types/types.js" ;
12+ import { AVALANCHE_CHAIN_IDS } from "../methods/consts.js" ;
13+
14+ const AVALANCHE_CHAIN_ID_VALUES = Object . values ( AVALANCHE_CHAIN_IDS ) as number [ ] ;
1215
1316export function createAvalancheTransportClient <
1417 transport extends Transport ,
@@ -94,7 +97,7 @@ function getClientURL(
9497 clientType : ClientType = "public" ,
9598 transportType : "http" | "webSocket" = "http"
9699) : string | undefined {
97- if ( chain ?. id !== 43_113 && chain ? .id !== 43_114 ) {
100+ if ( ! chain ?. id || ! AVALANCHE_CHAIN_ID_VALUES . includes ( chain . id ) ) {
98101 return url ?? chain ?. rpcUrls . default [ transportType ] ?. [ 0 ] ;
99102 }
100103
Original file line number Diff line number Diff line change 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+
115export const P_CHAIN_MAINNET_ID = '11111111111111111111111111111111LpoYY' ;
216export const P_CHAIN_FUJI_ID = '11111111111111111111111111111111LpoYY' ;
17+ export const P_CHAIN_LOCAL_ID = '11111111111111111111111111111111LpoYY' ;
318export const P_CHAIN_ALIAS = 'P' ;
419
520export const X_CHAIN_MAINNET_ID = '2oYMBNV4eNHyqk2fjjV5nVQLDbtmNJzq5s3qs3Lo6ftnC6FByM' ;
621export const X_CHAIN_FUJI_ID = '2JVSBoinj9C2J33VntvzYtVJNZdN2NKiwwKjcumHUWEb5DbBrm' ;
22+ export const X_CHAIN_LOCAL_ID = '2eNy1mUFdmaxXNj1eQHUe7Np4gju9sJsEtWQ4MX3ToiNKuADed' ;
723export const X_CHAIN_ALIAS = 'X' ;
824
925export const C_CHAIN_MAINNET_ID = '2q9e4r6Mu3U68nU1fYjgbR6JvwrRx36CohpAX5UQxse55x1Q5' ;
1026export const C_CHAIN_FUJI_ID = 'yH8D7ThNJkxmtkuv2jgBa4P1Rn3Qpr4pPr7QYNfcdoS6k6HWp' ;
27+ export const C_CHAIN_LOCAL_ID = '2CA6j5zYzasynPsFeNoqWkmTCt3VScMvXUZHbfDJ8k3oGzAPtU' ;
1128export const C_CHAIN_ALIAS = 'C' ;
1229
1330export 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 ;
Original file line number Diff line number Diff line change @@ -110,17 +110,23 @@ test("exports", () => {
110110 "watchEvent",
111111 "watchPendingTransactions",
112112 "writeContract",
113+ "AVALANCHE_CHAIN_IDS",
114+ "AVALANCHE_NETWORK_IDS",
113115 "P_CHAIN_MAINNET_ID",
114116 "P_CHAIN_FUJI_ID",
117+ "P_CHAIN_LOCAL_ID",
115118 "P_CHAIN_ALIAS",
116119 "X_CHAIN_MAINNET_ID",
117120 "X_CHAIN_FUJI_ID",
121+ "X_CHAIN_LOCAL_ID",
118122 "X_CHAIN_ALIAS",
119123 "C_CHAIN_MAINNET_ID",
120124 "C_CHAIN_FUJI_ID",
125+ "C_CHAIN_LOCAL_ID",
121126 "C_CHAIN_ALIAS",
122127 "MAINNET_NETWORK_ID",
123128 "TESTNET_NETWORK_ID",
129+ "LOCAL_NETWORK_ID",
124130 ]
125131 ` ) ;
126132} ) ;
You can’t perform that action at this time.
0 commit comments