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 🙏

© 2024 – Pkg Stats / Ryan Hefner

qtum-light-js

v0.6.2

Published

JavaScript library for Qtum Light Wallet

Downloads

14

Readme

qtum-light-js

qtum-light-js is a JavaScript library for Qtum Light Wallet.

Installation

NPM Stats

NPM

npm npm i --save qtum-light-js

Yarn

yarn add qtum-light-js

Usage

Import

import { QtumLightApi } from 'qtum-light-js';

QtumLightApi class

QtumLightApi is the single interface to use qtum-light-js.

const qtumLightApi = new QtumLightApi();

Once we create the instance of QtumLightApi, then we can use it to interact with Qtum Light Wallet.

isQtumLightInstalled method

isQtumLightInstalled is used to get the installation status of Qtum Light Wallet

const installed = qtumLightApi.isQtumLightInstalled();

getCurrentAddress method

getCurrentAddress is used to get current active wallet address, it returns the active wallet address or null if the wallet is locked.

const address = await qtumLightApi.getCurrentAddress();

queryAccount method

queryAccount(address) is used to get the account information. It returns a Promise.

const account = await qtumLightApi.queryAccount(address);

queryTransaction method

queryTransaction(tx) is used to get the transaction result. It returns a Promise with the transaction information. It throw an error if there is any error like network issue.

const result = await qtumLightApi.queryTransaction(tx);

queryConfirmation method

queryConfirmation(tx) is used to get the confirmation. It returns a Promise with the confirmation information. It will keep retrying every period time until the blockchain finish or fail the confirmation. It throw an error if there is any error like network issue.

const result = await qtumLightApi.queryConfirmation(tx, period);

The difference between queryTransaction and queryConfirmation is queryTransaction will return immediately once it retrieve the transaction information. Thus queryConfirmation will keep retrying every period time until the blockchain finish or fail the confirmation.

DataTypes property

DataTypes provides a set of data type constants for the input and output of the contract calls. e.g. UINT256, STRING, ADDRESS. We can use them like:

const { UINT256, ADDRESS } = qtumLightApi.DataTypes; 

Contract method

Contract(address) method takes the address of the contract and returns an object of Contract class. Or returns null if the address is invalid.

const contract = qtumLightApi.Contract('a27225bcb75142b8f90dcf3365055899b7c091fd');

More details can be found in Contract class.

Contract class

constructor method

the constructor takes an address parameter.

send method

send(method, inputData, inputTypes, amount, gasPrice, gasLimit) is used to send a transaction to the smart contract on the blockchain. It is a write operation and needs some gas to process.

method is the name of the method within the smart contract to call.

inputData is the input data e.g. [1, 'abc', true, 'a27225bcb75142b8f90dcf3365055899b7c091fd'].

inputTypes is the input types e.g. [UINT256, STRING, BOOL, ADDRESS].

amount is the amount to be sent to the contract.

gasPrice is the gas price to be used for the transaction.

gasLimit is the gas limit to be used for the transaction.

It returns the transaction id in a Promise once the blockchain receives the transaction.

try {
  const result = await contract.send(
    'increment', // method
    [3, 1], // inputData
    [UINT256, UINT256], // inputTypes
    0 // amount
  );

  this.setState({output: result});
} catch (e) {
  this.setState({output: e.message});
}    

call method

call(method, inputData, inputTypes, outputTypes) is used to call a method within the smart contract on the blockchain. It is a read operation and doesn't need any gas to process.

method is the name of the method within the smart contract to call.

inputData is the input data e.g. [1, 'abc', true, 'a27225bcb75142b8f90dcf3365055899b7c091fd'].

inputTypes is the input types e.g. [UINT256, STRING, BOOL, ADDRESS].

outputTypes is the output types e.g. [STRING, UINT256, ADDRESS, BOOL].

It returns the data in an array. e.g. ['abc', 1, 'a27225bcb75142b8f90dcf3365055899b7c091fd', true]. Or if there is only one data, then only return data without array e.g. 'abc'.

try {
  const result = await contract.call(
    'getCount', // method
    null, // inputData
    null, // inputTypes
    [UINT256, UINT256, ADDRESS] // outputTypes
  );
  this.setState({output: JSON.stringify(result)});
} catch (e) {
  this.setState({output: e.message});
}

queryTransaction method

queryTransaction(tx) is same as queryTransaction method in QtumLightApi class.

const result = await contract.queryTransaction(tx);

queryConfirmation method

queryConfirmation(tx) is same as queryConfirmation method in QtumLightApi class.

const result = await contract.queryConfirmation(tx, period);

sendAndConfirm method

sendAndConfirm(method, inputData, inputTypes, amount, gasPrice, gasLimit, period) is used to send a transaction to the smart contract on the blockchain and wait for the confirmation. It is a write operation and needs some gas to process.

method is the name of the method within the smart contract to call.

inputData is the input data e.g. [1, 'abc', true, 'a27225bcb75142b8f90dcf3365055899b7c091fd'].

inputTypes is the input types e.g. [UINT256, STRING, BOOL, ADDRESS].

amount is the amount to be sent to the contract.

gasPrice is the gas price to be used for the transaction.

gasLimit is the gas limit to be used for the transaction.

period is the duration to query the confirmation.

try {
  const result = await contract.sendAndConfirm(
    'increment', // method
    [3, 1], // inputData
    [UINT256, UINT256], // inputTypes
    0 // amount
  );
  this.setState({output: JSON.stringify(result)});
} catch (e) {
  this.setState({output: e.message});
}

License

LGPL-3.0+