Key-Value Storage (KVS)
Learn how to use the KVS
About
An alternative method for storing function state is through a Key-Value storage system. This approach enables storing and retrieving specific portions of the state during any interaction, eliminating the need to process the entire JSON object while reading state.
API reference
SmartWeave.kv.put(key, value)
- insert a new key-value pair or update an existing key's valueSmartWeave.kv.get(key)
- return the value of a given key, readable viaresponse.data.result
SmartWeave.kv.del(key)
- delete a key-value pair (it will still be accessible on-chain from the previous state reference)SmartWeave.kv.keys(options: QueryOptions)
- fetch a key based on a custom rangeSmartWeave.kv.kvMap(options: QueryOptions)
- Fetch a pair based on custom range
QueryOptions interface for .keys and .kvMap
Function example
After writing to the Key-Value storage (KVS), data can be retrieved by external actors/applications through the following flow:
Retrieve the value associated with the key using
SmartWeave.kv.get()
.The result, which is the value of the key, is then returned alongside the response transaction as a
result
.
Contribution History
The MEM features introduced to the 3EM repository codebase (OSS) have started by this PR: https://github.com/three-em/3em/pull/234
Last updated