ICON JavaScript SDK

1.5.3 · active · verified Tue Apr 21

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.

Common errors

Warnings

Install

Imports

Quickstart

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();

view raw JSON →