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

xian-js

v0.1.9

Published

javascript tools for interacting with the Xian blockchain.

Readme

xian-js

JavaScript/TypeScript SDK for interacting with the Xian blockchain network. This library provides comprehensive tools for wallet management, transaction handling, and smart contract interactions.

Table of Contents

Installation

npm install xian-js

Features

  • Basic and HD wallet creation using BIP39/BIP32 standards
  • Secure keystore functionality for encrypted key storage
  • Transaction creation, simulation, and broadcasting
  • Support for both synchronous and asynchronous transaction submission
  • Smart contract deployment and interaction
  • Comprehensive blockchain querying capabilities
  • Network status monitoring and management
  • Advanced data encoding utilities for blockchain-specific types
  • Custom BigNumber handling for precise decimal operations
  • Message signing and verification utilities
  • Event emitting system for real-time updates
  • TypeScript support with full type definitions

Quick Start

import { TransactionBuilder, Wallet } from "xian-js";

// Create a new wallet
const wallet = Wallet.create_wallet();
console.log(`Public Key: ${wallet.vk}`);

// Set up network information
const network_info = {
    chain_id: "xian-testnet-1",
    masternode_hosts: ["https://testnet.xian.org"]
};

// Create and send a transaction
const tx_info = {
    senderVk: wallet.vk,
    chain_id: network_info.chain_id,
    contractName: "currency",
    methodName: "transfer",
    kwargs: {
        to: "recipient_address",
        amount: 100
    },
    stampLimit: 50000
};

const transaction = new TransactionBuilder(network_info, tx_info);
const result = await transaction.send(wallet.sk);

Usage Guide

Wallet Management

Creating Wallets

import { Wallet } from "xian-js";

// Create a new wallet
const newWallet = Wallet.create_wallet();

// Create from existing private key
const existingWallet = Wallet.create_wallet({
    sk: "your_private_key_here"
});

// Create BIP39 HD wallet
const hdWallet = Wallet.new_wallet_bip39();
console.log(`Mnemonic: ${hdWallet.mnemonic}`);

Message Signing and Verification

// Sign a message
const message = Buffer.from('Hello Xian');
const signature = wallet.sign(wallet.sk, message);

// Verify signature
const isValid = wallet.verify(wallet.vk, message, signature);

Transaction Management

Basic Transaction

const tx_info = {
    senderVk: wallet.vk,
    chain_id: network_info.chain_id,
    contractName: "currency",
    methodName: "transfer",
    kwargs: {
        to: "recipient_address",
        amount: 100
    }
};

const transaction = new TransactionBuilder(network_info, tx_info);
const result = await transaction.send(wallet.sk);

Transaction Simulation

// Simulate transaction to estimate stamps
const simulation = await transaction.simulate_txn(wallet.sk);
console.log(`Estimated stamps: ${simulation.stamps_used}`);

Keystore Management

The SDK provides secure key storage functionality:

import { Keystore } from "xian-js";

// Create a new keystore
const keystore = new Keystore();

// Add keys with metadata
keystore.addKey({
    sk: "private_key_here",
    nickname: "Main Wallet",
    name: "Trading Account",
    network: "testnet"
});

// Encrypt keystore with password
const encrypted = keystore.createKeystore("your_password", "optional_hint");

// Load encrypted keystore
const loadedKeystore = new Keystore({ keystoreData: encrypted });
loadedKeystore.decryptKeystore("your_password");

// Access wallets
const wallets = loadedKeystore.wallets;

Data Encoding

The SDK includes utilities for handling blockchain-specific data types:

import { Encoder } from "xian-js";

// Handle blockchain numbers with precision
const amount = Encoder("bigNumber", "123.456789");

// Encode various data types
const intValue = Encoder("int", 123);
const floatValue = Encoder("float", 123.456);
const dateValue = Encoder("datetime", new Date());
const listValue = Encoder("list", [1, 2, 3]);

Network Interactions

import { Network } from "xian-js";

const network = new Network({
    chain_id: "xian-testnet-1",
    masternode_hosts: ["https://testnet.xian.org"]
});

// Check network status
const isOnline = await network.ping();

// Get latest block
const latestBlock = await network.getLastetBlock();

Smart Contract Operations

import { MasternodeAPI } from "xian-js";

const api = new MasternodeAPI(network_info);

// Get contract info
const contractInfo = await api.getContractInfo("currency");

// Get contract methods
const methods = await api.getContractMethods("currency");

// Query contract state
const state = await api.getVariable("currency", "balances", address);

Blockchain Queries

// Get account balance
const balance = await api.getCurrencyBalance(address);

// Get transaction details
const tx = await api.getTxResult(txHash);

// Get contract variables
const variables = await api.getContractVariables("currency");

Events System

The SDK includes an event emitter system for real-time updates:

network.events.on("online", (status) => {
    console.log(`Network status changed: ${status}`);
});