Registry / http-networking / icon-sdk-js

icon-sdk-js

JSON →
library1.5.3jsnpmunverified

The ICON JavaScript SDK provides a comprehensive set of tools for interacting with the ICON blockchain network. It enables developers to build decentralized applications (dApps) and services by offering APIs for transaction building, wallet management, unit conversions, and communication with ICON nodes using JSON-RPC version 3. Currently at version 1.5.3, the library sees active development with regular dependency updates and feature additions, as evidenced by recent releases including new APIs like `icx_getNetworkInfo` and ongoing maintenance. Key differentiators include its explicit support for various JavaScript environments (Node.js, browser, React Native) and a modular builder pattern for constructing complex transactions.

npm install icon-sdk-js
INSTALL
IMPORT
SIG · ICON-SDK-JS
I
icon-sdk-js
http-networkingjavascriptv1.5.3
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

IconService
import IconService from 'icon-sdk-js'; // For browser/React Native // OR const IconService = require('icon-sdk-js'); // For Node.js
import { IconService } from 'icon-sdk-js'; // Incorrect named import for default export in browser const { IconService } = require('icon-sdk-js'); // Incorrect destructuring for default export in Node.js
IconService is the default export in browser/React Native environments and the module.exports in Node.js. The library ships with TypeScript types, supporting type-safe development.
IconBuilder
import IconService from 'icon-sdk-js'; const { IconBuilder } = IconService; // Accessing nested builder via default export
import { IconBuilder } from 'icon-sdk-js'; // Incorrect direct named import const IconBuilder = require('icon-sdk-js').IconBuilder; // Possible but less idiomatic if IconService is already imported
IconBuilder is an exposed property of the IconService class, not a direct top-level export. It's typically accessed via the main IconService object.
IcxTransactionBuilder
import IconService from 'icon-sdk-js'; const { IconBuilder } = IconService; const { IcxTransactionBuilder } = IconBuilder;
import { IcxTransactionBuilder } from 'icon-sdk-js'; // Incorrect direct named import
Transaction builders like IcxTransactionBuilder are deeply nested under IconService.IconBuilder and must be accessed through the parent objects.

Initializes the ICON SDK, connects to a public ICON node, and fetches basic network information like block height and demonstrates ICX unit conversion.

import IconService from 'icon-sdk-js'; import HttpProvider from 'icon-sdk-js/lib/httpprovider'; const rpcUrl = process.env.ICON_RPC_URL || 'https://lisbon.net.solidwallet.io/api/v3/icon'; const provider = new HttpProvider(rpcUrl); const iconService = new IconService(provider); async function getNetworkInfo() { try { const networkInfo = await iconService.getNetworkInfo().execute(); console.log('ICON Network Info:', networkInfo); const blockHeight = await iconService.getLastBlock().execute(); console.log('Current Block Height:', blockHeight.height); // Example of using IconAmount for conversion const icxAmount = IconService.IconAmount.of(100, IconService.IconAmount.Unit.ICX).toLoop(); console.log('100 ICX in Loop units:', icxAmount.toString()); } catch (error) { console.error('Failed to retrieve network info:', error); } } getNetworkInfo();
Debug
Known issues
gotchaThe Node.js environment requires a minimum version of 18.0.0. Using older Node.js versions may lead to unexpected errors or unsupported features.
fix
Upgrade your Node.js runtime to version 18.0.0 or higher using nvm or your preferred package manager.
affects: <18.0.0
gotchaWhen using `icon-sdk-js` in older browser environments that do not natively support the `fetch` API, a polyfill like `whatwg-fetch` is required for network requests to function correctly.
fix
Include `import 'whatwg-fetch';` in your project's entry point if targeting older browsers.
affects: <1.0.0
breakingVersion 1.5.0 introduced the `icx_getNetworkInfo` API. If your application relies on network information that might have been inferred differently before, consider updating your logic to use this new, explicit API.
fix
Update your code to call `iconService.getNetworkInfo().execute()` to retrieve comprehensive network details.
affects: <1.5.0
gotchaDependency vulnerabilities are regularly addressed through minor version bumps (e.g., `get-func-name`, `browserify-sign`, `@babel/traverse`). Users should regularly update to the latest patch version to ensure all known security fixes are applied.
fix
Run `yarn upgrade icon-sdk-js` or `npm update icon-sdk-js` to get the latest stable version.
affects: <=1.5.3
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'IconBuilder')
Attempting to destructure `IconBuilder` directly from the main `icon-sdk-js` module when using `require` or incorrect named import with `import`.
fix
Access `IconBuilder` as a property of the `IconService` object: `const IconService = require('icon-sdk-js'); const { IconBuilder } = IconService;` or `import IconService from 'icon-sdk-js'; const { IconBuilder } = IconService;`
ReferenceError: fetch is not defined
Running `icon-sdk-js` in an environment (e.g., older Node.js versions or some browser environments) where the global `fetch` API is not available.
fix
For Node.js, ensure Node.js >=18.0.0. For older browsers, import a `fetch` polyfill like `whatwg-fetch`.
Error: Failed to fetch
Network issues, incorrect RPC endpoint URL, or CORS policies preventing the browser from connecting to the ICON node.
fix
Verify your `rpcUrl` is correct and accessible. Ensure the ICON node is running and configured for public access. For browser apps, check server-side CORS configuration.
Upgrade
Version history
1.5.3latest on npm
Audit
Dependencies
node-fetchoptionalUsed internally for HTTP requests in Node.js environment; if using an older browser, `whatwg-fetch` polyfill might be required.
Agent activity
13 hits · last 30 days
node
12
OpenAI (training)
1
Resources
icon-sdk-js — npm install icon-sdk-js · libregistry