---
title: "Class: Client"
canonical_url: "https://nimiq.dev/web-client/reference/classes/client"
---
# Class: Client

[@nimiq/core](../globals) / Client

Defined in: @nimiq/core/types/wasm/web.d.ts:851

Nimiq Albatross client that runs in browsers via WASM and is exposed to Javascript.

### Usage:

```js
import init, * as Nimiq from "./pkg/nimiq_web_client.js";

init().then(async () => {
    const config = new Nimiq.ClientConfiguration();
    const client = await config.instantiateClient();
    // ...
});
```

## Methods

### [dispose]()

> **[dispose]**(): `void`

Defined in: @nimiq/core/types/wasm/web.d.ts:854

#### Returns

`void`

---

### addConsensusChangedListener()

> **addConsensusChangedListener**(`listener`): `Promise`<`number`>

Defined in: @nimiq/core/types/wasm/web.d.ts:858

Adds an event listener for consensus-change events, such as when consensus is established or lost.

#### Parameters

##### listener

(`state`) => `any`

#### Returns

`Promise`<`number`>

---

### addHeadChangedListener()

> **addHeadChangedListener**(`listener`): `Promise`<`number`>

Defined in: @nimiq/core/types/wasm/web.d.ts:862

Adds an event listener for new blocks added to the blockchain.

#### Parameters

##### listener

(`hash`, `reason`, `reverted_blocks`, `adopted_blocks`) => `any`

#### Returns

`Promise`<`number`>

---

### addPeerChangedListener()

> **addPeerChangedListener**(`listener`): `Promise`<`number`>

Defined in: @nimiq/core/types/wasm/web.d.ts:866

Adds an event listener for peer-change events, such as when a new peer joins, or a peer leaves.

#### Parameters

##### listener

(`peer_id`, `reason`, `peer_count`, `peer_info?`) => `any`

#### Returns

`Promise`<`number`>

---

### addTransactionListener()

> **addTransactionListener**(`listener`, `addresses`): `Promise`<`number`>

Defined in: @nimiq/core/types/wasm/web.d.ts:872

Adds an event listener for transactions to and from the provided addresses.

The listener is called for transactions when they are *included* in the blockchain.

#### Parameters

##### listener

(`transaction`) => `any`

##### addresses

(`string` | [`Address`](Address) | `Uint8Array`<`ArrayBufferLike`>)<span>



</span>



#### Returns

`Promise`<`number`>

---

### connectNetwork()

> **connectNetwork**(): `Promise`<`void`>

Defined in: @nimiq/core/types/wasm/web.d.ts:878

This function is used to tell the network to (re)start connecting to peers.
This is could be used to tell the network to restart connection operations after
disconnect network is called.

#### Returns

`Promise`<`void`>

---

### disconnectNetwork()

> **disconnectNetwork**(): `Promise`<`void`>

Defined in: @nimiq/core/types/wasm/web.d.ts:891

This function is used to tell the network to disconnect from every connected
peer and stop trying to connect to other peers.

**Important**: this function returns when the signal to disconnect was sent,
before all peers actually disconnect. This means that in order to ensure the
network is disconnected, wait for all peers to disappear after calling.

#### Returns

`Promise`<`void`>

---

### free()

> **free**(): `void`

Defined in: @nimiq/core/types/wasm/web.d.ts:853

#### Returns

`void`

---

### getAccount()

> **getAccount**(`address`): `Promise`<[`PlainAccount`](../type-aliases/PlainAccount)>

Defined in: @nimiq/core/types/wasm/web.d.ts:897

Fetches the account for the provided address from the network.

Throws if the address cannot be parsed and on network errors.

#### Parameters

##### address

`string` | [`Address`](Address) | `Uint8Array`<`ArrayBufferLike`>

#### Returns

`Promise`<[`PlainAccount`](../type-aliases/PlainAccount)>

---

### getAccounts()

> **getAccounts**(`addresses`): `Promise`<[`PlainAccount`](../type-aliases/PlainAccount)<span>
> 
> 
> 
> </span>
> 
> >

