Skip to content

Commit 0ec38e9

Browse files
committedApr 8, 2024
Adding in new X-Aleo-SDK-Version header
1 parent 411bd0b commit 0ec38e9

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed
 

‎sdk/src/network-client.ts

+23-5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ import {
1313

1414
type ProgramImports = { [key: string]: string | Program };
1515

16+
interface AleoNetworkClientOptions {
17+
headers?: { [key: string]: string };
18+
}
19+
1620
/**
1721
* Client library that encapsulates REST calls to publicly exposed endpoints of Aleo nodes. The methods provided in this
1822
* allow users to query public information from the Aleo blockchain and submit transactions to the network.
@@ -27,10 +31,20 @@ type ProgramImports = { [key: string]: string | Program };
2731
*/
2832
class AleoNetworkClient {
2933
host: string;
34+
headers: { [key: string]: string };
3035
account: Account | undefined;
3136

32-
constructor(host: string) {
37+
constructor(host: string, options?: AleoNetworkClientOptions) {
3338
this.host = host + "/testnet3";
39+
40+
if (options && options.headers) {
41+
this.headers = options.headers;
42+
43+
} else {
44+
this.headers = {
45+
"X-Aleo-SDK-Version": "0.6.9",
46+
};
47+
}
3448
}
3549

3650
/**
@@ -69,8 +83,12 @@ class AleoNetworkClient {
6983
url = "/",
7084
): Promise<Type> {
7185
try {
72-
const response = await get(this.host + url);
86+
const response = await get(this.host + url, {
87+
headers: this.headers
88+
});
89+
7390
return await response.json();
91+
7492
} catch (error) {
7593
throw new Error("Error fetching data.");
7694
}
@@ -627,9 +645,9 @@ class AleoNetworkClient {
627645
try {
628646
const response = await post(this.host + "/transaction/broadcast", {
629647
body: transaction_string,
630-
headers: {
648+
headers: Object.assign({}, this.headers, {
631649
"Content-Type": "application/json",
632-
},
650+
}),
633651
});
634652

635653
try {
@@ -644,4 +662,4 @@ class AleoNetworkClient {
644662
}
645663
}
646664

647-
export { AleoNetworkClient, ProgramImports }
665+
export { AleoNetworkClient, AleoNetworkClientOptions, ProgramImports }

‎sdk/src/utils.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
export async function get(url: URL | string) {
2-
const response = await fetch(url);
1+
export async function get(url: URL | string, options?: RequestInit) {
2+
const response = await fetch(url, options);
33

44
if (!response.ok) {
55
throw new Error(response.status + " could not get URL " + url);

0 commit comments

Comments
 (0)
Please sign in to comment.