Skip to content

Nimiq Web Client in Vite

The Nimiq Web Client ships with support for Vite.


Installation

bash
npm install @nimiq/core@next
npm install -D vite-plugin-top-level-await vite-plugin-wasm
bash
yarn add @nimiq/core@next
yarn add -D vite-plugin-top-level-await vite-plugin-wasm
bash
pnpm add @nimiq/core@next
pnpm add -D vite-plugin-top-level-await vite-plugin-wasm
bash
bun add @nimiq/core@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 topLevelAwait from 'vite-plugin-top-level-await'
import wasm from 'vite-plugin-wasm'

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

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

Now you are ready to go!

js
import init, { Client, ClientConfiguration } from '@nimiq/core/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.