Defined in: @nimiq/core/types/wasm/web.d.ts:903

Fetches the accounts for the provided addresses from the network.

Throws if an address cannot be parsed and on network errors.

#### Parameters

##### addresses

(`string` | [`Address`](Address) | `Uint8Array`<`ArrayBufferLike`>)<span>



</span>



#### Returns

`Promise`<[`PlainAccount`](../type-aliases/PlainAccount)<span>



</span>

>

---

### getAddressBook()

> **getAddressBook**(): `Promise`<[`PlainPeerInfo`](../interfaces/PlainPeerInfo)<span>
> 
> 
> 
> </span>
> 
> >

Defined in: @nimiq/core/types/wasm/web.d.ts:910

Returns the current address books peers.
Each peer will have one address and currently no guarantee for the usefulness of that address can be given.

The resulting Array may be empty if there is no peers in the address book.

#### Returns

`Promise`<[`PlainPeerInfo`](../interfaces/PlainPeerInfo)<span>



</span>

>

---

### getBlock()

> **getBlock**(`hash`): `Promise`<[`PlainBlock`](../type-aliases/PlainBlock)>

Defined in: @nimiq/core/types/wasm/web.d.ts:918

Fetches a block by its hash.

Throws if the client does not have the block.

Fetching blocks from the network is not yet available.

#### Parameters

##### hash

`string`

#### Returns

`Promise`<[`PlainBlock`](../type-aliases/PlainBlock)>

---

### getBlockAt()

> **getBlockAt**(`height`): `Promise`<[`PlainBlock`](../type-aliases/PlainBlock)>

Defined in: @nimiq/core/types/wasm/web.d.ts:926

Fetches a block by its height (block number).

Throws if the client does not have the block.

Fetching blocks from the network is not yet available.

#### Parameters

##### height

`number`

#### Returns

`Promise`<[`PlainBlock`](../type-aliases/PlainBlock)>

---

### getElectedValidators()

> **getElectedValidators**(): `Promise`<[`PlainElectedValidator`](../interfaces/PlainElectedValidator)<span>
> 
> 
> 
> </span>
> 
> >

Defined in: @nimiq/core/types/wasm/web.d.ts:937

Returns the validators elected for the current epoch, together with the number of validator
slots assigned to each of them.

