Skip to content

Commit ae8cf8e

Browse files
committed
fix(RpcChannel): allow client to provide specVersion
this saves an extra call on RPC for optionally-known information (like the `chainId` case). also fixed speck -> spec typo
1 parent d56be0c commit ae8cf8e

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/channel/rpc_0_6.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ export class RpcChannel {
4848

4949
private chainId?: StarknetChainId;
5050

51-
private speckVersion?: string;
51+
private specVersion?: string;
5252

5353
readonly waitMode: Boolean; // behave like web2 rpc and return when tx is processed
5454

5555
constructor(optionsOrProvider?: RpcProviderOptions) {
56-
const { nodeUrl, retries, headers, blockIdentifier, chainId, waitMode } =
56+
const { nodeUrl, retries, headers, blockIdentifier, chainId, specVersion, waitMode } =
5757
optionsOrProvider || {};
5858
if (Object.values(NetworkName).includes(nodeUrl as NetworkName)) {
5959
this.nodeUrl = getDefaultNodeUrl(nodeUrl as NetworkName, optionsOrProvider?.default);
@@ -66,6 +66,7 @@ export class RpcChannel {
6666
this.headers = { ...defaultOptions.headers, ...headers };
6767
this.blockIdentifier = blockIdentifier || defaultOptions.blockIdentifier;
6868
this.chainId = chainId;
69+
this.specVersion = specVersion;
6970
this.waitMode = waitMode || false;
7071
this.requestId = 0;
7172
}
@@ -121,8 +122,8 @@ export class RpcChannel {
121122
}
122123

123124
public async getSpecVersion() {
124-
this.speckVersion ??= (await this.fetchEndpoint('starknet_specVersion')) as StarknetChainId;
125-
return this.speckVersion;
125+
this.specVersion ??= (await this.fetchEndpoint('starknet_specVersion')) as StarknetChainId;
126+
return this.specVersion;
126127
}
127128

128129
public getNonceForAddress(

src/types/provider/configuration.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export type RpcProviderOptions = {
99
headers?: object;
1010
blockIdentifier?: BlockIdentifier;
1111
chainId?: StarknetChainId;
12+
specVersion?: string;
1213
default?: boolean;
1314
waitMode?: boolean;
1415
};

0 commit comments

Comments
 (0)