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

@web4/iq.js

v1.0.0

Published

The JavaScript SDK for the IQ network.

Downloads

3

Readme

IQ.js

Iq.js a JavaScript SDK for writing applications that interact with the Iq blockchain from either Node.js, browser, or React Native environments and provides simple abstractions over core data structures, serialization, key management, and API request generation.

Features

  • Written in TypeScript, with type definitions
  • Versatile support for key management solutions
  • Works in Node.js, in the browser, and React Native
  • Exposes the Iq API through LCDClient
  • Parses responses into native JavaScript types

We highly suggest using Iq.js with TypeScript, or JavaScript in a code editor that has support for type declarations, so you can take advantage of the helpful type hints that are included with the package.

Installation

Grab the latest version off NPM:

npm install @web4/iq.js

Usage

Iq.js can be use in Node.js, as well as inside the browser. Please check the docs for notes on how to get up and running.

Getting blockchain data

import { LCDClient, Coin } from '@web4/iq.js';

// connect to mcafee testnet
const iq = new LCDClient({
  URL: 'https://mcafee-lcd.iqchain.network',
  chainID: 'mcafee-1',
});

// To use LocalIq
// const iq = new LCDClient({
//   URL: 'http://localhost:1317',
//   chainID: 'localiq'
// });

// get the current swap rate from 1 BUSD to I
BKRW
const offerCoin = new Coin('ubusd', '1000000');
iq.market.swapRate(offerCoin, 'ubkrw').then(c => {
  console.log(`${offerCoin.toString()} can be swapped for ${c.toString()}`);
});

Broadcasting transactions

First, get some testnet tokens for iq1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v, or use LocalIq.

import { LCDClient, MsgSend, MnemonicKey } from '@web4/iq.js';

// create a key out of a mnemonic
const mk = new MnemonicKey({
  mnemonic:
    'notice oak worry limit wrap speak medal online prefer cluster roof addict wrist behave treat actual wasp year salad speed social layer crew genius',
});

// connect to mcafee testnet
const iq = new LCDClient({
  URL: 'https://mcafee-lcd.iqchain.network',
  chainID: 'mcafee-1',
});

// To use LocalIq
// const iq = new LCDClient({
//   URL: 'http://localhost:1317',
//   chainID: 'localiq'
// });

// a wallet can be created out of any key
// wallets abstract transaction building
const wallet = iq.wallet(mk);

// create a simple message that moves coin balances
const send = new MsgSend(
  'iq1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v',
  'iq17lmam6zguazs5q5u6z5mmx76uj63gldnse2pdp',
  { ubiq: 1000000, ubkrw: 1230201, ubusd: 1312029 }
);

wallet
  .createAndSignTx({
    msgs: [send],
    memo: 'test from iq.js!',
  })
  .then(tx => iq.tx.broadcast(tx))
  .then(result => {
    console.log(`TX hash: ${result.txhash}`);
  });

Iq.js in the browser

You can access all the objects of the @web4/iq.js from the global Iq object if you load Iq.js with a <script> tag.

Include the following in your browser:

<script
  crossorigin
  src="https://unpkg.com/@web4/iq.js/dist/bundle.js"
></script>

You can find a small JSFiddle example that refreshes current Oracle votes here.

Iq.js in React Native

In order to use Iq.js inside React Native, you need to add the node-libs-react-native package and react-native-get-random-values package to your React Native app's package.json.

yarn add node-libs-react-native react-native-get-random-values

You will need to register Node.js native modules in an entry point of your application, such as index.tsx:

import 'node-libs-react-native/globals';
import 'react-native-get-random-values';

Also, add resolvers to your metro.config.js

module.exports {
  // ...
  resolver: {
    // ...
    extraNodeModules: require('node-libs-react-native'),
  },
  // ...
}

License

This software is licensed under the MIT license. See LICENSE for full disclosure.

© 2022 BitWeb Labs