pub fn storage_write(key: &[u8], value: &[u8]) -> bool
Expand description
Writes key-value into storage.
If another key-value existed in the storage with the same key it returns true
, otherwise false
.
§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_read};
assert!(!storage_write(b"key", b"value"));
assert!(storage_write(b"key", b"another_value"));
assert_eq!(storage_read(b"key").unwrap(), b"another_value");
Example of usage here