Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions sdks/js/examples/spark-bare-app/auto-claim-static-deposit.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,22 @@ import walletConfig, { getExampleWalletOptions } from "./wallet-config.js";

async function autoclaimStaticDeposit(mnemonicInit, transactionId) {
const options = getExampleWalletOptions(process.env, "REGTEST");
let { wallet } = await SparkWallet.initialize({
mnemonicOrSeed: mnemonicInit,
options,
});
const quote = await wallet.getClaimStaticDepositQuote(transactionId);
const claimResult = await wallet.claimStaticDeposit({
transactionId,
creditAmountSats: quote.creditAmountSats,
sspSignature: quote.signature,
});
await wallet.cleanupConnections();
return claimResult;
let wallet;
try {
const initialized = await SparkWallet.initialize({
mnemonicOrSeed: mnemonicInit,
options,
});
wallet = initialized.wallet;
const quote = await wallet.getClaimStaticDepositQuote(transactionId);
return await wallet.claimStaticDeposit({
transactionId,
creditAmountSats: quote.creditAmountSats,
sspSignature: quote.signature,
});
} finally {
await wallet?.cleanupConnections();
}
}

const args = process.argv.slice(2);
Expand Down
22 changes: 13 additions & 9 deletions sdks/js/examples/spark-bare-app/create-lightning-invoice.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,20 @@ import walletConfig, { getExampleWalletOptions } from "./wallet-config.js";

async function createLightningInvoice(mnemonicInit, amountSats) {
const options = getExampleWalletOptions(process.env, "REGTEST");
const { wallet } = await SparkWallet.initialize({
mnemonicOrSeed: mnemonicInit,
options,
});
let wallet;
try {
const initialized = await SparkWallet.initialize({
mnemonicOrSeed: mnemonicInit,
options,
});
wallet = initialized.wallet;

const invoice = await wallet.createLightningInvoice({
amountSats: Number(amountSats),
});
await wallet.cleanupConnections();
return invoice;
return await wallet.createLightningInvoice({
amountSats: Number(amountSats),
});
} finally {
await wallet?.cleanupConnections();
}
}

const args = process.argv.slice(2);
Expand Down
29 changes: 17 additions & 12 deletions sdks/js/examples/spark-bare-app/get-or-create-wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,23 @@ import walletConfig, { getExampleWalletOptions } from "./wallet-config.js";

async function getOrCreateWallet(mnemonicInit) {
const options = getExampleWalletOptions(process.env, "REGTEST");
const { wallet, mnemonic } = await SparkWallet.initialize({
mnemonicOrSeed: mnemonicInit,
options,
});
const balance = await wallet.getBalance();
const sparkAddress = await wallet.getSparkAddress();
await wallet.cleanupConnections();
return {
mnemonic,
balance,
sparkAddress,
};
let wallet;
try {
const initialized = await SparkWallet.initialize({
mnemonicOrSeed: mnemonicInit,
options,
});
wallet = initialized.wallet;
const balance = await wallet.getBalance();
const sparkAddress = await wallet.getSparkAddress();
return {
mnemonic: initialized.mnemonic,
balance,
sparkAddress,
};
} finally {
await wallet?.cleanupConnections();
}
}

const args = process.argv.slice(2);
Expand Down
18 changes: 11 additions & 7 deletions sdks/js/examples/spark-bare-app/get-static-deposit-address.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ import walletConfig, { getExampleWalletOptions } from "./wallet-config.js";

async function getStaticDepositAddress(mnemonicInit) {
const options = getExampleWalletOptions(process.env, "REGTEST");
let { wallet, mnemonic } = await SparkWallet.initialize({
mnemonicOrSeed: mnemonicInit,
options,
});
const staticDepositAddress = await wallet.getStaticDepositAddress();
await wallet.cleanupConnections();
return staticDepositAddress;
let wallet;
try {
const initialized = await SparkWallet.initialize({
mnemonicOrSeed: mnemonicInit,
options,
});
wallet = initialized.wallet;
return await wallet.getStaticDepositAddress();
} finally {
await wallet?.cleanupConnections();
}
}