The slot distribution is fixed for the duration of an epoch and is the metric used on-chain
to evaluate support for protocol upgrades. Combine this with [Client.getValidators](#getvalidators) to
relate slot counts to each validator's stake and signal data.

Throws if the elected validators are not available (e.g. before consensus is established).

#### Returns

`Promise`<[`PlainElectedValidator`](../interfaces/PlainElectedValidator)<span>



</span>

>

---

### getHeadBlock()

> **getHeadBlock**(): `Promise`<[`PlainBlock`](../type-aliases/PlainBlock)>

Defined in: @nimiq/core/types/wasm/web.d.ts:942

Returns the current blockchain head block.
Note that the web client is a light client and does not have block bodies, i.e. no transactions.

#### Returns

`Promise`<[`PlainBlock`](../type-aliases/PlainBlock)>

---

### getHeadHash()

> **getHeadHash**(): `Promise`<`string`>

Defined in: @nimiq/core/types/wasm/web.d.ts:946

Returns the block hash of the current blockchain head.

#### Returns

`Promise`<`string`>

---

### getHeadHeight()

> **getHeadHeight**(): `Promise`<`number`>

Defined in: @nimiq/core/types/wasm/web.d.ts:950

Returns the block number of the current blockchain head.

#### Returns

`Promise`<`number`>

---

### getNetworkId()

> **getNetworkId**(): `Promise`<`number`>

Defined in: @nimiq/core/types/wasm/web.d.ts:954

Returns the network ID that the client is connecting to.

#### Returns

`Promise`<`number`>

---

### getProtocolVersion()

> **getProtocolVersion**(): `Promise`<`number`>

Defined in: @nimiq/core/types/wasm/web.d.ts:958

Returns the blockchain protocol version the client currently uses to verify transactions.

#### Returns

`Promise`<`number`>

---

### getStaker()

> **getStaker**(`address`): `Promise`<[`PlainStaker`](../interfaces/PlainStaker)>

Defined in: @nimiq/core/types/wasm/web.d.ts:964

Fetches the staker for the provided address from the network.

Throws if the address cannot be parsed and on network errors.

#### Parameters

##### address

`string` | [`Address`](Address) | `Uint8Array`<`ArrayBufferLike`>

#### Returns

`Promise`<[`PlainStaker`](../interfaces/PlainStaker)>

---

### getStakers()

> **getStakers**(`addresses`): `Promise`<[`PlainStaker`](../interfaces/PlainStaker)<span>
> 
> 
> 
> </span>
> 
> >

Defined in: @nimiq/core/types/wasm/web.d.ts:970

Fetches the stakers for the provided addresses from the network.

Throws if an address cannot be parsed and on network errors.

#### Parameters

##### addresses

(`string` | [`Address`](Address) | `Uint8Array`<`ArrayBufferLike`>)<span>



</span>



#### Returns

`Promise`<[`PlainStaker`](../interfaces/PlainStaker)<span>



</span>

>

---

### getTransaction()

> **getTransaction**(`hash`): `Promise`<[`PlainTransactionDetails`](../interfaces/PlainTransactionDetails)>

Defined in: @nimiq/core/types/wasm/web.d.ts:974

Fetches the transaction details for the given transaction hash.

#### Parameters

##### hash

`string`

#### Returns

`Promise`<[`PlainTransactionDetails`](../interfaces/PlainTransactionDetails)>

---

### getTransactionReceiptsByAddress()

> **getTransactionReceiptsByAddress**(`address`, `limit?`, `start_at?`, `min_peers?`): `Promise`<[`PlainTransactionReceipt`](../interfaces/PlainTransactionReceipt)<span>
> 
> 
> 
> </span>
> 
> >

Defined in: @nimiq/core/types/wasm/web.d.ts:986

This function is used to query the network for transaction receipts from and to a
specific address, that have been included in the chain.

The obtained receipts are *not* verified before being returned.

Up to a `limit` number of transaction receipts are returned from newest to oldest.
It starts at the `start_at` transaction and goes backwards. If this hash does not exist
or does not belong to the address, an empty list is returned.
If the network does not have at least `min_peers` to query, then an error is returned.

#### Parameters

##### address

`string` | [`Address`](Address) | `Uint8Array`<`ArrayBufferLike`>

##### limit?

`number`

##### start_at?

`string`

##### min_peers?

`number`

#### Returns

`Promise`<[`PlainTransactionReceipt`](../interfaces/PlainTransactionReceipt)<span>



</span>

>

---

### getTransactionsByAddress()

> **getTransactionsByAddress**(`address`, `since_block_height?`, `known_transaction_details?`, `start_at?`, `limit?`, `min_peers?`): `Promise`<[`PlainTransactionDetails`](../interfaces/PlainTransactionDetails)<span>
> 
> 
> 
> </span>
> 
> >

Defined in: @nimiq/core/types/wasm/web.d.ts:1008

This function is used to query the network for transactions from and to a specific
address, that have been included in the chain.

The obtained transactions are verified before being returned.

If you already have transactions belonging to this address, you can provide some of that
information to reduce the amount of network requests made:

- Provide the `since_block_height` parameter to exclude any history from before
that block height. You should be completely certain about its state. This should not be
the last known block height, but an earlier block height that could not have been forked
from (e.g. the last known election or checkpoint block).
- Provide a list of `known_transaction_details` to have them verified and/or broadcasted
again.
- Provide a `start_at` parameter to start the query at a specific transaction hash
(which will not be included). This hash must exist and the corresponding transaction
must involve this address for the query to work correctly.

Up to a `limit` number of transactions are returned from newest to oldest.
If the network does not have at least `min_peers` to query, an error is returned.

#### Parameters

##### address

`string` | [`Address`](Address) | `Uint8Array`<`ArrayBufferLike`>

##### since_block_height?

`number`

##### known_transaction_details?

[`PlainTransactionDetails`](../interfaces/PlainTransactionDetails)<span>



</span>



##### start_at?

`string`

##### limit?

`number`

##### min_peers?

`number`

#### Returns

`Promise`<[`PlainTransactionDetails`](../interfaces/PlainTransactionDetails)<span>



</span>

>

---

### getValidator()

> **getValidator**(`address`): `Promise`<[`PlainValidator`](../interfaces/PlainValidator)>

Defined in: @nimiq/core/types/wasm/web.d.ts:1014

Fetches the validator for the provided address from the network.

Throws if the address cannot be parsed and on network errors.

#### Parameters

##### address

`string` | [`Address`](Address) | `Uint8Array`<`ArrayBufferLike`>

#### Returns

`Promise`<[`PlainValidator`](../interfaces/PlainValidator)>

---

### getValidators()

> **getValidators**(`addresses`): `Promise`<[`PlainValidator`](../interfaces/PlainValidator)<span>
> 
> 
> 
> </span>
> 
> >

Defined in: @nimiq/core/types/wasm/web.d.ts:1020

Fetches the validators for the provided addresses from the network.

Throws if an address cannot be parsed and on network errors.

#### Parameters

##### addresses

(`string` | [`Address`](Address) | `Uint8Array`<`ArrayBufferLike`>)<span>



</span>



#### Returns

`Promise`<[`PlainValidator`](../interfaces/PlainValidator)<span>



</span>

>

---

### getVersion()

> **getVersion**(): `Promise`<`string`>

Defined in: @nimiq/core/types/wasm/web.d.ts:1025

Returns the version of the web client, including a `+dirty` build-metadata
suffix when it was built from a Git work tree with uncommitted changes.

#### Returns

`Promise`<`string`>

---

### isConsensusEstablished()

> **isConsensusEstablished**(): `Promise`<`boolean`>

Defined in: @nimiq/core/types/wasm/web.d.ts:1029

Returns if the client currently has consensus with the network.

#### Returns

`Promise`<`boolean`>

---

### removeListener()

> **removeListener**(`handle`): `Promise`<`void`>

Defined in: @nimiq/core/types/wasm/web.d.ts:1033

Removes an event listener by its handle.

#### Parameters

##### handle

`number`

#### Returns

`Promise`<`void`>

---

### sendTransaction()

> **sendTransaction**(`transaction`): `Promise`<[`PlainTransactionDetails`](../interfaces/PlainTransactionDetails)>

Defined in: @nimiq/core/types/wasm/web.d.ts:1039

Sends a transaction to the network and returns [PlainTransactionDetails](../interfaces/PlainTransactionDetails).

Throws in case of network errors.

#### Parameters

##### transaction

`string` | [`PlainTransaction`](../interfaces/PlainTransaction) | `Uint8Array`<`ArrayBufferLike`> | [`Transaction`](Transaction)

#### Returns

`Promise`<[`PlainTransactionDetails`](../interfaces/PlainTransactionDetails)>

---

### waitForConsensusEstablished()

> **waitForConsensusEstablished**(): `Promise`<`void`>

Defined in: @nimiq/core/types/wasm/web.d.ts:1043

Returns a promise that resolves when the client has established consensus with the network.

#### Returns

`Promise`<`void`>

---

### create()

> `static` **create**(`config`): `Promise`<`Client`>

Defined in: @nimiq/core/types/wasm/web.d.ts:882

Creates a new Client that automatically starts connecting to the network.

#### Parameters

##### config

[`PlainClientConfiguration`](../interfaces/PlainClientConfiguration)

#### Returns

`Promise`<`Client`>


## Sitemap

See the full [sitemap](https://nimiq.dev/sitemap.md) for all pages.
