npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

necjs

v1.3.8

Published

NECJS SDK for NCOG Earth Chain RPC

Readme

NEC BLOCKCHAIN SDK

The all-in-one JavaScript/TypeScript SDK for building apps on the NCOG Earth Chain.
Supports Node.js, browsers, React, Next.js, Vite, and React Native.
Includes post-quantum cryptography, wallet management, contract interaction, extension wallet support, contract deployment, and real-time subscriptions.

Key Features

  • Multi-Platform Support: Node.js, Browser, React Native, React, Next.js, Vite
  • Post-Quantum Cryptography: MLKEM and MLDSA87 algorithms via WebAssembly
  • Smart Contract Integration: Deploy, interact, and manage smart contracts
  • Wallet Management: Private key wallets and browser extension integration
  • Real-time Subscriptions: WebSocket-based blockchain event monitoring
  • Ethereum Compatibility: JSON-RPC protocol support
  • TypeScript Support: Full type definitions and IntelliSense

Package Information

  • Name: necjs
  • License: MIT
  • Repository: https://github.com/Ncog-Earth-Chain/nec-node-sdk
  • Author: [email protected]
  • Node.js Requirement: >=16.0.0

Documentation Index

Platform-Specific Guides

Function Reference Documentation

Specialized Documentation


Setup & Installation

Prerequisites

  • Node.js >= 16.0.0
  • npm or yarn package manager

Installation

For End Users

# Install the package
npm install necjs

# Or using yarn
yarn add necjs

Requirements

  1. Node.js Environment

    # Verify Node.js version
    node --version  # Should be >= 16.0.0
    
  2. Browser Environment

    • No additional setup required
    • WebAssembly support is automatically handled
  3. React Native Environment

Build Configuration

The project uses Rollup for bundling with multiple output formats:

  • CommonJS (dist/index.cjs.js) - Node.js compatibility
  • ES Modules (dist/index.esm.js) - Modern JavaScript
  • UMD (dist/index.umd.js) - Universal module definition
  • Browser-specific (dist/index.browser.esm.js) - Browser optimization
  • React Native (dist/index.react-native.esm.js) - React Native optimization

Use Cases & Examples

1. Basic Wallet Operations

import { loadWasm, Provider, Wallet } from 'necjs';

async function basicWalletExample() {
  // Initialize WebAssembly
  await loadWasm();
  
  // Create wallet from private key
  const wallet = await Wallet.create('0x1234567890abcdef...');
  console.log('Wallet address:', wallet.address);
  
  // Connect to blockchain
  const provider = new Provider('https://rpc.ncog.earth');
  
  // Get balance
  const balance = await provider.getBalance(wallet.address);
  console.log('Balance:', balance);
}

2. Smart Contract Interaction

import { Provider, Contract } from 'necjs';

async function contractExample() {
  const provider = new Provider('https://rpc.ncog.earth');
  
  // Contract ABI and address
  const contractABI = [...];
  const contractAddress = '0x...';
  
  // Create contract instance
  const contract = new Contract(contractAddress, contractABI, provider);
  
  // Call contract function
  const result = await contract.methods.getBalance().call();
  console.log('Contract balance:', result);
}

3. Contract Deployment

import { Provider, ContractFactory, Wallet } from 'necjs';

async function deployContract() {
  await loadWasm();
  
  const wallet = await Wallet.create('0x...');
  const provider = new Provider('https://rpc.ncog.earth');
  
  // Contract bytecode and ABI
  const contractBytecode = '0x...';
  const contractABI = [...];
  
  // Deploy contract
  const factory = new ContractFactory(contractABI, contractBytecode, wallet);
  const contract = await factory.deploy('Constructor Parameter');
  
  console.log('Deployed contract address:', contract.address);
}

4. Browser Extension Integration

import { Provider, ExtensionSigner } from 'necjs';

async function extensionExample() {
  if (window.ncogWallet) {
    const provider = new Provider('https://rpc.ncog.earth');
    const signer = new ExtensionSigner(window.ncogWallet, provider);
    
    const address = await signer.getAddress();
    console.log('Extension wallet address:', address);
    
    // Send transaction
    const tx = await signer.sendTransaction({
      to: '0x...',
      value: '1000000000000000000' // 1 ETH
    });
  }
}

