Skip to content

Commit

Permalink
fix: allow custom chain ID in JS scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
hstove committed Oct 14, 2024
1 parent fdb340a commit e240b15
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions stacking/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
AccountsApi,
} from '@stacks/blockchain-api-client';
import pino, { Logger } from 'pino';
import { ChainID } from '@stacks/common';

const serviceName = process.env.SERVICE_NAME || 'JS';
export let logger: Logger;
Expand All @@ -37,8 +38,11 @@ if (process.env.STACKS_LOG_JSON === '1') {
});
}

export const CHAIN_ID = parseEnvInt('CHAIN_ID', false) ?? ChainID.Testnet;

export const nodeUrl = `http://${process.env.STACKS_CORE_RPC_HOST}:${process.env.STACKS_CORE_RPC_PORT}`;
export const network = new StacksTestnet({ url: nodeUrl });
network.chainId = CHAIN_ID;
const apiConfig = new Configuration({
basePath: nodeUrl,
});
Expand Down
2 changes: 1 addition & 1 deletion stacking/stacking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ async function stackStx(poxInfo: PoxInfo, account: Account, balance: bigint) {
if (typeof stackAmount === 'number') {
amountToStx = BigInt(stackAmount) * 1_000_000n;
}

if (amountToStx > balance) {
throw new Error(
`Insufficient balance to stack-stx (amount=${amountToStx}, balance=${balance})`
Expand Down

0 comments on commit e240b15

Please sign in to comment.