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

@nimiq/core

v2.0.5

Published

Nimiq's Rust-to-WASM web client

Downloads

2,112

Readme

Nimiq Albatross Light Client

A very light Nimiq Proof-of-Stake client for browsers and NodeJS, compiled from Rust to WebAssembly.

Note This light client is intended to be used in web browsers or NodeJS only (no WASI support either). Other webworker-enabled environments are not yet supported.

📦 Installation

You need to install this package from the next tag:

npm install @nimiq/core@next

or

yarn add @nimiq/core@next

🛠️ Usage

This package contains the WASM file bundled for three targets: bundler, web and node.

With Bundlers

If you use any bundler for your project, like Webpack or Vite, you should probably use the bundler target exported from the package root. If that doesn't work, or you require the web target for your use-case, jump to the With ES Modules section.

[!IMPORTANT] For Webpack 5:

  • Enable the asyncWebAssembly experiment in your config.
  • Dynamically import the package with await import().

[!IMPORTANT] For Vite:

  • Use the vite-plugin-wasm plugin.
  • Exclude this package from Vite's dependency optimization:
// vite.config.ts
optimizeDeps: {
   exclude: ['@nimiq/core'],
}

[!IMPORTANT] For Nuxt:

  • Use the vite-plugin-wasm plugin.
  • Exclude this package from Vite's dependency optimization:
// nuxt.config.ts
vite: {
  optimizeDeps: {
     exclude: ['@nimiq/core'],
  }
}
  • Ensure the package is only run client-side: either set ssr: false in your Nuxt config, import this package only in client-side plugins, or wrap it in <ClientOnly>.
// With Webpack: import the package asynchronously:
const Nimiq = await import('@nimiq/core');
// With Vite, import at the top of your file:
import * as Nimiq from '@nimiq/core';

// Create a configuration builder:
const config = new Nimiq.ClientConfiguration();

// Change the config, if necessary:
// --------------------------------
// Specify the network to use:
// Optional, default is 'testalbatross'
config.network('testalbatross');
// Specify the seed nodes to initially connect to:
// Optional, default is ['/dns4/seed1.pos.nimiq-testnet.com/tcp/8443/wss']
config.seedNodes(['/dns4/seed1.pos.nimiq-testnet.com/tcp/8443/wss']);
// Change the lowest log level that is output to the console:
// Optional, default is 'info'
config.logLevel('debug');

// Instantiate and launch the client:
const client = await Nimiq.Client.create(config.build());

With ES Modules

// Import the loader and package from the /web path:
import init, * as Nimiq from '@nimiq/core/web';

// Load and initialize the WASM file
init().then(() => {
    // Create a configuration builder:
    const config = new Nimiq.ClientConfiguration();

    // Change the config as shown above, if necessary
    // ...

    // Instantiate and launch the client:
    const client = await Nimiq.Client.create(config.build());
});

NodeJS

For NodeJS, this package includes both CommonJS and ESM builds. You can either require() the package or import it.

// Import as CommonJS module
const Nimiq = require("@nimiq/core");
// Or import as ESM module
import * as Nimiq from "@nimiq/core";

// In ESM modules you can use await at the top-level and do not need an async wrapper function.
async function main() {
    // Create a configuration builder:
    const config = new Nimiq.ClientConfiguration();

    // Change the config as shown above, if necessary
    // ...

    // Instantiate and launch the client:
    const client = await Nimiq.Client.create(config.build());
}
main();

🐛 Issues, Bugs and Feedback

This is an early version of the client code compiled to WebAssembly and as such there can be problems and friction, especially now that more people try it out in more environments than we could ever test ourselves.

If you encounter issues or you find a bug, please open an issue in our Github at https://github.com/nimiq/core-rs-albatross.

If you want to provide feedback or have questions about the client, our "Nimiq Coders Dojo" Telegram group and the Community Forum are the right places for that.