Skip to content

Commit 0d0b76c

Browse files
committed
fix: faucet node override vars missing in tx submission call
1 parent 6c899d4 commit 0d0b76c

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/api/routes/faucets.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,12 @@ export function createFaucetRouter(db: DataStore): RouterWithAsync {
130130
let sendError: Error | undefined = undefined;
131131
let sendSuccess = false;
132132
for (let i = 0; i < MAX_NONCE_INCREMENT_RETRIES; i++) {
133+
const network = getStxFaucetNetwork();
133134
const txOpts: SignedTokenTransferOptions = {
134135
recipient: address,
135136
amount: new BN(stxAmount.toString()),
136137
senderKey: privateKey,
137-
network: getStxFaucetNetwork(),
138+
network: network,
138139
memo: 'Faucet',
139140
};
140141
if (nextNonce !== undefined) {
@@ -143,7 +144,9 @@ export function createFaucetRouter(db: DataStore): RouterWithAsync {
143144
const tx = await makeSTXTokenTransfer(txOpts);
144145
const serializedTx = tx.serialize();
145146
try {
146-
const txSendResult = await new StacksCoreRpcClient().sendTransaction(serializedTx);
147+
const coreUrl = new URL(network.coreApiUrl);
148+
const rpcClient = new StacksCoreRpcClient({ host: coreUrl.hostname, port: coreUrl.port });
149+
const txSendResult = await rpcClient.sendTransaction(serializedTx);
147150
res.json({
148151
success: true,
149152
txId: txSendResult.txId,
@@ -152,7 +155,9 @@ export function createFaucetRouter(db: DataStore): RouterWithAsync {
152155
sendSuccess = true;
153156
break;
154157
} catch (error) {
155-
sendError = error;
158+
if (sendError === undefined) {
159+
sendError = error;
160+
}
156161
if (error.message?.includes('ConflictingNonceInMempool')) {
157162
nextNonce = unwrap(tx.auth.spendingCondition).nonce.add(new BN(1));
158163
} else if (error.message?.includes('BadNonce')) {

0 commit comments

Comments
 (0)