Symbol OpenAPI TypeScript Fetch Client
This package, `symbol-openapi-typescript-fetch-client` (version 1.0.3, last published in November 2021), provides a generated OpenAPI client for the Symbol blockchain. It is built using `symbol-openapi-generator` and designed to interact with Symbol nodes via the standard `fetch` API. It ships with TypeScript types, offering type-safe access to Symbol's REST API endpoints as defined by its OpenAPI specification at the time of its generation. However, it's crucial to note that this package is essentially an artifact generated from an older specification and generator. The README itself points users to `symbol-sdk-typescript-javascript`, which has since been deprecated (as of January 2022). For current Symbol blockchain development, the actively maintained `@symbol/symbol-sdk` package should be used instead, as this generated client is not regularly updated and reflects an outdated state of the Symbol ecosystem.
Common errors
-
TypeError: fetch is not defined
cause The client attempts to use the `fetch` API, but it's not available in the current JavaScript runtime, specifically in older Node.js versions (pre-18) or environments without a `fetch` polyfill.fixFor Node.js environments, upgrade to Node.js 18 or newer, or install `node-fetch` and polyfill `globalThis.fetch`: ```typescript import fetch from 'node-fetch'; globalThis.fetch = fetch as any; ``` -
Error: unable to verify the first certificate
cause This error typically occurs when connecting to a Symbol node via HTTPS with a self-signed or untrusted SSL certificate, common in local development environments or private networks without proper certificate authority setup.fixFor development, you can temporarily disable certificate verification by setting the `NODE_TLS_REJECT_UNAUTHORIZED='0'` environment variable (not recommended for production). Alternatively, configure your environment to trust the certificate or use an HTTP endpoint if available and appropriate for your security model.
Warnings
- breaking This package (version 1.0.3) was last published over 4 years ago (November 2021) and is considered abandoned. It reflects an outdated state of the Symbol OpenAPI specification and generator. Using it in new projects is highly discouraged due to potential incompatibilities and lack of updates.
- deprecated The README for this package explicitly directs users to `symbol-sdk-typescript-javascript` for client development. However, `symbol-sdk-typescript-javascript` itself has been deprecated as of January 2022. This further underscores the outdated nature of `symbol-openapi-typescript-fetch-client` and its recommendations.
- gotcha This is a *generated OpenAPI client*, not the comprehensive Symbol SDK. It provides raw API access based on the OpenAPI specification. It lacks higher-level abstractions, utility functions, and domain-specific logic that are present in the full `@symbol/symbol-sdk`.
- gotcha The client relies on the global `fetch` API. In Node.js environments prior to version 18, `fetch` is not natively available. Running the client in such environments will result in a runtime error.
Install
-
npm install symbol-openapi-typescript-fetch-client -
yarn add symbol-openapi-typescript-fetch-client -
pnpm add symbol-openapi-typescript-fetch-client
Imports
- Configuration
const Configuration = require('symbol-openapi-typescript-fetch-client').Configuration;import { Configuration } from 'symbol-openapi-typescript-fetch-client'; - NodeRoutesApi
import NodeRoutesApi from 'symbol-openapi-typescript-fetch-client/NodeRoutesApi';
import { NodeRoutesApi } from 'symbol-openapi-typescript-fetch-client'; - BlockRoutesApi
import { BlockRoutesApi } from 'symbol-openapi-typescript-fetch-client';
Quickstart
import { Configuration, NodeRoutesApi } from 'symbol-openapi-typescript-fetch-client';
async function getNodeHealthStatus() {
// For Node.js versions < 18, you might need a polyfill:
// import fetch from 'node-fetch';
// globalThis.fetch = fetch as any;
const nodeUrl = process.env.SYMBOL_NODE_URL ?? 'http://localhost:3000';
try {
const config = new Configuration({
basePath: nodeUrl,
// You can add headers, API keys, or other configurations here
// For example, for a public node, no specific auth is usually needed for node info.
});
const nodeApi = new NodeRoutesApi(config);
// Fetch the node info
const nodeInfo = await nodeApi.getNodeInfo();
console.log('Node Info:', nodeInfo);
// Fetch the node health status
const healthStatus = await nodeApi.getNodeHealth();
console.log('Node Health Status:', healthStatus);
} catch (error) {
console.error('Error fetching Symbol node information:', error);
if (error instanceof TypeError && error.message.includes('fetch is not defined')) {
console.error('Hint: In Node.js environments, ensure `fetch` is available. For Node.js < 18, install `node-fetch` and polyfill `globalThis.fetch`.');
}
}
}
getNodeHealthStatus();