Skip to content

Nimiq Web Client in Vite

The Nimiq Web Client ships with support for Vite.


Installation

bash
npm install @nimiq/core-web@next
npm install -D vite-plugin-top-level-await vite-plugin-wasm
bash
yarn add @nimiq/core-web@next
yarn add -D vite-plugin-top-level-await vite-plugin-wasm
bash
pnpm add @nimiq/core-web@next
pnpm add -D vite-plugin-top-level-await vite-plugin-wasm
bash
bun add @nimiq/core-web@next
bun add -D vite-plugin-top-level-await vite-plugin-wasm
info

Currently, Vite does not support WebAssembly out of the box. To enable WebAssembly support, you need to install the vite-plugin-wasm plugin. Learn more here.

Update your vite.config.js:

javascript
import wasm from "vite-plugin-wasm"; 
import topLevelAwait from "vite-plugin-top-level-await"; 

export default defineConfig({
  plugins: [
    wasm(), 
    topLevelAwait(), 
  ],

  optimizeDeps: { 
    exclude: ['@nimiq/core-web'], 
  }, 
})

Now you are ready to go!

js
import init, { Client, ClientConfiguration } from '@nimiq/core-web/web'

await init()

const config = new ClientConfiguration()
const client = await Client.create(config.build())

await client.waitForConsensusEstablished​()

Contribute

You can help us improve this guide by contributing to the Nimiq Web Client documentation on GitHub. Simply click the Edit this page button at the bottom of the page to suggest changes.