Skip to Content
DevelopersNTSNMap class

NMap Class

️⚠️
NTS is in active development and currently unstable. It is open to select early developers for exploration but is not yet suitable for production use. Follow developer updates for the latest changes, as performance is not at production level.

The NMap class is a specialized key-value type for N1 applications that provides persistent storage with automatic state management. It’s designed to work seamlessly with the NApp class to store and manage collections of data on the blockchain.

NMap is the preferred way to store collections of data on N1.

Usage

Creating an NMap

To create a map type using NMap, instantiate it with a prefix:

private scores = new NMap<number>(this, "scores");

Basic Operations

The NMap class provides familiar Map-like operations:

private scores = new NMap<number>(this, "scores"); setScore(player: string, score: number): void { this.scores.set(player, score); }

API Reference

Constructor

constructor(parent: NApp, prefix: string)
  • parent: The NApp instance that owns this map
  • prefix: A unique prefix for this map’s keys in storage

Methods

set

set(key: string, value: T, tag?: string): void

Stores a value in the map.

  • tag: Optional tag for more easily fetching values later

delete

delete(key: string, tag?: string): void

Removes a key-value pair from the map.

  • tag: Optional tag for more easily fetching values later
Last updated on