5. Real-time Subscriptions

import { Provider, Subscription } from 'necjs';

async function subscriptionExample() {
  const provider = new Provider('wss://rpc.ncog.earth');
  
  // Subscribe to new blocks
  const subscription = new Subscription(provider);
  const blockSub = await subscription.subscribe('newHeads', (block) => {
    console.log('New block:', block);
  });
  
  // Subscribe to contract events
  const eventSub = await subscription.subscribe('logs', {
    address: '0x...',
    topics: ['0x...']
  }, (log) => {
    console.log('Contract event:', log);
  });
}

6. Post-Quantum Cryptography

import { loadWasm, MlKem } from 'necjs';

async function mlkemExample() {
  await loadWasm();
  
  // Generate key pair
  const keyPair = await MlKem.keygen();
  
  // Encrypt message
  const ciphertext = await MlKem.encaps(keyPair.publicKey);
  
  // Decrypt message
  const plaintext = await MlKem.decaps(ciphertext, keyPair.secretKey);
  
  console.log('Decrypted message:', plaintext);
}

7. React Integration

import React, { useEffect, useState } from 'react';
import { loadWasm, Provider, Wallet } from 'necjs';

function WalletComponent() {
  const [balance, setBalance] = useState(null);
  const [address, setAddress] = useState(null);
  
  useEffect(() => {
    async function initWallet() {
      await loadWasm();
      const wallet = await Wallet.create('0x...');
      const provider = new Provider('https://rpc.ncog.earth');
      
      setAddress(wallet.address);
      const bal = await provider.getBalance(wallet.address);
      setBalance(bal);
    }
    
    initWallet();
  }, []);
  
  return (
    <div>
      <p>Address: {address}</p>
      <p>Balance: {balance}</p>
    </div>
  );
}

API Reference

Core Classes

Provider

  • Constructor: new Provider(url, options?)
  • Methods: getBalance(), getBlockNumber(), sendTransaction(), etc.
  • Events: WebSocket connection events

Wallet

  • Static Methods: create(privateKey), fromMnemonic(mnemonic)
  • Instance Methods: signTransaction(tx), getAddress()
  • Properties: address, privateKey

Contract

  • Constructor: new Contract(address, abi, provider)
  • Methods: Dynamic methods based on ABI
  • Events: events.EventName()

ContractFactory

  • Constructor: new ContractFactory(abi, bytecode, signer)
  • Methods: deploy(...args), attach(address)

ExtensionSigner

  • Constructor: new ExtensionSigner(extension, provider)
  • Methods: getAddress(), sendTransaction(tx), signMessage(message)

Subscription

  • Constructor: new Subscription(provider)
  • Methods: subscribe(type, params?, callback), unsubscribe(id)

Utility Functions

  • hexToDecimalString(hex): Convert hex to decimal
  • decimalToHex(value): Convert decimal to hex
  • etherToWeiHex(value): Convert Ether to Wei
  • formatUnits(value, decimals): Format with decimals
  • isValidAddress(address): Validate address format
  • serializeForRpc(payload): Prepare RPC payload
  • normalizeResponse(resp): Normalize RPC response

MLKEM Functions

  • loadWasm(): Initialize WebAssembly
  • MlKem.keygen(): Generate key pair
  • MlKem.encaps(publicKey): Encrypt message
  • MlKem.decaps(ciphertext, secretKey): Decrypt message
  • MlKem.sign(message, secretKey): Sign message
  • MlKem.verify(message, signature, publicKey): Verify signature

Performance Optimization

  1. WebAssembly Loading: Load WASM once and reuse
  2. Provider Connections: Reuse provider instances
  3. Contract Instances: Cache contract instances
  4. Subscription Management: Properly unsubscribe from events

Security Considerations

  1. Private Key Management: Never expose private keys in client-side code
  2. RPC Endpoint Security: Use HTTPS/WSS for production
  3. Input Validation: Validate all user inputs
  4. Error Handling: Don't expose sensitive information in errors

Support & Community

Getting Help

Resources

Contributing

We welcome contributions! Please see the development guide above for details on how to contribute to the project.


License

This project is licensed under the MIT License - see the LICENSE file for details.


NECJS SDK - Building the future of decentralized applications with post-quantum security.