Skip to content

Commit 17fbbb9

Browse files
Add debug mode to network client
1 parent ad57da5 commit 17fbbb9

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

sdk/src/network-client.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,14 @@ class AleoNetworkClient {
3939
headers: { [key: string]: string };
4040
account: Account | undefined;
4141
ctx: { [key: string]: string };
42+
debugMode: boolean;
4243
readonly network: string;
4344

4445
constructor(host: string, options?: AleoNetworkClientOptions) {
4546
this.host = host + "/%%NETWORK%%";
4647
this.network = "%%NETWORK%%";
4748
this.ctx = {};
49+
this.debugMode = true;
4850

4951
if (options && options.headers) {
5052
this.headers = options.headers;
@@ -101,6 +103,24 @@ class AleoNetworkClient {
101103
this.host = host + "/%%NETWORK%%";
102104
}
103105

106+
/**
107+
* Set debug mode for the networkClient. When this mode is enabled, if Aleo network nodes report failures after
108+
* calling the `submitTransaction` method, nodes will report debug information as to why the transaction failed.
109+
*
110+
* @param {boolean} debugMode Set debug mode for the networkClient.
111+
* @example
112+
* import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
113+
*
114+
* // Create a networkClient
115+
* const networkClient = new AleoNetworkClient();
116+
*
117+
* // Set debug mode to true
118+
* networkClient.setDebugMode(true);
119+
**/
120+
setDebugMode(debugMode: boolean) {
121+
this.debugMode = debugMode;
122+
}
123+
104124
/**
105125
* Set a header in the `AleoNetworkClient`s header map
106126
*
@@ -1538,8 +1558,9 @@ class AleoNetworkClient {
15381558
? transaction.toString()
15391559
: transaction;
15401560
try {
1561+
const endpoint = this.debugMode ? "transaction/broadcast?debug=true" : "transaction/broadcast";
15411562
const response = await retryWithBackoff(() =>
1542-
this._sendPost(this.host + "/transaction/broadcast", {
1563+
this._sendPost(`${this.host}/${endpoint}`, {
15431564
body: transactionString,
15441565
headers: Object.assign({}, {...this.headers, "X-ALEO-METHOD" : "submitTransaction"}, {
15451566
"Content-Type": "application/json",

0 commit comments

Comments
 (0)