Skip to content

Commit b4613f7

Browse files
Add backend constructor option for routing requests (#48)
* Add backend constructor option for routing requests * Prettier fix
1 parent e48c089 commit b4613f7

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/Substrate.ts

+17-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ type Configuration = {
2323
* Request timeout in milliseconds. Default: 5m
2424
*/
2525
timeout?: number;
26+
27+
/**
28+
* Switches between existing backend and newer backend
29+
*/
30+
backend?: "v0" | "v1";
2631
};
2732

2833
/**
@@ -33,11 +38,18 @@ export class Substrate {
3338
baseUrl: string;
3439
apiVersion: string;
3540
timeout: number;
41+
backend: string;
3642

3743
/**
3844
* Initialize the Substrate SDK.
3945
*/
40-
constructor({ apiKey, baseUrl, apiVersion, timeout }: Configuration) {
46+
constructor({
47+
apiKey,
48+
baseUrl,
49+
apiVersion,
50+
timeout,
51+
backend,
52+
}: Configuration) {
4153
if (!apiKey) {
4254
throw new SubstrateError(
4355
"An API Key is required. Specify it when constructing the Substrate client: `new Substrate({ apiKey: 'API_KEY' })`",
@@ -47,6 +59,7 @@ export class Substrate {
4759
this.baseUrl = baseUrl ?? "https://api.substrate.run";
4860
this.apiVersion = apiVersion ?? OpenAPIjson["info"]["version"];
4961
this.timeout = timeout ?? 300000;
62+
this.backend = backend ?? "v0";
5063
}
5164

5265
/**
@@ -136,6 +149,9 @@ export class Substrate {
136149
headers.append("X-Substrate-Runtime", props.runtime);
137150
headers.append("X-Substrate-Runtime-Version", props.runtimeVersion);
138151

152+
// Switch between old and new backends
153+
headers.append("X-Substrate-Backend", this.backend);
154+
139155
return headers;
140156
}
141157
}

0 commit comments

Comments
 (0)