Options
All
  • Public
  • Public/Protected
  • All
Menu

This class represents contract storage.

It is a key-value store that is persisted on the NEAR blockchain.

Hierarchy

  • Storage

Index

Methods

Static contains

  • contains(key: string): bool
  • Returns true if the given key is present in the storage.

    storage.contains("myKey")
    

    Parameters

    • key: string

      The unique identifier associated with a value in a key-value store

    Returns bool

    True if the given key is present in the storage.

Static delete

  • delete(key: string): void
  • Deletes a given key from the storage.

    storage.delete("myKey")
    

    Parameters

    • key: string

      The unique identifier associated with a value in a key-value store

    Returns void

Static get

  • get<T>(key: string, defaultValue?: T | null): T | null
  • Gets given generic value stored under the key. Key is encoded as UTF-8 strings. Supported types: string and data objects defined in model.ts. Please use getPrimitive for getting primitives with a default value, and getSome for primitives and non-primitives in case it's known that a particular key exists.

    storage.get<string>("myKey")
    storage.get<u16>("myKey")
    storage.get<MyCustomObject>("myKey")
    

    Type parameters

    • T

    Parameters

    • key: string

      The unique identifier associated with a value in a key-value store

    • Default value defaultValue: T | null = null

      The default value if the key is not available

    Returns T | null

    A value of type T stored under the given key.

Static getBytes

  • getBytes(key: string): Uint8Array | null
  • Get byte array stored under given key. Key is encoded as UTF-8 strings. Byte array stored as is.

    It's convenient to use this together with DomainObject.decode().

    storage.getBytes("myKey")
    

    Parameters

    • key: string

      The unique identifier associated with a value in a key-value store

    Returns Uint8Array | null

    Byte array stored under given key

Static getPrimitive

  • getPrimitive<T>(key: string, defaultValue: T): T
  • Gets given generic value stored under the key. Key is encoded as UTF-8 strings. Supported types: bool, integer.

    This function will throw if type T can not be cast as integer

    storage.getPrimitive<string>("myKey", "default value")
    storage.getPrimitive<u16>("myKey", 123)
    

    Type parameters

    • T

    Parameters

    • key: string

      The unique identifier associated with a value in a key-value store

    • defaultValue: T

      The default value if the key is not available

    Returns T

    A value of type T stored under the given key.

Static getSome

  • getSome<T>(key: string): T
  • Gets given generic value stored under the key. Key is encoded as UTF-8 strings. Supported types: bool, integer, string and data objects defined in model.ts.

    This function will throw if the key does not exist in the storage.

    storage.getSome<string>("myKey")
    storage.getSome<u16>("myKey")
    

    Type parameters

    • T

    Parameters

    • key: string

      The unique identifier associated with a value in a key-value store

    Returns T

    A value of type T stored under the given key.

Static getString

  • getString(key: string): string | null
  • Get string value stored under given key. Both key and value are encoded as UTF-8 strings.

    let value = storage.getString("myKey")
    

    Parameters

    • key: string

      The unique identifier associated with a value in a key-value store

    Returns string | null

    String value stored under given key

Static hasKey

  • hasKey(key: string): bool
  • Returns true if the given key is present in the storage.

    // alias for method contains()
    

    Parameters

    • key: string

      The unique identifier associated with a value in a key-value store

    Returns bool

    True if the given key is present in the storage.

Static set

  • set<T>(key: string, value: T): void
  • Stores given generic value under the key. Key is encoded as UTF-8 strings. Supported types: bool, integer, string and data objects defined in model.ts.

    storage.set<string>("myKey", "myValue")
    storage.set<u16>("myKey", 123)
    storage.set<MyCustomObject>("myKey", new MyCustomObject())
    

    Type parameters

    • T

    Parameters

    • key: string

      The unique identifier associated with a value in a key-value store

    • value: T

      The value stored at a particular key in a key-value store

    Returns void

Static setBytes

  • setBytes(key: string, value: Uint8Array): void
  • Store byte array under given key. Key is encoded as UTF-8 strings. Byte array stored as is.

    It's convenient to use this together with domainObject.encode().

    let data = new Uint8Array([1,2,3])
    storage.setBytes("myKey", data)
    

    Parameters

    • key: string

      The unique identifier associated with a value in a key-value store

    • value: Uint8Array

      The value stored at a particular key in a key-value store

    Returns void

Static setString

  • setString(key: string, value: string): void
  • Store string value under given key. Both key and value are encoded as UTF-8 strings.

    storage.setString("myKey", "myValue")
    

    Parameters

    • key: string

      The unique identifier associated with a value in a key-value store

    • value: string

      The value stored at a particular key in a key-value store

    Returns void

Generated using TypeDoc