Skip to content
This repository was archived by the owner on Mar 18, 2026. It is now read-only.

Commit 1fc361f

Browse files
committed
fix: Update Stacks network imports and types for API service
1 parent 59800af commit 1fc361f

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

src/services/stacks-api-service.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { StacksNetworkName, StacksMainnet, StacksTestnet } from '@stacks/network';
1+
import { StacksNetworkName, STACKS_MAINNET, STACKS_TESTNET } from '@stacks/network';
22
import { ClarityValue, cvToHex, deserializeCV } from '@stacks/transactions';
3-
import { createApiKeyMiddleware, createFetchFn } from '@stacks/common';
3+
import { createApiKeyMiddleware, createFetchFn, FetchFn } from '@stacks/common';
44
import { AppConfig } from '../config';
55
import { ApiError } from '../utils/api-error-util';
66
import { ErrorCode } from '../utils/error-catalog-util';
@@ -62,7 +62,7 @@ export class StacksApiService {
6262

6363
try {
6464
// Create a custom fetch function with API key middleware if available
65-
let customFetchFn;
65+
let customFetchFn: FetchFn | undefined;
6666
if (this.hiroApiKey) {
6767
const apiMiddleware = createApiKeyMiddleware({
6868
apiKey: this.hiroApiKey,
@@ -71,15 +71,16 @@ export class StacksApiService {
7171
}
7272

7373
// Determine network object
74-
const networkObj = network === 'mainnet' ? new StacksMainnet() : new StacksTestnet();
74+
const networkObj = network === 'mainnet' ? STACKS_MAINNET : STACKS_TESTNET;
7575

7676
// Build API URL
77+
// TODO: coreUrl does not exist, updated object to use latest constant but property is missing. will include latest network docs to assist in fix.
7778
const url = `${networkObj.coreUrl}/v2/contracts/call-read/${contractAddress}/${contractName}`;
7879

7980
// Prepare request body
8081
const body = JSON.stringify({
8182
sender: senderAddress,
82-
arguments: functionArgs.map(arg => cvToHex(arg)),
83+
arguments: functionArgs.map((arg) => cvToHex(arg)),
8384
});
8485

8586
// Prepare fetch options
@@ -91,6 +92,7 @@ export class StacksApiService {
9192

9293
// Perform the fetch with timeout
9394
const response = await withTimeout(
95+
// TODO: issue with assinging Promise<unknown> to Promise<Response> here
9496
async () => {
9597
const resp = await (customFetchFn ? customFetchFn(url, fetchOptions) : fetch(url, fetchOptions));
9698
if (onResponse) onResponse(resp);
@@ -100,7 +102,7 @@ export class StacksApiService {
100102
`Contract call to ${contractAddress}.${contractName}::${functionName} timed out`
101103
);
102104

103-
// Parse response
105+
// Parse response - TODO related, we need to type this correctly response is unknown
104106
const data = await response.json<any>();
105107

106108
if (!response.ok) {

0 commit comments

Comments
 (0)