const args = process.argv.slice(2);
Expand Down
3 changes: 3 additions & 0 deletions sdks/js/examples/spark-bare-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"auto-claim-static-deposit": "node ./scripts/run-script.mjs auto-claim-static-deposit",
"create-lightning-invoice": "node ./scripts/run-script.mjs create-lightning-invoice",
"transfer": "node ./scripts/run-script.mjs transfer",
"repro:agent-suspend-balance": "node ./scripts/run-script.mjs repro-agent-suspend-balance",
"run": "node ./scripts/run-script.mjs",
"run:local": "cross-env NODE_ENV=development NETWORK=LOCAL ../../scripts/with-local-routing.sh node ./scripts/run-script.mjs",
"run:mainnet": "cross-env NODE_ENV=production NETWORK=MAINNET node ./scripts/run-script.mjs",
Expand All @@ -21,6 +22,8 @@
"@buildonspark/bare": "0.0.67",
"@buildonspark/spark-sdk": "0.7.17",
"bare": "^1.28.4",
"bare-http1": "^4.5.2",
"bare-https": "^3.0.0",
"bare-runtime": "^1.28.4"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
$ WATCHDOG_MS=20000 NETWORK=MAINNET bare repro-agent-suspend-balance.js
[2026-05-08T19:21:37.090Z] starting Bare agent suspend balance repro { cleanupConnections: true, network: 'MAINNET', watchdogMs: 20000 }
[2026-05-08T19:21:37.815Z] wallet initialized
[2026-05-08T19:21:37.935Z] initial balance resolved after 120ms {
balance: 0n,
satsBalance: { available: 0n, owned: 0n, incoming: 0n },
tokenBalances: Map(0) {}
}
[2026-05-08T19:21:37.936Z] agents suspended
[2026-05-08T19:21:37.939Z] balance while agents already suspended rejected after 3ms SparkError: /spark.SparkService/query_nodes UNKNOWN: Transport error: AGENT_SUSPENDED: Agent is suspended [serverTraceId: 39961a9aa0d63b37fec142d383eca5a6, idPubKey: 03114fc8a14874bec79b734a44c8b7c36efb4d9dbce7ad51cc4e8cfe4746e6ba22, clientEnv: js-spark-sdk/0.7.17 bare/v1.28.4]
[2026-05-08T19:21:37.939Z] agents resumed
[2026-05-08T19:21:37.939Z] same already-suspended balance promise after resume rejected after 0ms SparkError: /spark.SparkService/query_nodes UNKNOWN: Transport error: AGENT_SUSPENDED: Agent is suspended [serverTraceId: 39961a9aa0d63b37fec142d383eca5a6, idPubKey: 03114fc8a14874bec79b734a44c8b7c36efb4d9dbce7ad51cc4e8cfe4746e6ba22, clientEnv: js-spark-sdk/0.7.17 bare/v1.28.4]
[2026-05-08T19:21:37.940Z] agents suspended
[2026-05-08T19:21:52.943Z] balance suspended while in flight rejected after 15003ms SparkError: /spark.SparkService/query_nodes UNKNOWN: Transport error: /spark.SparkService/query_nodes UNAVAILABLE: UNAVAILABLE: request timed out after 15000ms [serverTraceId: 39961a9aa0d63b37fec142d383eca5a6, idPubKey: 03114fc8a14874bec79b734a44c8b7c36efb4d9dbce7ad51cc4e8cfe4746e6ba22, clientEnv: js-spark-sdk/0.7.17 bare/v1.28.4]
[2026-05-08T19:21:52.943Z] agents resumed
[2026-05-08T19:21:53.172Z] fresh balance after resume resolved after 229ms {
balance: 0n,
satsBalance: { available: 0n, owned: 0n, incoming: 0n },
tokenBalances: Map(0) {}
}
[2026-05-08T19:21:53.173Z] cleaning up wallet connections
[2026-05-08T19:21:53.175Z] repro script completed
real 16.38
user 0.41
sys 0.09
exit_code=0
Loading
Loading