Function storage_has_key

Source
pub fn storage_has_key(key: &[u8]) -> bool
Expand description

Checks if there is a key-value in the storage.

§Use cases

Storage functions are typically used to upgrade/migrate a contract state, preventing errors like Cannot deserialize the contract state after rolling out the breaking changes to the network. For practical examples, see different implementations in this repository.

§Examples

use near_sdk::env::{storage_write, storage_has_key};

assert_eq!(storage_has_key(b"key"), false);
storage_write(b"key", b"value");
assert_eq!(storage_has_key(b"key"), true);